Top Description Inners Fields Constructors Methods
org.eclipse.jgit.lib

public Class IndexDiff

extends Object
Class Inheritance
Imports
java.io.File, .IOException, java.nio.file.DirectoryIteratorException, .DirectoryStream, .Files, java.text.MessageFormat, java.util.ArrayList, .Collection, .Collections, .HashMap, .HashSet, .Map, .Set, org.eclipse.jgit.dircache.DirCache, .DirCacheEntry, .DirCacheIterator, org.eclipse.jgit.errors.ConfigInvalidException, .IncorrectObjectTypeException, .MissingObjectException, .StopWalkException, org.eclipse.jgit.internal.JGitText, org.eclipse.jgit.revwalk.RevWalk, org.eclipse.jgit.submodule.SubmoduleWalk, .SubmoduleWalk.IgnoreSubmoduleMode, org.eclipse.jgit.treewalk.AbstractTreeIterator, .EmptyTreeIterator, .FileTreeIterator, .TreeWalk, .TreeWalk.OperationType, .WorkingTreeIterator, org.eclipse.jgit.treewalk.filter.AndTreeFilter, .IndexDiffFilter, .SkipWorkTreeFilter, .TreeFilter

Compares the index, a tree, and the working directory Ignored files are not taken into account. The following information is retrieved:

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
public static enum
IndexDiff.StageState

Represents the state of the index for a certain path regarding the stages - which stages exist for a path and which not (base, ours, theirs).

public static interface
IndexDiff.WorkingTreeIteratorFactory

A factory to producing WorkingTreeIterators

Field Summary

Modifier and TypeField and Description
private Set<String>
private Set<String>
private Set<String>
private Map<String, IndexDiff.StageState>
private DirCache
private Map<FileMode, Set<String>>
private TreeFilter
private Set<String>
private SubmoduleWalk.IgnoreSubmoduleMode
private static final int
private IndexDiffFilter
private final WorkingTreeIterator
private Set<String>
private Set<String>
private Set<String>
private Set<String>
private final Repository
private Map<String, IndexDiff>
private static final int
private final AnyObjectId
private Set<String>
private static final int
private IndexDiff.WorkingTreeIteratorFactory

Constructor Summary

AccessConstructor and Description
public
IndexDiff(Repository repository, String
symbolic name e.g. HEAD An EmptyTreeIterator is used if revstr cannot be resolved.
revstr
,
WorkingTreeIterator
iterator for working directory
workingTreeIterator
)

Construct an IndexDiff

public
IndexDiff(Repository repository, ObjectId
tree id. If null, an EmptyTreeIterator is used.
objectId
,
WorkingTreeIterator
iterator for working directory
workingTreeIterator
)

Construct an Indexdiff

Method Summary

Modifier and TypeMethod and Description
private void
addConflict(String path, int stage)

public boolean

Returns:

if anything is different between index, tree, and workdir
diff
()

Run the diff operation.

public boolean

Returns:

if anything is different between index, tree, and workdir
diff
(RepositoryBuilderFactory
the RepositoryBuilderFactory to use to create builders to create submodule repositories, if needed; if null, submodule repositories will be built using a plain RepositoryBuilder.
factory
)

Run the diff operation.

public boolean

Returns:

if anything is different between index, tree, and workdir
diff
(final ProgressMonitor
for reporting progress, may be null
monitor
,
int
number or estimated files in the working tree
estWorkTreeSize
,
int
number of estimated entries in the cache
estIndexSize
,
final String title)

Run the diff operation.

public boolean

Returns:

if anything is different between index, tree, and workdir
diff
(ProgressMonitor
for reporting progress, may be null
monitor
,
int
number or estimated files in the working tree
estWorkTreeSize
,
int
number of estimated entries in the cache
estIndexSize
,
String title, RepositoryBuilderFactory
the RepositoryBuilderFactory to use to create builders to create submodule repositories, if needed; if null, submodule repositories will be built using a plain RepositoryBuilder.
factory
)

Run the diff operation.

public Set<String>

Returns:

list of files added to the index, not in the tree
getAdded
()

Get list of files added to the index, not in the tree

