Top Description Fields Constructors Methods
org.eclipse.jgit.internal.diffmergetool

public Class DiffTools

extends Object
Class Inheritance
Imports
java.io.File, .IOException, java.util.Collections, .LinkedHashSet, .Map, .Map.Entry, .Optional, .Set, .TreeMap, org.eclipse.jgit.internal.JGitText, org.eclipse.jgit.lib.Repository, .StoredConfig, org.eclipse.jgit.lib.internal.BooleanTriState, org.eclipse.jgit.treewalk.TreeWalk, org.eclipse.jgit.util.FS, .FS.ExecutionResult, .StringUtils

Manages diff tools.

Field Summary

Modifier and TypeField and Description
private final DiffToolConfig
private final FS
private final File
private final Map<String, ExternalDiffTool>
private final Repository
private final Map<String, ExternalDiffTool>
private final File

Constructor Summary

AccessConstructor and Description
public
DiffTools(Repository
the repository
repo
)

Creates the external diff-tools manager for given repository.

public
DiffTools(StoredConfig
the git configuration
config
)

Creates the external merge-tools manager for given configuration.

private

Method Summary

Modifier and TypeMethod and Description
public Optional<FS.ExecutionResult>

Returns:

the optional result of executing the tool if it was executed
compare
(FileElement
The local/left version of the file.
localFile
,
FileElement
The remote/right version of the file.
remoteFile
,
Optional<String>
Optionally the name of the tool to use. If not given the default tool will be used.
toolName
,
BooleanTriState
Optionally a flag whether to prompt the user before compare. If not given the default will be used.
prompt
,
boolean
A flag whether to prefer a gui tool.
gui
,
BooleanTriState
Optionally a flag whether to trust the exit code of the tool. If not given the default will be used.
trustExitCode
,
PromptContinueHandler
The handler to use when needing to prompt the user if he wants to continue.
promptHandler
,
InformNoToolHandler
The handler to use when needing to inform the user, that no tool is configured.
noToolHandler
)

Compare two versions of a file.

public FS.ExecutionResult

Returns:

the execution result from tool
compare
(FileElement
the local file element
localFile
,
FileElement
the remote file element
remoteFile
,
ExternalDiffTool
the selected tool
tool
,
boolean
the "trust exit code" option
trustExitCode
)

Compare two versions of a file.

public Set<String>

Returns:

the all tool names (default or available tool name is the first in the set)
getAllToolNames
()

Get all tool names.

public String

Returns:

the default tool name
getDefaultToolName
(boolean
use the diff.guitool setting ?
gui
)

Get default (gui-)tool name.

public Optional<String>

Returns:

name of the difftool if set
getExternalToolFromAttributes
(final String
path to the node in repository to parse git attributes for
path
)

Provides Optional with the name of an external diff tool if specified in git configuration for a path.

public String

Returns:

the name of first available predefined tool or null
getFirstAvailableTool
()

Get first available tool name.

public Set<String>

Returns:

set of predefined available tools
getPredefinedAvailableTools
()

Checks the availability of the predefined tools in the system.

public Set<String>

Returns:

the predefined tool names
getPredefinedToolNames
()

Get predefined tool names.

public Map<String, ExternalDiffTool>

Returns:

the predefined tools with optionally checked availability (long running operation)
getPredefinedTools
(boolean
true: for checking if tools can be executed; ATTENTION: this check took some time, do not execute often (store the map for other actions); false: availability is NOT checked: isAvailable() returns default false is this case!
checkAvailability
)

Get predefined tools map.

private ExternalDiffTool
getTool(final String name)

public Set<String>

Returns:

the user defined tool names
getUserDefinedToolNames
()

Get user defined tool names.

public Map<String, ExternalDiffTool>

Returns:

the user defined tools
getUserDefinedTools
()

Get user defined tools map.

public boolean

Returns:

is interactive (config prompt enabled) ?
isInteractive
()

Is interactive diff (prompt enabled) ?

private static Map<String, ExternalDiffTool>
private Map<String, ExternalDiffTool>
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

configback to summary
private final DiffToolConfig config
fsback to summary
private final FS fs
gitDirback to summary
private final File gitDir
predefinedToolsback to summary
private final Map<String, ExternalDiffTool> predefinedTools
repoback to summary
private final Repository repo
userDefinedToolsback to summary
private final Map<String, ExternalDiffTool> userDefinedTools
workTreeback to summary
private final File workTree

Constructor Detail

DiffToolsback to summary
public DiffTools(Repository repo)

Creates the external diff-tools manager for given repository.

Parameters
repo:Repository

