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.
|
protected 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 Map<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.
|
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 merge operation.
|
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 Map<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 List<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 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 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 |
---|---|
protected void |
cleanUp()
Reverts the worktree after an unsuccessful merge.
|
boolean |
failed()
Returns whether this merge failed (i.e.
|
String[] |
getCommitNames()
Get the names of the commits as they would appear in conflict markers.
|
Map<String,ResolveMerger.MergeFailureReason> |
getFailingPaths()
Get list of paths causing this merge to fail (not stopped because of a
conflict).
|
Map<String,MergeResult<? extends Sequence>> |
getMergeResults()
Get the mergeResults
|
List<String> |
getModifiedFiles()
Get the paths of files which have been modified by this merge.
|
ObjectId |
getResultTreeId()
Get resulting tree.
|
Map<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.
|
List<String> |
getUnmergedPaths()
Get the paths with conflicts.
|
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.
|
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(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.
|
getBaseCommitId, merge, mergeBase, setBase
getBaseCommit, getObjectInserter, getRepository, merge, nonNullRepo, openTree, setObjectInserter, setProgressMonitor
protected NameConflictTreeWalk tw
protected 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 List<String> unmergedPaths
protected List<String> modifiedFiles
protected Map<String,DirCacheEntry> toBeCheckedOut
protected List<String> toBeDeleted
protected Map<String,MergeResult<? extends Sequence>> mergeResults
protected Map<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.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 configurationprotected boolean mergeImpl() throws 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.IOException
- one or more sources could not be read, or outputs could not
be written to the Repository.protected void cleanUp() throws NoWorkTreeException, CorruptObjectException, IOException
IOException
CorruptObjectException
NoWorkTreeException
protected boolean processEntry(CanonicalTreeParser base, CanonicalTreeParser ours, CanonicalTreeParser theirs, DirCacheBuildIterator index, WorkingTreeIterator work, boolean ignoreConflicts, Attributes attributes) throws MissingObjectException, IncorrectObjectTypeException, CorruptObjectException, 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
IOException
public ObjectId getResultTreeId()
getResultTreeId
in class Merger
Merger.merge(AnyObjectId[])
returned true.public void setCommitNames(String[] commitNames)
commitNames
- the names of the commits as they would appear in conflict
markerspublic String[] getCommitNames()
public List<String> getUnmergedPaths()
getModifiedFiles()
getModifiedFiles()
public List<String> getModifiedFiles()
getUnmergedPaths()
.public Map<String,DirCacheEntry> getToBeCheckedOut()
public Map<String,MergeResult<? extends Sequence>> getMergeResults()
public Map<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 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.
IOException
protected boolean mergeTreeWalk(TreeWalk treeWalk, boolean ignoreConflicts) throws IOException
treeWalk
- The walk to iterate over.ignoreConflicts
- see
mergeTrees(AbstractTreeIterator, RevTree, RevTree, boolean)
IOException
Copyright © 2018 Eclipse JGit Project. All rights reserved.