public Set<String>

Returns:

list of files with the flag assume-unchanged
getAssumeUnchanged
()

Get list of files with the flag assume-unchanged

public Set<String>

Returns:

list of files changed from tree to index
getChanged
()

Get list of files changed from tree to index

public Set<String>

Returns:

list of files that are in conflict, corresponds to the keys of getConflictingStageStates()
getConflicting
()

Get list of files that are in conflict, corresponds to the keys of getConflictingStageStates()

public Map<String, IndexDiff.StageState>

Returns:

the map from each path of getConflicting() to its corresponding org.eclipse.jgit.lib.IndexDiff.StageState
getConflictingStageStates
()

Get the map from each path of getConflicting() to its corresponding org.eclipse.jgit.lib.IndexDiff.StageState

public Set<String>

Returns:

list of files / folders that are ignored
getIgnoredNotInIndex
()

The method returns the list of ignored files and folders.

public FileMode

Returns:

file mode
getIndexMode
(String path)

Get the file mode of the given path in the index

public Set<String>

Returns:

list of files in index, but not filesystem
getMissing
()

Get list of files in index, but not filesystem

public Set<String>

Returns:

list of files modified on disk relative to the index
getModified
()

Get list of files modified on disk relative to the index

public Set<String>

Returns:

the list of paths that IndexDiff has detected to differ and have the given file mode
getPathsWithIndexMode
(FileMode mode)

Get the list of paths that IndexDiff has detected to differ and have the given file mode

public Set<String>

Returns:

list of files removed from index, but in tree
getRemoved
()

Get list of files removed from index, but in tree

public Set<String>

Returns:

list of files that are not ignored, and not in the index.
getUntracked
()

Get list of files that are not ignored, and not in the index.

public Set<String>

Returns:

list of folders containing only untracked files/folders
getUntrackedFolders
()

Get list of folders containing only untracked files/folders

private boolean
hasFiles(File directory)

private void
public void
public void
setIgnoreSubmoduleMode(SubmoduleWalk.IgnoreSubmoduleMode
defines how modifications in submodules are treated
mode
)

Defines how modifications in submodules are treated

public void
setWorkingTreeItFactory(IndexDiff.WorkingTreeIteratorFactory
working tree iterator factory
wTreeIt
)

Allows higher layers to set the factory for WorkingTreeIterators.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

addedback to summary
private Set<String> added
assumeUnchangedback to summary
private Set<String> assumeUnchanged
changedback to summary
private Set<String> changed
conflictsback to summary
private Map<String, IndexDiff.StageState> conflicts
dirCacheback to summary
private DirCache dirCache
fileModesback to summary
private Map<FileMode, Set<String>> fileModes
filterback to summary
private TreeFilter filter
ignoredback to summary
private Set<String> ignored
ignoreSubmoduleModeback to summary
private SubmoduleWalk.IgnoreSubmoduleMode ignoreSubmoduleMode
INDEXback to summary
private static final int INDEX
indexDiffFilterback to summary
private IndexDiffFilter indexDiffFilter
initialWorkingTreeIteratorback to summary
private final WorkingTreeIterator initialWorkingTreeIterator
missingback to summary
private Set<String> missing
missingSubmodulesback to summary
private Set<String> missingSubmodules
modifiedback to summary
private Set<String> modified
removedback to summary
private Set<String> removed
repositoryback to summary
private final Repository repository
submoduleIndexDiffsback to summary
private Map<String, IndexDiff> submoduleIndexDiffs
TREEback to summary
private static final int TREE
treeback to summary
private final AnyObjectId tree
untrackedback to summary
private Set<String> untracked
WORKDIRback to summary
private static final int WORKDIR
wTreeItback to summary
private IndexDiff.WorkingTreeIteratorFactory wTreeIt

Constructor Detail

IndexDiffback to summary
public IndexDiff(Repository repository, String revstr, WorkingTreeIterator workingTreeIterator) throws IOException

Construct an IndexDiff

Parameters
repository:Repository

a org.eclipse.jgit.lib.Repository object.

revstr:String

symbolic name e.g. HEAD An EmptyTreeIterator is used if revstr cannot be resolved.