the repository

DiffToolsback to summary
public DiffTools(StoredConfig config)

Creates the external merge-tools manager for given configuration.

Parameters
config:StoredConfig

the git configuration

DiffToolsback to summary
private DiffTools(Repository repo, StoredConfig config)

Method Detail

compareback to summary
public Optional<FS.ExecutionResult> compare(FileElement localFile, FileElement remoteFile, Optional<String> toolName, BooleanTriState prompt, boolean gui, BooleanTriState trustExitCode, PromptContinueHandler promptHandler, InformNoToolHandler noToolHandler) throws ToolException

Compare two versions of a file.

Parameters
localFile:FileElement

The local/left version of the file.

remoteFile:FileElement

The remote/right version of the file.

toolName:Optional<String>

Optionally the name of the tool to use. If not given the default tool will be used.

prompt:BooleanTriState

Optionally a flag whether to prompt the user before compare. If not given the default will be used.

gui:boolean

A flag whether to prefer a gui tool.

trustExitCode:BooleanTriState

Optionally a flag whether to trust the exit code of the tool. If not given the default will be used.

promptHandler:PromptContinueHandler

The handler to use when needing to prompt the user if he wants to continue.

noToolHandler:InformNoToolHandler

The handler to use when needing to inform the user, that no tool is configured.

Returns:Optional<FS.ExecutionResult>

the optional result of executing the tool if it was executed

Exceptions
ToolException:
when the tool fails
compareback to summary
public FS.ExecutionResult compare(FileElement localFile, FileElement remoteFile, ExternalDiffTool tool, boolean trustExitCode) throws ToolException

Compare two versions of a file.

Parameters
localFile:FileElement

the local file element

remoteFile:FileElement

the remote file element

tool:ExternalDiffTool

the selected tool

trustExitCode:boolean

the "trust exit code" option

Returns:FS.ExecutionResult

the execution result from tool

Exceptions
ToolException:
when the tool fails
getAllToolNamesback to summary
public Set<String> getAllToolNames()

Get all tool names.

Returns:Set<String>

the all tool names (default or available tool name is the first in the set)

getDefaultToolNameback to summary
public String getDefaultToolName(boolean gui)

Get default (gui-)tool name.

Parameters
gui:boolean

use the diff.guitool setting ?

Returns:String

the default tool name

getExternalToolFromAttributesback to summary
public Optional<String> getExternalToolFromAttributes(final String path) throws ToolException

Provides Optional with the name of an external diff tool if specified in git configuration for a path. The formed git configuration results from global rules as well as merged rules from info and worktree attributes. Triggers TreeWalk until specified path found in the tree.

Parameters
path:String

path to the node in repository to parse git attributes for

Returns:Optional<String>

name of the difftool if set

Exceptions
ToolException:
when the tool failed
getFirstAvailableToolback to summary
public String getFirstAvailableTool()

Get first available tool name.

Returns:String

the name of first available predefined tool or null

getPredefinedAvailableToolsback to summary
public Set<String> getPredefinedAvailableTools()

Checks the availability of the predefined tools in the system.

Returns:Set<String>

set of predefined available tools

getPredefinedToolNamesback to summary
public Set<String> getPredefinedToolNames()

Get predefined tool names.

Returns:Set<String>

the predefined tool names

getPredefinedToolsback to summary
public Map<String, ExternalDiffTool> getPredefinedTools(boolean checkAvailability)

Get predefined tools map.

Parameters
checkAvailability:boolean

true: for checking if tools can be executed; ATTENTION: this check took some time, do not execute often (store the map for other actions); false: availability is NOT checked: isAvailable() returns default false is this case!

Returns:Map<String, ExternalDiffTool>

the predefined tools with optionally checked availability (long running operation)

getToolback to summary
private ExternalDiffTool getTool(final String name)
getUserDefinedToolNamesback to summary
public Set<String> getUserDefinedToolNames()

Get user defined tool names.

Returns:Set<String>

the user defined tool names

getUserDefinedToolsback to summary
public Map<String, ExternalDiffTool> getUserDefinedTools()

Get user defined tools map.

Returns:Map<String, ExternalDiffTool>

the user defined tools

isInteractiveback to summary
public boolean isInteractive()

Is interactive diff (prompt enabled) ?

Returns:boolean

is interactive (config prompt enabled) ?

setupPredefinedToolsback to summary
private static Map<String, ExternalDiffTool> setupPredefinedTools()
setupUserDefinedToolsback to summary
private Map<String, ExternalDiffTool> setupUserDefinedTools(Map<String, ExternalDiffTool> predefTools)