public class ResolveMerger extends ThreeWayMerger
Modifier and Type | Class and Description |
---|---|
static class |
ResolveMerger.MergeFailureReason
If the merge fails (means: not stopped because of unresolved conflicts)
this enum is used to explain why it failed
|
Modifier and Type | Field and Description |
---|---|
protected DirCacheBuilder |
builder
Builder to update the cache during this merge.
|
private java.util.Map<java.lang.String,DirCacheCheckout.CheckoutMetadata> |
checkoutMetadata
|
protected java.lang.String[] |
commitNames
string versions of a list of commit SHA1s
|
protected DirCache |
dircache
Directory cache
|
protected boolean |
enterSubtree
Updated as we merge entries of the tree walk.
|
protected java.util.Map<java.lang.String,ResolveMerger.MergeFailureReason> |
failingPaths
Paths for which the merge failed altogether.
|
protected boolean |
implicitDirCache
Set to true if this merger should use the default dircache of the
repository and should handle locking and unlocking of the dircache.
|
protected boolean |
inCore
Set to true if this merge should work in-memory.
|
private int |
inCoreLimit
The size limit (bytes) which controls a file to be stored in
Heap
or LocalFile during the merge. |
protected MergeAlgorithm |
mergeAlgorithm
our merge algorithm
|
protected java.util.Map<java.lang.String,MergeResult<? extends Sequence>> |
mergeResults
Low-level textual merge results.
|
protected java.util.List<java.lang.String> |
modifiedFiles
Files modified during this merge operation.
|
private static Attributes |
NO_ATTRIBUTES |
protected ObjectId |
resultTree
merge result as tree
|
protected static int |
T_BASE
Index of the base tree within the
tree walk . |
protected static int |
T_FILE
Index of the working directory tree within the
tree walk . |
protected static int |
T_INDEX
Index of the index tree within the
tree walk . |
protected static int |
T_OURS
Index of our tree in withthe
tree walk . |
protected static int |
T_THEIRS
Index of their tree within the
tree walk . |
protected java.util.Map<java.lang.String,DirCacheEntry> |
toBeCheckedOut
If the merger has nothing to do for a file but check it out at the end of
the operation, it can be added here.
|
protected java.util.List<java.lang.String> |
toBeDeleted
Paths in this list will be deleted from the local copy at the end of the
operation.
|
protected NameConflictTreeWalk |
tw
The tree walk which we'll iterate over to merge entries.
|
protected java.util.List<java.lang.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 WorkingTreeOptions |
workingTreeOptions
The
WorkingTreeOptions are needed to determine line endings for
merged files. |
db, monitor, reader, sourceCommits, sourceObjects, sourceTrees, walk
Modifier | Constructor and Description |
---|---|
protected |
ResolveMerger(ObjectInserter inserter,
Config config)
Constructor for ResolveMerger.
|
protected |
ResolveMerger(Repository local)
Constructor for ResolveMerger.
|
protected |
ResolveMerger(Repository local,
boolean inCore)
Constructor for ResolveMerger.
|
Modifier and Type | Method and Description |
---|---|
private DirCacheEntry |
add(byte[] path,
CanonicalTreeParser p,
int stage,
java.time.Instant lastMod,
long len)
adds a new path with the specified stage to the index builder
|
protected void |
addCheckoutMetadata(java.lang.String path,
Attributes attributes)
Remembers the
DirCacheCheckout.CheckoutMetadata for the given path; it may be
needed in checkout() or in cleanUp() . |
protected void |
addDeletion(java.lang.String path,
boolean isFile,
Attributes attributes)
Remember a path for deletion, and remember its
DirCacheCheckout.CheckoutMetadata
in case it has to be restored in cleanUp() . |
protected void |
addToCheckout(java.lang.String path,
DirCacheEntry entry,
Attributes attributes)
Adds a
DirCacheEntry for direct checkout and remembers its
DirCacheCheckout.CheckoutMetadata . |
private void |
checkout() |
protected void |
cleanUp()
Reverts the worktree after an unsuccessful merge.
|
private MergeResult<RawText> |
contentMerge(CanonicalTreeParser base,
CanonicalTreeParser ours,
CanonicalTreeParser theirs,
Attributes attributes)
Does the content merge.
|
private static java.lang.String[] |
defaultCommitNames() |
private TemporaryBuffer |
doMerge(MergeResult<RawText> result) |
boolean |
failed()
Returns whether this merge failed (i.e.
|
java.lang.String[] |
getCommitNames()
Get the names of the commits as they would appear in conflict markers.
|
java.util.Map<java.lang.String,ResolveMerger.MergeFailureReason> |
getFailingPaths()
Get list of paths causing this merge to fail (not stopped because of a
conflict).
|
private static int |
getInCoreLimit(Config config) |
private static MergeAlgorithm |
getMergeAlgorithm(Config config) |
java.util.Map<java.lang.String,MergeResult<? extends Sequence>> |
getMergeResults()
Get the mergeResults
|
java.util.List<java.lang.String> |
getModifiedFiles()
Get the paths of files which have been modified by this merge.
|
private RawText |
getRawText(ObjectId id,
Attributes attributes) |
ObjectId |
getResultTreeId()
Get resulting tree.
|
java.util.Map<java.lang.String,DirCacheEntry> |
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.
|
java.util.List<java.lang.String> |
getUnmergedPaths()
Get the paths with conflicts.
|
private ObjectId |
insertMergeResult(TemporaryBuffer buf,
Attributes attributes) |
private static boolean |
isGitLink(int mode) |
private boolean |
isIndexDirty() |
private boolean |
isWorktreeDirty(WorkingTreeIterator work,
DirCacheEntry ourDce) |
private DirCacheEntry |
keep(DirCacheEntry e)
adds a entry to the index builder which is a copy of the specified
DirCacheEntry
|
private int |
mergeFileModes(int modeB,
int modeO,
int modeT)
Try to merge filemodes.
|
protected boolean |
mergeImpl()
Execute the merge.
|
protected boolean |
mergeTrees(AbstractTreeIterator baseTree,
RevTree headTree,
RevTree mergeTree,
boolean ignoreConflicts)
The resolve conflict way of three way merging
|
protected boolean |
mergeTreeWalk(TreeWalk treeWalk,
boolean ignoreConflicts)
Process the given TreeWalk's entries.
|
private static boolean |
nonTree(int mode) |
protected boolean |
processEntry(CanonicalTreeParser base,
CanonicalTreeParser ours,
CanonicalTreeParser theirs,
DirCacheBuildIterator index,
WorkingTreeIterator work,
boolean ignoreConflicts,
Attributes attributes)
Processes one path and tries to merge taking git attributes in account.
|
void |
setCommitNames(java.lang.String[] commitNames)
Set the names of the commits as they would appear in conflict markers
|
void |
setDirCache(DirCache dc)
Sets the DirCache which shall be used by this merger.
|
void |
setWorkingTreeIterator(WorkingTreeIterator workingTreeIterator)
Sets the WorkingTreeIterator to be used by this merger.
|
private void |
updateIndex(CanonicalTreeParser base,
CanonicalTreeParser ours,
CanonicalTreeParser theirs,
MergeResult<RawText> result,
Attributes attributes)
Updates the index after a content merge has happened.
|
private java.io.File |
writeMergedFile(TemporaryBuffer rawMerged,
Attributes attributes)
Writes merged file content to the working tree.
|
getBaseCommitId, merge, mergeBase, setBase
getBaseCommit, getObjectInserter, getRepository, merge, nonNullRepo, openTree, setObjectInserter, setProgressMonitor
protected NameConflictTreeWalk tw
protected java.lang.String[] commitNames
protected static final int T_BASE
tree walk
.protected static final int T_OURS
tree walk
.protected static final int T_THEIRS
tree walk
.protected static final int T_INDEX
tree walk
.protected static final int T_FILE
tree walk
.protected DirCacheBuilder builder
protected ObjectId resultTree
protected java.util.List<java.lang.String> unmergedPaths
protected java.util.List<java.lang.String> modifiedFiles
protected java.util.Map<java.lang.String,DirCacheEntry> toBeCheckedOut
protected java.util.List<java.lang.String> toBeDeleted
protected java.util.Map<java.lang.String,MergeResult<? extends Sequence>> mergeResults
protected java.util.Map<java.lang.String,ResolveMerger.MergeFailureReason> failingPaths
protected boolean enterSubtree
protected boolean inCore
protected boolean implicitDirCache
protected DirCache dircache
protected WorkingTreeIterator workingTreeIterator
null
this
merger will not touch the working tree.protected MergeAlgorithm mergeAlgorithm
protected WorkingTreeOptions workingTreeOptions
WorkingTreeOptions
are needed to determine line endings for
merged files.private int inCoreLimit
Heap
or LocalFile
during the merge.private java.util.Map<java.lang.String,DirCacheCheckout.CheckoutMetadata> checkoutMetadata
private static final Attributes NO_ATTRIBUTES
protected ResolveMerger(Repository local, boolean inCore)
local
- the Repository
.inCore
- a boolean.protected ResolveMerger(Repository local)
local
- the Repository
.protected ResolveMerger(ObjectInserter inserter, Config config)
inserter
- an ObjectInserter
object.config
- the repository configurationprivate static MergeAlgorithm getMergeAlgorithm(Config config)
private static int getInCoreLimit(Config config)
private static java.lang.String[] defaultCommitNames()
protected boolean mergeImpl() throws java.io.IOException
This method is called from Merger.merge(AnyObjectId[])
after the
Merger.sourceObjects
, Merger.sourceCommits
and Merger.sourceTrees
have been populated.
mergeImpl
in class Merger
IncorrectObjectTypeException
- one of the input objects is not a commit, but the strategy
requires it to be a commit.java.io.IOException
- one or more sources could not be read, or outputs could not
be written to the Repository.private void checkout() throws NoWorkTreeException, java.io.IOException
NoWorkTreeException
java.io.IOException
protected void cleanUp() throws NoWorkTreeException, CorruptObjectException, java.io.IOException
java.io.IOException
CorruptObjectException
NoWorkTreeException
private DirCacheEntry add(byte[] path, CanonicalTreeParser p, int stage, java.time.Instant lastMod, long len)
path
- p
- stage
- lastMod
- len
- private DirCacheEntry keep(DirCacheEntry e)
e
- the entry which should be copiedprotected void addCheckoutMetadata(java.lang.String path, Attributes attributes) throws java.io.IOException
DirCacheCheckout.CheckoutMetadata
for the given path; it may be
needed in checkout()
or in cleanUp()
.path
- of the current nodeattributes
- for the current nodejava.io.IOException
- if the smudge filter cannot be determinedprotected void addToCheckout(java.lang.String path, DirCacheEntry entry, Attributes attributes) throws java.io.IOException
DirCacheEntry
for direct checkout and remembers its
DirCacheCheckout.CheckoutMetadata
.path
- of the entryentry
- to addattributes
- for the current entryjava.io.IOException
- if the DirCacheCheckout.CheckoutMetadata
cannot be determinedprotected void addDeletion(java.lang.String path, boolean isFile, Attributes attributes) throws java.io.IOException
DirCacheCheckout.CheckoutMetadata
in case it has to be restored in cleanUp()
.path
- of the entryisFile
- whether it is a fileattributes
- for the entryjava.io.IOException
- if the DirCacheCheckout.CheckoutMetadata
cannot be determinedprotected boolean processEntry(CanonicalTreeParser base, CanonicalTreeParser ours, CanonicalTreeParser theirs, DirCacheBuildIterator index, WorkingTreeIterator work, boolean ignoreConflicts, Attributes attributes) throws MissingObjectException, IncorrectObjectTypeException, CorruptObjectException, java.io.IOException
base
- the common base for ours and theirsours
- the ours side of the merge. When merging a branch into the
HEAD ours will point to HEADtheirs
- 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.index
- the index entrywork
- the file in the working treeignoreConflicts
- see
mergeTrees(AbstractTreeIterator, RevTree, RevTree, boolean)
attributes
- the attributes defined for this entryfalse
if the merge will fail because the index entry
didn't match ours or the working-dir file was dirty and a
conflict occurredMissingObjectException
IncorrectObjectTypeException
CorruptObjectException
java.io.IOException
private MergeResult<RawText> contentMerge(CanonicalTreeParser base, CanonicalTreeParser ours, CanonicalTreeParser theirs, Attributes attributes) throws java.io.IOException
CanonicalTreeParser
. If any of the parsers is
specified as null
then an empty text will be used instead.base
- ours
- theirs
- attributes
- java.io.IOException
private boolean isIndexDirty()
private boolean isWorktreeDirty(WorkingTreeIterator work, DirCacheEntry ourDce) throws java.io.IOException
java.io.IOException
private void updateIndex(CanonicalTreeParser base, CanonicalTreeParser ours, CanonicalTreeParser theirs, MergeResult<RawText> result, Attributes attributes) throws java.io.FileNotFoundException, java.io.IOException
base
- ours
- theirs
- result
- attributes
- java.io.FileNotFoundException
java.io.IOException
private java.io.File writeMergedFile(TemporaryBuffer rawMerged, Attributes attributes) throws java.io.FileNotFoundException, java.io.IOException
rawMerged
- the raw merged contentattributes
- the files .gitattributes entriesjava.io.FileNotFoundException
java.io.IOException
private TemporaryBuffer doMerge(MergeResult<RawText> result) throws java.io.IOException
java.io.IOException
private ObjectId insertMergeResult(TemporaryBuffer buf, Attributes attributes) throws java.io.IOException
java.io.IOException
private int mergeFileModes(int modeB, int modeO, int modeT)
FileMode.MISSING
int that case.modeB
- filemode found in BASEmodeO
- filemode found in OURSmodeT
- filemode found in THEIRSFileMode.MISSING
in case of a
conflictprivate RawText getRawText(ObjectId id, Attributes attributes) throws java.io.IOException, BinaryBlobException
java.io.IOException
BinaryBlobException
private static boolean nonTree(int mode)
private static boolean isGitLink(int mode)
public ObjectId getResultTreeId()
getResultTreeId
in class Merger
Merger.merge(AnyObjectId[])
returned true.public void setCommitNames(java.lang.String[] commitNames)
commitNames
- the names of the commits as they would appear in conflict
markerspublic java.lang.String[] getCommitNames()
public java.util.List<java.lang.String> getUnmergedPaths()
getModifiedFiles()
getModifiedFiles()
public java.util.List<java.lang.String> getModifiedFiles()
getUnmergedPaths()
.public java.util.Map<java.lang.String,DirCacheEntry> getToBeCheckedOut()
public java.util.Map<java.lang.String,MergeResult<? extends Sequence>> getMergeResults()
public java.util.Map<java.lang.String,ResolveMerger.MergeFailureReason> getFailingPaths()
null
is returned if this merge didn't
fail.public boolean failed()
true
if a failure occurred, false
otherwisepublic void setDirCache(DirCache dc)
DirCache.commit()
which requires that the DirCache is locked. If the mergeImpl()
returns without throwing an exception the lock will be released. In case
of exceptions the caller is responsible to release the lock.dc
- the DirCache to setpublic void setWorkingTreeIterator(WorkingTreeIterator workingTreeIterator)
TODO: enhance WorkingTreeIterator to support write operations. Then this merger will be able to merge with a different working tree abstraction.
workingTreeIterator
- the workingTreeIt to setprotected boolean mergeTrees(AbstractTreeIterator baseTree, RevTree headTree, RevTree mergeTree, boolean ignoreConflicts) throws java.io.IOException
baseTree
- a AbstractTreeIterator
object.headTree
- a RevTree
object.mergeTree
- a RevTree
object.ignoreConflicts
- 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 RecursiveMerger
where when determining merge bases we don't want to deal with
content-merge conflicts.
java.io.IOException
protected boolean mergeTreeWalk(TreeWalk treeWalk, boolean ignoreConflicts) throws java.io.IOException
treeWalk
- The walk to iterate over.ignoreConflicts
- see
mergeTrees(AbstractTreeIterator, RevTree, RevTree, boolean)
java.io.IOException