workingTreeIterator:WorkingTreeIterator

iterator for working directory

Exceptions
IOException:
if an IO error occurred
IndexDiffback to summary
public IndexDiff(Repository repository, ObjectId objectId, WorkingTreeIterator workingTreeIterator) throws IOException

Construct an Indexdiff

Parameters
repository:Repository

a org.eclipse.jgit.lib.Repository object.

objectId:ObjectId

tree id. If null, an EmptyTreeIterator is used.

workingTreeIterator:WorkingTreeIterator

iterator for working directory

Exceptions
IOException:
if an IO error occurred

Method Detail

addConflictback to summary
private void addConflict(String path, int stage)
diffback to summary
public boolean diff() throws IOException

Run the diff operation. Until this is called, all lists will be empty. Use diff(ProgressMonitor, int, int, String) if a progress monitor is required.

Returns:boolean

if anything is different between index, tree, and workdir

Exceptions
IOException:
if an IO error occurred
diffback to summary
public boolean diff(RepositoryBuilderFactory factory) throws IOException

Run the diff operation. Until this is called, all lists will be empty. Use diff(ProgressMonitor, int, int, String, RepositoryBuilderFactory) if a progress monitor is required.

The operation may create repositories for submodules using builders provided by the given factory, if any, and will also close these submodule repositories again.

Parameters
factory:RepositoryBuilderFactory

the RepositoryBuilderFactory to use to create builders to create submodule repositories, if needed; if null, submodule repositories will be built using a plain RepositoryBuilder.

Returns:boolean

if anything is different between index, tree, and workdir

Exceptions
IOException:
if an IO error occurred
Since
5.6
diffback to summary
public boolean diff(final ProgressMonitor monitor, int estWorkTreeSize, int estIndexSize, final String title) throws IOException

Run the diff operation. Until this is called, all lists will be empty.

The operation may be aborted by the progress monitor. In that event it will report what was found before the cancel operation was detected. Callers should ignore the result if monitor.isCancelled() is true. If a progress monitor is not needed, callers should use diff() instead. Progress reporting is crude and approximate and only intended for informing the user.

Parameters
monitor:ProgressMonitor

for reporting progress, may be null

estWorkTreeSize:int

number or estimated files in the working tree

estIndexSize:int

number of estimated entries in the cache

title:String

a java.lang.String object.

Returns:boolean

if anything is different between index, tree, and workdir

Exceptions
IOException:
if an IO error occurred
diffback to summary
public boolean diff(ProgressMonitor monitor, int estWorkTreeSize, int estIndexSize, String title, RepositoryBuilderFactory factory) throws IOException

Run the diff operation. Until this is called, all lists will be empty.

The operation may be aborted by the progress monitor. In that event it will report what was found before the cancel operation was detected. Callers should ignore the result if monitor.isCancelled() is true. If a progress monitor is not needed, callers should use diff() instead. Progress reporting is crude and approximate and only intended for informing the user.

The operation may create repositories for submodules using builders provided by the given factory, if any, and will also close these submodule repositories again.

Parameters
monitor:ProgressMonitor

for reporting progress, may be null

estWorkTreeSize:int

number or estimated files in the working tree

estIndexSize:int

number of estimated entries in the cache

title:String

a java.lang.String object.

factory:RepositoryBuilderFactory

the RepositoryBuilderFactory to use to create builders to create submodule repositories, if needed; if null, submodule repositories will be built using a plain RepositoryBuilder.

Returns:boolean

if anything is different between index, tree, and workdir

Exceptions
IOException:
if an IO error occurred
Since
5.6
getAddedback to summary
public Set<String> getAdded()

Get list of files added to the index, not in the tree

Returns:Set<String>

list of files added to the index, not in the tree

getAssumeUnchangedback to summary
public Set<String> getAssumeUnchanged()

Get list of files with the flag assume-unchanged

Returns:Set<String>

list of files with the flag assume-unchanged

getChangedback to summary
public Set<String> getChanged()

Get list of files changed from tree to index

Returns:Set<String>

list of files changed from tree to index

getConflictingback to summary
public Set<String> getConflicting()

