Class NameConflictTreeWalk
- java.lang.Object
-
- org.eclipse.jgit.treewalk.TreeWalk
-
- org.eclipse.jgit.treewalk.NameConflictTreeWalk
-
- All Implemented Interfaces:
java.lang.AutoCloseable
,AttributesProvider
public class NameConflictTreeWalk extends TreeWalk
Specialized TreeWalk to detect directory-file (D/F) name conflicts.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 andTreeWalk.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.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.eclipse.jgit.treewalk.TreeWalk
TreeWalk.OperationType
-
-
Field Summary
Fields Modifier and Type Field Description private AbstractTreeIterator
dfConflict
private boolean
fastMinHasMatch
private static int
TREE_MODE
-
Fields inherited from class org.eclipse.jgit.treewalk.TreeWalk
currentHead, depth, trees
-
-
Constructor Summary
Constructors Constructor 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.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method 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.-
Methods inherited from class org.eclipse.jgit.treewalk.TreeWalk
addTree, addTree, close, enterSubtree, exitSubtree, forPath, forPath, forPath, forPath, getAttributes, getAttributes, getAttributesNodeProvider, getCheckoutEolStreamType, getDepth, getEolStreamType, getFileMode, getFileMode, getFilter, getFilterCommand, getNameString, getObjectId, getObjectId, getObjectReader, getOperationType, getPathLength, getPathString, getRawMode, getRawPath, getSmudgeCommand, getSmudgeCommand, getTree, getTree, getTreeCount, idEqual, isPathMatch, isPathPrefix, isPathSuffix, isPostChildren, isPostOrderTraversal, isRecursive, isSubtree, next, pathOf, pathOf, reset, reset, reset, setAttributesNodeProvider, setFilter, setHead, setOperationType, setPostOrderTraversal, setRecursive
-
-
-
-
Field Detail
-
TREE_MODE
private static final int TREE_MODE
-
fastMinHasMatch
private boolean fastMinHasMatch
-
dfConflict
private AbstractTreeIterator dfConflict
-
-
Constructor Detail
-
NameConflictTreeWalk
public NameConflictTreeWalk(Repository repo)
Create a new tree walker for a given repository.- Parameters:
repo
- the repository the walker will obtain data from.
-
NameConflictTreeWalk
public NameConflictTreeWalk(@Nullable Repository repo, ObjectReader or)
Create a new tree walker for a given repository.- Parameters:
repo
- the repository the walker will obtain data from.or
- the reader the walker will obtain tree data from.- Since:
- 4.3
-
NameConflictTreeWalk
public NameConflictTreeWalk(ObjectReader or)
Create a new tree walker for a given repository.- Parameters:
or
- the reader the walker will obtain tree data from.
-
-
Method Detail
-
min
AbstractTreeIterator min() throws CorruptObjectException
- Overrides:
min
in classTreeWalk
- Throws:
CorruptObjectException
-
fastMin
private AbstractTreeIterator fastMin()
-
nameEqual
private static boolean nameEqual(AbstractTreeIterator a, AbstractTreeIterator b)
-
isGitlink
private boolean isGitlink(AbstractTreeIterator p)
-
isTree
private static boolean isTree(AbstractTreeIterator p)
-
skipEntry
private boolean skipEntry(AbstractTreeIterator minRef) throws CorruptObjectException
- Throws:
CorruptObjectException
-
combineDF
private AbstractTreeIterator combineDF(AbstractTreeIterator minRef) throws CorruptObjectException
- Throws:
CorruptObjectException
-
popEntriesEqual
void popEntriesEqual() throws CorruptObjectException
- Overrides:
popEntriesEqual
in classTreeWalk
- Throws:
CorruptObjectException
-
skipEntriesEqual
void skipEntriesEqual() throws CorruptObjectException
- Overrides:
skipEntriesEqual
in classTreeWalk
- Throws:
CorruptObjectException
-
stopWalk
void stopWalk() throws java.io.IOException
Description copied from class:TreeWalk
Notify iterators the walk is aborting.Primarily to notify
DirCacheBuildIterator
the walk is aborting so that it can copy any remaining entries.
-
needsStopWalk
private boolean needsStopWalk()
-
isDirectoryFileConflict
public boolean isDirectoryFileConflict()
True if the current entry is covered by a directory/file conflict. This means that for some prefix of the current entry's path, this walk has detected a directory/file conflict. Also true if the current entry itself is a directory/file conflict. Example: If this TreeWalk points to foo/bar/a.txt and this method returns true then you know that either for path foo or for path foo/bar files and folders were detected.- Returns:
true
if the current entry is covered by a directory/file conflict,false
otherwise
-
-