public class NameConflictTreeWalk extends TreeWalk
Due to the way a Git tree is organized the standard
TreeWalk
won't easily find a D/F conflict
when merging two or more trees together. In the standard TreeWalk the file
will be returned first, and then much later the directory will be returned.
This makes it impossible for the application to efficiently detect and handle
the conflict.
Using this walk implementation causes the directory to report earlier than usual, at the same time as the non-directory entry. This permits the application to handle the D/F conflict in a single step. The directory is returned only once, so it does not get returned later in the iteration.
When a D/F conflict is detected
TreeWalk.isSubtree()
will return true and
TreeWalk.enterSubtree()
will recurse into
the subtree, no matter which iterator originally supplied the subtree.
Because conflicted directories report early, using this walk implementation
to populate a DirCacheBuilder
may cause the
automatic resorting to run and fix the entry ordering.
This walk implementation requires more CPU to implement a look-ahead and a look-behind to merge a D/F pair together, or to skip a previously reported directory. In typical Git repositories the look-ahead cost is 0 and the look-behind doesn't trigger, as users tend not to create trees which contain both "foo" as a directory and "foo.c" as a file.
In the worst-case however several thousand look-ahead steps per walk step may be necessary, making the overhead quite significant. Since this worst-case should never happen this walk implementation has made the time/space tradeoff in favor of more-time/less-space, as that better suits the typical case.
TreeWalk.OperationType
Modifier and Type | Field and Description |
---|---|
private AbstractTreeIterator |
dfConflict |
private boolean |
fastMinHasMatch |
private static int |
TREE_MODE |
currentHead, depth, trees
Constructor and Description |
---|
NameConflictTreeWalk(ObjectReader or)
Create a new tree walker for a given repository.
|
NameConflictTreeWalk(Repository repo)
Create a new tree walker for a given repository.
|
NameConflictTreeWalk(Repository repo,
ObjectReader or)
Create a new tree walker for a given repository.
|
Modifier and Type | Method and Description |
---|---|
private AbstractTreeIterator |
combineDF(AbstractTreeIterator minRef) |
private AbstractTreeIterator |
fastMin() |
boolean |
isDirectoryFileConflict()
True if the current entry is covered by a directory/file conflict.
|
private boolean |
isGitlink(AbstractTreeIterator p) |
private static boolean |
isTree(AbstractTreeIterator p) |
(package private) AbstractTreeIterator |
min() |
private static boolean |
nameEqual(AbstractTreeIterator a,
AbstractTreeIterator b) |
private boolean |
needsStopWalk() |
(package private) void |
popEntriesEqual() |
(package private) void |
skipEntriesEqual() |
private boolean |
skipEntry(AbstractTreeIterator minRef) |
(package private) void |
stopWalk()
Notify iterators the walk is aborting.
|
addTree, addTree, close, enterSubtree, exitSubtree, forPath, forPath, forPath, forPath, getAttributes, getAttributesNodeProvider, getDepth, getEolStreamType, getFileMode, getFileMode, getFilter, getFilterCommand, getNameString, getObjectId, getObjectId, getObjectReader, getOperationType, getPathLength, getPathString, getRawMode, getRawPath, getTree, getTree, getTreeCount, idEqual, isPathMatch, isPathPrefix, isPathSuffix, isPostChildren, isPostOrderTraversal, isRecursive, isSubtree, next, pathOf, pathOf, reset, reset, reset, setAttributesNodeProvider, setFilter, setOperationType, setPostOrderTraversal, setRecursive
private static final int TREE_MODE
private boolean fastMinHasMatch
private AbstractTreeIterator dfConflict
public NameConflictTreeWalk(Repository repo)
repo
- the repository the walker will obtain data from.public NameConflictTreeWalk(@Nullable Repository repo, ObjectReader or)
repo
- the repository the walker will obtain data from.or
- the reader the walker will obtain tree data from.public NameConflictTreeWalk(ObjectReader or)
or
- the reader the walker will obtain tree data from.AbstractTreeIterator min() throws CorruptObjectException
min
in class TreeWalk
CorruptObjectException
private AbstractTreeIterator fastMin()
private static boolean nameEqual(AbstractTreeIterator a, AbstractTreeIterator b)
private boolean isGitlink(AbstractTreeIterator p)
private static boolean isTree(AbstractTreeIterator p)
private boolean skipEntry(AbstractTreeIterator minRef) throws CorruptObjectException
CorruptObjectException
private AbstractTreeIterator combineDF(AbstractTreeIterator minRef) throws CorruptObjectException
CorruptObjectException
void popEntriesEqual() throws CorruptObjectException
popEntriesEqual
in class TreeWalk
CorruptObjectException
void skipEntriesEqual() throws CorruptObjectException
skipEntriesEqual
in class TreeWalk
CorruptObjectException
void stopWalk() throws java.io.IOException
TreeWalk
Primarily to notify DirCacheBuildIterator
the walk is aborting so
that it can copy any remaining entries.
private boolean needsStopWalk()
public boolean isDirectoryFileConflict()
true
if the current entry is covered by a
directory/file conflict, false
otherwise