Get list of files that are in conflict, corresponds to the keys of getConflictingStageStates()

Returns:Set<String>

list of files that are in conflict, corresponds to the keys of getConflictingStageStates()

getConflictingStageStatesback to summary
public Map<String, IndexDiff.StageState> getConflictingStageStates()

Get the map from each path of getConflicting() to its corresponding org.eclipse.jgit.lib.IndexDiff.StageState

Returns:Map<String, IndexDiff.StageState>

the map from each path of getConflicting() to its corresponding org.eclipse.jgit.lib.IndexDiff.StageState

Since
3.0
getIgnoredNotInIndexback to summary
public Set<String> getIgnoredNotInIndex()

The method returns the list of ignored files and folders. Only the root folder of an ignored folder hierarchy is reported. If a/b/c is listed in the .gitignore then you should not expect a/b/c/d/e/f to be reported here. Only a/b/c will be reported. Furthermore only ignored files / folders are returned that are NOT in the index.

Returns:Set<String>

list of files / folders that are ignored

getIndexModeback to summary
public FileMode getIndexMode(String path)

Get the file mode of the given path in the index

Parameters
path:String

a java.lang.String object.

Returns:FileMode

file mode

getMissingback to summary
public Set<String> getMissing()

Get list of files in index, but not filesystem

Returns:Set<String>

list of files in index, but not filesystem

getModifiedback to summary
public Set<String> getModified()

Get list of files modified on disk relative to the index

Returns:Set<String>

list of files modified on disk relative to the index

getPathsWithIndexModeback to summary
public Set<String> getPathsWithIndexMode(FileMode mode)

Get the list of paths that IndexDiff has detected to differ and have the given file mode

Parameters
mode:FileMode

a org.eclipse.jgit.lib.FileMode object.

Returns:Set<String>

the list of paths that IndexDiff has detected to differ and have the given file mode

Since
3.6
getRemovedback to summary
public Set<String> getRemoved()

Get list of files removed from index, but in tree

Returns:Set<String>

list of files removed from index, but in tree

getUntrackedback to summary
public Set<String> getUntracked()

Get list of files that are not ignored, and not in the index.

Returns:Set<String>

list of files that are not ignored, and not in the index.

getUntrackedFoldersback to summary
public Set<String> getUntrackedFolders()

Get list of folders containing only untracked files/folders

Returns:Set<String>

list of folders containing only untracked files/folders

hasFilesback to summary
private boolean hasFiles(File directory)
recordFileModeback to summary
private void recordFileMode(String path, FileMode mode)
setFilterback to summary
public void setFilter(TreeFilter filter)

Sets a filter. Can be used e.g. for restricting the tree walk to a set of files.

Parameters
filter:TreeFilter

a org.eclipse.jgit.treewalk.filter.TreeFilter object.

setIgnoreSubmoduleModeback to summary
public void setIgnoreSubmoduleMode(SubmoduleWalk.IgnoreSubmoduleMode mode)

Defines how modifications in submodules are treated

Parameters
mode:SubmoduleWalk.IgnoreSubmoduleMode

defines how modifications in submodules are treated

Since
3.6
setWorkingTreeItFactoryback to summary
public void setWorkingTreeItFactory(IndexDiff.WorkingTreeIteratorFactory wTreeIt)

Allows higher layers to set the factory for WorkingTreeIterators.

Parameters
wTreeIt:IndexDiff.WorkingTreeIteratorFactory

working tree iterator factory

Since
3.6
org.eclipse.jgit.lib back to summary

private final Class IndexDiff.ProgressReportingFilter

extends TreeFilter
Class Inheritance

Field Summary

Modifier and TypeField and Description
private int
private final ProgressMonitor
private int
private final int
Inherited from org.eclipse.jgit.treewalk.filter.TreeFilter:
ALLANY_DIFF

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public TreeFilter
clone()

Implements abstract org.eclipse.jgit.treewalk.filter.TreeFilter.clone.

Creates and returns a copy of this object.

public boolean
include(TreeWalk
the walker the filter needs to examine.
walker
)

Implements abstract org.eclipse.jgit.treewalk.filter.TreeFilter.include.

