Top Description Fields Constructors Methods
org.eclipse.jgit.treewalk

public Class NameConflictTreeWalk

extends TreeWalk
Class Inheritance
Imports
java.io.IOException, org.eclipse.jgit.annotations.Nullable, org.eclipse.jgit.errors.CorruptObjectException, org.eclipse.jgit.lib.FileMode, .ObjectReader, .Repository

Specialized TreeWalk to detect directory-file (D/F) name conflicts.

Due to the way a Git tree is organized the standard org.eclipse.jgit.treewalk.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 org.eclipse.jgit.treewalk.TreeWalk#isSubtree() will return true and org.eclipse.jgit.treewalk.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 org.eclipse.jgit.dircache.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.

Field Summary

Modifier and TypeField and Description
private boolean
allTreesNamesMatchFastMinRef

True if all trees point to entries with equal names.

private AbstractTreeIterator
private static final int
Inherited from org.eclipse.jgit.treewalk.TreeWalk:
currentHeaddepthtrees

Constructor Summary

AccessConstructor and Description
public
NameConflictTreeWalk(Repository
the repository the walker will obtain data from.
repo
)

Create a new tree walker for a given repository.

public
NameConflictTreeWalk(Repository
the repository the walker will obtain data from.
repo
,
ObjectReader
the reader the walker will obtain tree data from.
or
)

Create a new tree walker for a given repository.

public
NameConflictTreeWalk(ObjectReader
the reader the walker will obtain tree data from.
or
)

Create a new tree walker for a given repository.

Method Summary

Modifier and TypeMethod and Description
private AbstractTreeIterator
private AbstractTreeIterator
private int
public boolean

Returns:

true if the current entry is covered by a directory/file conflict, false otherwise
isDirectoryFileConflict
()

True if the current entry is covered by a directory/file conflict.

private static boolean
pack-priv AbstractTreeIterator
min()

Overrides org.eclipse.jgit.treewalk.TreeWalk.min.

Returns an AbstractTreeIterator from trees with the smallest name, and sets its matches field.

private static boolean
private boolean
pack-priv void
pack-priv void
private boolean
pack-priv void
stopWalk()

Overrides org.eclipse.jgit.treewalk.TreeWalk.stopWalk.

Notify iterators the walk is aborting.

Inherited from org.eclipse.jgit.treewalk.TreeWalk:
addTreeaddTreecloseenterSubtreeexitSubtreeforPathforPathforPathforPathgetAttributesgetAttributesgetAttributesNodeProvidergetCheckoutEolStreamTypegetDepthgetEolStreamTypegetFileModegetFileModegetFiltergetFilterCommandgetNameStringgetObjectIdgetObjectIdgetObjectReadergetOperationTypegetPathLengthgetPathStringgetRawModegetRawPathgetSmudgeCommandgetSmudgeCommandgetTreegetTreegetTreeCountidEqualisPathMatchisPathPrefixisPathSuffixisPostChildrenisPostOrderTraversalisRecursiveisSubtreenextpathOfpathOfresetresetresetsetAttributesNodeProvidersetFiltersetHeadsetOperationTypesetPostOrderTraversalsetRecursive

Field Detail

allTreesNamesMatchFastMinRefback to summary
private boolean allTreesNamesMatchFastMinRef

True if all trees point to entries with equal names. If at least one tree iterator point to a different name or reached end of the tree, the value is false.

Note

if all iterators reached end of trees, the value is true.

dfConflictback to summary
private AbstractTreeIterator dfConflict
TREE_MODEback to summary
private static final int TREE_MODE

Constructor Detail

NameConflictTreeWalkback to summary
public NameConflictTreeWalk(Repository repo)

Create a new tree walker for a given repository.

Parameters
repo:Repository

the repository the walker will obtain data from.

NameConflictTreeWalkback to summary
public NameConflictTreeWalk(Repository repo, ObjectReader or)

Create a new tree walker for a given repository.

Parameters
repo:Repository

the repository the walker will obtain data from.

or:ObjectReader

the reader the walker will obtain tree data from.

Since
4.3
NameConflictTreeWalkback to summary
public NameConflictTreeWalk(ObjectReader or)

Create a new tree walker for a given repository.

Parameters
or:ObjectReader

the reader the walker will obtain tree data from.

Method Detail

combineDFback to summary
private AbstractTreeIterator combineDF(AbstractTreeIterator minRef) throws CorruptObjectException
fastMinback to summary
private AbstractTreeIterator fastMin()
getFirstNonEofTreeIndexback to summary
private int getFirstNonEofTreeIndex()
isDirectoryFileConflictback to summary
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:boolean

true if the current entry is covered by a directory/file conflict, false otherwise

isTreeback to summary
private static boolean isTree(AbstractTreeIterator p)
minback to summary
pack-priv AbstractTreeIterator min() throws CorruptObjectException

Overrides org.eclipse.jgit.treewalk.TreeWalk.min.

Doc from org.eclipse.jgit.treewalk.TreeWalk.min.

Returns an AbstractTreeIterator from trees with the smallest name, and sets its matches field. This may clobber matches in other trees. Other iterators at the same name will have their matches pointing to the same min() value.

Returns:AbstractTreeIterator

the smallest tree iterator available.

Annotations
@Override
Exceptions
CorruptObjectException:
if an object is corrupt
nameEqualback to summary
private static boolean nameEqual(final AbstractTreeIterator a, final AbstractTreeIterator b)
needsStopWalkback to summary
private boolean needsStopWalk()
popEntriesEqualback to summary
pack-priv void popEntriesEqual() throws CorruptObjectException

Overrides org.eclipse.jgit.treewalk.TreeWalk.popEntriesEqual.

Annotations
@Override
skipEntriesEqualback to summary
pack-priv void skipEntriesEqual() throws CorruptObjectException

Overrides org.eclipse.jgit.treewalk.TreeWalk.skipEntriesEqual.

Annotations
@Override
skipEntryback to summary
private boolean skipEntry(AbstractTreeIterator minRef) throws CorruptObjectException
stopWalkback to summary
pack-priv void stopWalk() throws IOException

Overrides org.eclipse.jgit.treewalk.TreeWalk.stopWalk.

Doc from org.eclipse.jgit.treewalk.TreeWalk.stopWalk.

Notify iterators the walk is aborting.

Primarily to notify DirCacheBuildIterator the walk is aborting so that it can copy any remaining entries.

Annotations
@Override
Exceptions
IOException:
if traversal of remaining entries throws an exception during object access. This should never occur as remaining trees should already be in memory, however the methods used to finish traversal are declared to throw IOException.