Top Description Inners Fields Constructors Methods
org.eclipse.jgit.merge

public Class ResolveMerger

extends ThreeWayMerger
Class Inheritance
Known Direct Subclasses
org.eclipse.jgit.merge.RecursiveMerger
Static Imports
java.nio.charset.StandardCharsets.UTF_8, java.time.Instant.EPOCH, org.eclipse.jgit.diff.DiffAlgorithm.SupportedAlgorithm.HISTOGRAM, org.eclipse.jgit.lib.ConfigConstants.CONFIG_DIFF_SECTION, .ConfigConstants.CONFIG_KEY_ALGORITHM, .Constants.OBJ_BLOB

A three-way merger performing a content-merge if necessary

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum
ResolveMerger.MergeFailureReason

If the merge fails (means: not stopped because of unresolved conflicts) this enum is used to explain why it failed

protected static class
ResolveMerger.WorkTreeUpdater

Handles work tree updates on both the checkout and the index.

Field Summary

Modifier and TypeField and Description
protected AttributesNodeProvider
attributesNodeProvider

The AttributesNodeProvider to use while merging trees.

protected String[]
commitNames

string versions of a list of commit SHA1s

private ContentMergeStrategy
contentStrategy

The ContentMergeStrategy to use for "resolve" and "recursive" merges.

protected DirCache
dircache

Directory cache

protected boolean
enterSubtree

Updated as we merge entries of the tree walk.

protected Map<String, ResolveMerger.MergeFailureReason>
failingPaths

Paths for which the merge failed altogether.

protected boolean
inCore

Set to true if this merge should work in-memory.

protected MergeAlgorithm
mergeAlgorithm

our merge algorithm

protected Map<String, MergeResult<? extends Sequence>>
mergeResults

Low-level textual merge results.

protected List<String>
modifiedFiles

Files modified during this operation.

private static final Attributes
protected ObjectId
resultTree

merge result as tree

protected static final int
T_BASE

Index of the base tree within the tree walk.

protected static final int
T_FILE

Index of the working directory tree within the tree walk.

protected static final int
T_INDEX

Index of the index tree within the tree walk.

protected static final int
T_OURS

Index of our tree in withthe tree walk.

protected static final int
T_THEIRS

Index of their tree within the tree walk.

protected NameConflictTreeWalk
tw

The tree walk which we'll iterate over to merge entries.

protected List<String>
unmergedPaths

Paths that could not be merged by this merger because of an unsolvable conflict.

protected WorkingTreeIterator
workingTreeIterator

The iterator to access the working tree.

protected ResolveMerger.WorkTreeUpdater
workTreeUpdater

Handler for repository I/O actions.

Constructor Summary

AccessConstructor and Description
protected
ResolveMerger(Repository local, boolean
a boolean.
inCore
)

Constructor for ResolveMerger.

protected
ResolveMerger(Repository local)

Constructor for ResolveMerger.

protected
ResolveMerger(ObjectInserter inserter, Config
the repository configuration
config
)

Constructor for ResolveMerger.

Method Summary

Modifier and TypeMethod and Description
private DirCacheEntry

Returns:

the entry which was added to the index
add
(byte[]
the new path
path
,
CanonicalTreeParser
canonical tree parser
p
,
int
the stage
stage
,
Instant
lastModified attribute of the file
lastModified
,
long
file length
len
)

adds a new path with the specified stage to the index builder

private DirCacheEntry

Returns:

the DirCacheEntry for the "theirs" stage, or null
addConflict
(CanonicalTreeParser
of the conflict
base
,
CanonicalTreeParser
of the conflict
ours
,
CanonicalTreeParser
of the conflict
theirs
)

Adds the conflict stages for the current path of tw to the index builder and returns the "theirs" stage; if present.

protected void
addDeletion(String
of the entry
path
,
boolean
whether it is a file
isFile
,
Attributes
to use for determining the CheckoutMetadata
attributes
)

Remember a path for deletion, and remember its CheckoutMetadata in case it has to be restored in the cleanUp.

protected void
addToCheckout(String
of the entry
path
,
DirCacheEntry
to add
entry
,
Attributes[]
the Attributes of the trees
attributes
)

Adds a DirCacheEntry for direct checkout and remembers its CheckoutMetadata.

private MergeResult<RawText>

Returns:

the result of the content merge
contentMerge
(CanonicalTreeParser
used to parse base tree
base
,
CanonicalTreeParser
used to parse ours tree
ours
,
CanonicalTreeParser
used to parse theirs tree
theirs
,
Attributes[]
attributes for the different stages
attributes
,
ContentMergeStrategy
merge strategy
strategy
)

Does the content merge.

private static MergeResult<SubmoduleConflict>
private static String[]
private TemporaryBuffer
public boolean

Returns:

true if a failure occurred, false otherwise
failed
()

Returns whether this merge failed (i.e. not stopped because of a conflict)

private ContentMergeStrategy
public String[]

Returns:

the names of the commits as they would appear in conflict markers.
getCommitNames
()

Get the names of the commits as they would appear in conflict markers.

public ContentMergeStrategy

Returns:

the ContentMergeStrategy in effect
getContentMergeStrategy
()

Retrieves the content merge strategy for content conflicts.

public Map<String, ResolveMerger.MergeFailureReason>

Returns:

lists paths causing this merge to fail (not stopped because of a conflict). null is returned if this merge didn't fail.
getFailingPaths
()

Get list of paths causing this merge to fail (not stopped because of a conflict).

private static MergeAlgorithm
public Map<String, MergeResult<? extends Sequence>>

Returns:

the mergeResults
getMergeResults
()

Get the mergeResults

public List<String>

Returns:

the paths of files which have been modified by this merge. A file will be modified if a content-merge works on this path or if the merge algorithm decides to take the theirs-version. This is a superset of the files listed by getUnmergedPaths().
getModifiedFiles
()

Get the paths of files which have been modified by this merge.

private RawText
getRawText(ObjectId id, Attributes attributes)

public ObjectId
getResultTreeId()

Implements abstract org.eclipse.jgit.merge.Merger.getResultTreeId.

Get resulting tree.

public Map<String, DirCacheEntry>

Returns:

a map which maps the paths of files which have to be checked out because the merge created new fully-merged content for this file into the index. This means: the merge wrote a new stage 0 entry for this path.
getToBeCheckedOut
()

Get a map which maps the paths of files which have to be checked out because the merge created new fully-merged content for this file into the index.

public List<String>

Returns:

the paths with conflicts. This is a subset of the files listed by getModifiedFiles()
getUnmergedPaths
()

Get the paths with conflicts.

private boolean
private boolean
private DirCacheEntry

Returns:

the entry which was added to the index
keep
(DirCacheEntry
the entry which should be copied
e
)

adds a entry to the index builder which is a copy of the specified DirCacheEntry

private int

Returns:

the merged filemode or FileMode#MISSING in case of a conflict
mergeFileModes
(int
filemode found in BASE
modeB
,
int
filemode found in OURS
modeO
,
int
filemode found in THEIRS
modeT
)

Try to merge filemodes.

protected boolean
mergeImpl()

Implements abstract org.eclipse.jgit.merge.Merger.mergeImpl.

Execute the merge.

protected boolean

Returns:

whether the trees merged cleanly
mergeTrees
(AbstractTreeIterator baseTree, RevTree headTree, RevTree mergeTree, boolean
Controls what to do in case a content-merge is done and a conflict is detected. The default setting for this should be false. In this case the working tree file is filled with new content (containing conflict markers) and the index is filled with multiple stages containing BASE, OURS and THEIRS content. Having such non-0 stages is the sign to git tools that there are still conflicts for that path.

If true is specified the behavior is different. In case a conflict is detected the working tree file is again filled with new content (containing conflict markers). But also stage 0 of the index is filled with that content. No other stages are filled. Means: there is no conflict on that path but the new content (including conflict markers) is stored as successful merge result. This is needed in the context of org.eclipse.jgit.merge.RecursiveMerger where when determining merge bases we don't want to deal with content-merge conflicts.

ignoreConflicts
)

The resolve conflict way of three way merging

protected boolean

Returns:

Whether the trees merged cleanly.
mergeTreeWalk
(TreeWalk
The walk to iterate over.
treeWalk
,
boolean ignoreConflicts)

Process the given TreeWalk's entries.

private static boolean
nonTree(int mode)

protected boolean

Returns:

false if the merge will fail because the index entry didn't match ours or the working-dir file was dirty and a conflict occurred
processEntry
(CanonicalTreeParser
the common base for ours and theirs
base
,
CanonicalTreeParser
the ours side of the merge. When merging a branch into the HEAD ours will point to HEAD
ours
,
CanonicalTreeParser
the theirs side of the merge. When merging a branch into the current HEAD theirs will point to the branch which is merged into HEAD.
theirs
,
DirCacheBuildIterator
the index entry
index
,
WorkingTreeIterator
the file in the working tree
work
,
boolean ignoreConflicts, Attributes[]
the Attributes for the three trees
attributes
)

Processes one path and tries to merge taking git attributes in account.

public void
setAttributesNodeProvider(AttributesNodeProvider
the attributeNodeProvider to set
attributesNodeProvider
)

Sets the AttributesNodeProvider to be used by this merger.

public void
setCommitNames(String[]
the names of the commits as they would appear in conflict markers
commitNames
)

Set the names of the commits as they would appear in conflict markers

public void
setContentMergeStrategy(ContentMergeStrategy strategy)

Sets the content merge strategy for content conflicts.

public void
setDirCache(DirCache
the DirCache to set
dc
)

Sets the DirCache which shall be used by this merger.

public void
setWorkingTreeIterator(WorkingTreeIterator
the workingTreeIt to set
workingTreeIterator
)

Sets the WorkingTreeIterator to be used by this merger.

private void
updateIndex(CanonicalTreeParser
used to parse base tree
base
,
CanonicalTreeParser
used to parse ours tree
ours
,
CanonicalTreeParser
used to parse theirs tree
theirs
,
MergeResult<RawText>
merge result
result
,
Attributes
the file's attributes
attributes
)

Updates the index after a content merge has happened.

private File

Returns:

the working tree file to which the merged content was written.
writeMergedFile
(TemporaryBuffer
the raw merged content
rawMerged
,
Attributes
the files .gitattributes entries
attributes
)

Writes merged file content to the working tree.

Inherited from org.eclipse.jgit.merge.ThreeWayMerger:
getBaseCommitIdmergemergeBasesetBase