Determine if the current entry is interesting to report.

public boolean
shouldBeRecursive()

Implements abstract org.eclipse.jgit.treewalk.filter.TreeFilter.shouldBeRecursive.

Does this tree filter require a recursive walk to match everything?

Inherited from org.eclipse.jgit.treewalk.filter.TreeFilter:
getPathsBestEffortmatchFilternegatetoString

Field Detail

countback to summary
private int count
monitorback to summary
private final ProgressMonitor monitor
stepSizeback to summary
private int stepSize
totalback to summary
private final int total

Constructor Detail

ProgressReportingFilterback to summary
private ProgressReportingFilter(ProgressMonitor monitor, int total)

Method Detail

cloneback to summary
public TreeFilter clone()

Implements abstract org.eclipse.jgit.treewalk.filter.TreeFilter.clone.

Doc from org.eclipse.jgit.treewalk.filter.TreeFilter.clone.

Creates and returns a copy of this object. The precise meaning of "copy" may depend on the class of the object. The general intent is that, for any object x, the expression:

x.clone() != x
will be true, and that the expression:
x.clone().getClass() == x.getClass()
will be true, but these are not absolute requirements. While it is typically the case that:
x.clone().equals(x)
will be true, this is not an absolute requirement.

By convention, the returned object should be obtained by calling super.clone. If a class and all of its superclasses (except Object) obey this convention, it will be the case that x.clone().getClass() == x.getClass().

By convention, the object returned by this method should be independent of this object (which is being cloned). To achieve this independence, it may be necessary to modify one or more fields of the object returned by super.clone before returning it. Typically, this means copying any mutable objects that comprise the internal "deep structure" of the object being cloned and replacing the references to these objects with references to the copies. If a class contains only primitive fields or references to immutable objects, then it is usually the case that no fields in the object returned by super.clone need to be modified. Clone this tree filter, including its parameters.

This is a deep clone. If this filter embeds objects or other filters it must also clone those, to ensure the instances do not share mutable data.

Returns:TreeFilter

Doc from java.lang.Object.clone.

a clone of this instance.

Annotations
@Override
includeback to summary
public boolean include(TreeWalk walker) throws MissingObjectException, IncorrectObjectTypeException, IOException

Implements abstract org.eclipse.jgit.treewalk.filter.TreeFilter.include.

Doc from org.eclipse.jgit.treewalk.filter.TreeFilter.include.

Determine if the current entry is interesting to report.

This method is consulted for subtree entries even if org.eclipse.jgit.treewalk.TreeWalk#isRecursive() is enabled. The consultation allows the filter to bypass subtree recursion on a case-by-case basis, even when recursion is enabled at the application level.

Parameters
walker:TreeWalk

the walker the filter needs to examine.

Returns:boolean

true if the current entry should be seen by the application; false to hide the entry.

Annotations
@Override
Exceptions
MissingObjectException:
an object the filter needs to consult to determine its answer does not exist in the Git repository the walker is operating on. Filtering this current walker entry is impossible without the object.
IncorrectObjectTypeException:
an object the filter needed to consult was not of the expected object type. This usually indicates a corrupt repository, as an object link is referencing the wrong type.
IOException:
a loose object or pack file could not be read to obtain data necessary for the filter to make its decision.
shouldBeRecursiveback to summary
public boolean shouldBeRecursive()

Implements abstract org.eclipse.jgit.treewalk.filter.TreeFilter.shouldBeRecursive.

Doc from org.eclipse.jgit.treewalk.filter.TreeFilter.shouldBeRecursive.

Does this tree filter require a recursive walk to match everything?

If this tree filter is matching on full entry path names and its pattern is looking for a '/' then the filter would require a recursive TreeWalk to accurately make its decisions. The walker is not required to enable recursive behavior for any particular filter, this is only a hint.

Returns:boolean

true if the filter would like to have the walker recurse into subtrees to make sure it matches everything correctly; false if the filter does not require entering subtrees.

Annotations
@Override
org.eclipse.jgit.lib back to summary

public final Enum IndexDiff.StageState

extends Enum<IndexDiff.StageState>
Class Inheritance

Represents the state of the index for a certain path regarding the stages - which stages exist for a path and which not (base, ours, theirs).

This is used for figuring out what kind of conflict occurred.

Since
3.0
See Also
IndexDiff#getConflictingStageStates()

Field Summary

Modifier and TypeField and Description
public static final IndexDiff.StageState
ADDED_BY_THEM

Only exists in theirs.

public static final IndexDiff.StageState
ADDED_BY_US

Only exists in ours.

public static final IndexDiff.StageState
BOTH_ADDED

Exists in ours and theirs, but not in base.

public static final IndexDiff.StageState
BOTH_DELETED

Exists in base, but neither in ours nor in theirs.

public static final IndexDiff.StageState
BOTH_MODIFIED

Exists in all stages, content conflict.

public static final IndexDiff.StageState
DELETED_BY_THEM

Exists in base and ours, but no in theirs.

public static final IndexDiff.StageState
DELETED_BY_US

Exists in base and theirs, but not in ours.

private final int

Constructor Summary

AccessConstructor and Description
private
StageState(int stageMask)

Method Summary

Modifier and TypeMethod and Description
pack-priv static IndexDiff.StageState
fromMask(int stageMask)

pack-priv int
public boolean

Returns:

whether there is a "base" stage entry
hasBase
()

Whether there is a "base" stage entry

public boolean

Returns:

whether there is an "ours" stage entry
hasOurs
()

Whether there is an "ours" stage entry

public boolean

Returns:

whether there is a "theirs" stage entry
hasTheirs
()

Whether there is a "theirs" stage entry

public static IndexDiff.StageState
public static IndexDiff.StageState[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

ADDED_BY_THEMback to summary
public static final IndexDiff.StageState ADDED_BY_THEM

Only exists in theirs.

ADDED_BY_USback to summary
public static final IndexDiff.StageState ADDED_BY_US

Only exists in ours.

BOTH_ADDEDback to summary
public static final IndexDiff.StageState BOTH_ADDED

Exists in ours and theirs, but not in base.

BOTH_DELETEDback to summary
public static final IndexDiff.StageState BOTH_DELETED

Exists in base, but neither in ours nor in theirs.

BOTH_MODIFIEDback to summary
public static final IndexDiff.StageState BOTH_MODIFIED

Exists in all stages, content conflict.

DELETED_BY_THEMback to summary
public static final IndexDiff.StageState DELETED_BY_THEM

Exists in base and ours, but no in theirs.

DELETED_BY_USback to summary
public static final IndexDiff.StageState DELETED_BY_US

Exists in base and theirs, but not in ours.

stageMaskback to summary
private final int stageMask

Constructor Detail

StageStateback to summary
private StageState(int stageMask)

Method Detail

fromMaskback to summary
pack-priv static IndexDiff.StageState fromMask(int stageMask)
getStageMaskback to summary
pack-priv int getStageMask()
hasBaseback to summary
public boolean hasBase()

Whether there is a "base" stage entry

Returns:boolean

whether there is a "base" stage entry

hasOursback to summary
public boolean hasOurs()

Whether there is an "ours" stage entry

Returns:boolean

whether there is an "ours" stage entry

hasTheirsback to summary
public boolean hasTheirs()

Whether there is a "theirs" stage entry

Returns:boolean

whether there is a "theirs" stage entry

valueOfback to summary
public static IndexDiff.StageState valueOf(String name)
valuesback to summary
public static IndexDiff.StageState[] values()
org.eclipse.jgit.lib back to summary

public Interface IndexDiff.WorkingTreeIteratorFactory


A factory to producing WorkingTreeIterators
Since
3.6

Method Summary

Modifier and TypeMethod and Description
public WorkingTreeIterator

Returns:

working tree iterator
getWorkingTreeIterator
(Repository
the repository
repo
)

Get working tree iterator

Method Detail

getWorkingTreeIteratorback to summary
public WorkingTreeIterator getWorkingTreeIterator(Repository repo)

Get working tree iterator

Parameters
repo:Repository

the repository

Returns:WorkingTreeIterator

working tree iterator