Class IndexDiff
- java.lang.Object
-
- org.eclipse.jgit.lib.IndexDiff
-
public class IndexDiff extends java.lang.Object
Compares the index, a tree, and the working directory Ignored files are not taken into account. The following information is retrieved:- added files
- changed files
- removed files
- missing files
- modified files
- conflicting files
- untracked files
- files with assume-unchanged flag
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
IndexDiff.ProgressReportingFilter
static class
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).static interface
IndexDiff.WorkingTreeIteratorFactory
A factory to producing WorkingTreeIterators
-
Field Summary
Fields Modifier and Type Field Description private java.util.Set<java.lang.String>
added
private java.util.Set<java.lang.String>
assumeUnchanged
private java.util.Set<java.lang.String>
changed
private java.util.Map<java.lang.String,IndexDiff.StageState>
conflicts
private DirCache
dirCache
private java.util.Map<FileMode,java.util.Set<java.lang.String>>
fileModes
private TreeFilter
filter
private java.util.Set<java.lang.String>
ignored
private SubmoduleWalk.IgnoreSubmoduleMode
ignoreSubmoduleMode
private static int
INDEX
private IndexDiffFilter
indexDiffFilter
private WorkingTreeIterator
initialWorkingTreeIterator
private java.util.Set<java.lang.String>
missing
private java.util.Set<java.lang.String>
missingSubmodules
private java.util.Set<java.lang.String>
modified
private java.util.Set<java.lang.String>
removed
private Repository
repository
private java.util.Map<java.lang.String,IndexDiff>
submoduleIndexDiffs
private AnyObjectId
tree
private static int
TREE
private java.util.Set<java.lang.String>
untracked
private static int
WORKDIR
private IndexDiff.WorkingTreeIteratorFactory
wTreeIt
-
Constructor Summary
Constructors Constructor Description IndexDiff(Repository repository, java.lang.String revstr, WorkingTreeIterator workingTreeIterator)
Construct an IndexDiffIndexDiff(Repository repository, ObjectId objectId, WorkingTreeIterator workingTreeIterator)
Construct an Indexdiff
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
addConflict(java.lang.String path, int stage)
boolean
diff()
Run the diff operation.boolean
diff(ProgressMonitor monitor, int estWorkTreeSize, int estIndexSize, java.lang.String title)
Run the diff operation.boolean
diff(ProgressMonitor monitor, int estWorkTreeSize, int estIndexSize, java.lang.String title, RepositoryBuilderFactory factory)
Run the diff operation.boolean
diff(RepositoryBuilderFactory factory)
Run the diff operation.java.util.Set<java.lang.String>
getAdded()
Get list of files added to the index, not in the treejava.util.Set<java.lang.String>
getAssumeUnchanged()
Get list of files with the flag assume-unchangedjava.util.Set<java.lang.String>
getChanged()
Get list of files changed from tree to indexjava.util.Set<java.lang.String>
getConflicting()
Get list of files that are in conflict, corresponds to the keys ofgetConflictingStageStates()
java.util.Map<java.lang.String,IndexDiff.StageState>
getConflictingStageStates()
Get the map from each path ofgetConflicting()
to its correspondingIndexDiff.StageState
java.util.Set<java.lang.String>
getIgnoredNotInIndex()
The method returns the list of ignored files and folders.FileMode
getIndexMode(java.lang.String path)
Get the file mode of the given path in the indexjava.util.Set<java.lang.String>
getMissing()
Get list of files in index, but not filesystemjava.util.Set<java.lang.String>
getModified()
Get list of files modified on disk relative to the indexjava.util.Set<java.lang.String>
getPathsWithIndexMode(FileMode mode)
Get the list of paths that IndexDiff has detected to differ and have the given file modejava.util.Set<java.lang.String>
getRemoved()
Get list of files removed from index, but in treejava.util.Set<java.lang.String>
getUntracked()
Get list of files that are not ignored, and not in the index.java.util.Set<java.lang.String>
getUntrackedFolders()
Get list of folders containing only untracked files/foldersprivate boolean
hasFiles(java.io.File directory)
private boolean
isEntryGitLink(AbstractTreeIterator ti)
private void
recordFileMode(java.lang.String path, FileMode mode)
void
setFilter(TreeFilter filter)
Sets a filter.void
setIgnoreSubmoduleMode(SubmoduleWalk.IgnoreSubmoduleMode mode)
Defines how modifications in submodules are treatedvoid
setWorkingTreeItFactory(IndexDiff.WorkingTreeIteratorFactory wTreeIt)
Allows higher layers to set the factory for WorkingTreeIterators.
-
-
-
Field Detail
-
TREE
private static final int TREE
- See Also:
- Constant Field Values
-
INDEX
private static final int INDEX
- See Also:
- Constant Field Values
-
WORKDIR
private static final int WORKDIR
- See Also:
- Constant Field Values
-
repository
private final Repository repository
-
tree
private final AnyObjectId tree
-
filter
private TreeFilter filter
-
initialWorkingTreeIterator
private final WorkingTreeIterator initialWorkingTreeIterator
-
added
private java.util.Set<java.lang.String> added
-
changed
private java.util.Set<java.lang.String> changed
-
removed
private java.util.Set<java.lang.String> removed
-
missing
private java.util.Set<java.lang.String> missing
-
missingSubmodules
private java.util.Set<java.lang.String> missingSubmodules
-
modified
private java.util.Set<java.lang.String> modified
-
untracked
private java.util.Set<java.lang.String> untracked
-
conflicts
private java.util.Map<java.lang.String,IndexDiff.StageState> conflicts
-
ignored
private java.util.Set<java.lang.String> ignored
-
assumeUnchanged
private java.util.Set<java.lang.String> assumeUnchanged
-
dirCache
private DirCache dirCache
-
indexDiffFilter
private IndexDiffFilter indexDiffFilter
-
submoduleIndexDiffs
private java.util.Map<java.lang.String,IndexDiff> submoduleIndexDiffs
-
ignoreSubmoduleMode
private SubmoduleWalk.IgnoreSubmoduleMode ignoreSubmoduleMode
-
fileModes
private java.util.Map<FileMode,java.util.Set<java.lang.String>> fileModes
-
wTreeIt
private IndexDiff.WorkingTreeIteratorFactory wTreeIt
-
-
Constructor Detail
-
IndexDiff
public IndexDiff(Repository repository, java.lang.String revstr, WorkingTreeIterator workingTreeIterator) throws java.io.IOException
Construct an IndexDiff- Parameters:
repository
- aRepository
object.revstr
- symbolic name e.g. HEAD An EmptyTreeIterator is used ifrevstr
cannot be resolved.workingTreeIterator
- iterator for working directory- Throws:
java.io.IOException
-
IndexDiff
public IndexDiff(Repository repository, ObjectId objectId, WorkingTreeIterator workingTreeIterator) throws java.io.IOException
Construct an Indexdiff- Parameters:
repository
- aRepository
object.objectId
- tree id. If null, an EmptyTreeIterator is used.workingTreeIterator
- iterator for working directory- Throws:
java.io.IOException
-
-
Method Detail
-
setIgnoreSubmoduleMode
public void setIgnoreSubmoduleMode(SubmoduleWalk.IgnoreSubmoduleMode mode)
Defines how modifications in submodules are treated- Parameters:
mode
- defines how modifications in submodules are treated- Since:
- 3.6
-
setWorkingTreeItFactory
public void setWorkingTreeItFactory(IndexDiff.WorkingTreeIteratorFactory wTreeIt)
Allows higher layers to set the factory for WorkingTreeIterators.- Parameters:
wTreeIt
-- Since:
- 3.6
-
setFilter
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
- aTreeFilter
object.
-
diff
public boolean diff() throws java.io.IOException
Run the diff operation. Until this is called, all lists will be empty. Usediff(ProgressMonitor, int, int, String)
if a progress monitor is required.- Returns:
- if anything is different between index, tree, and workdir
- Throws:
java.io.IOException
-
diff
public boolean diff(RepositoryBuilderFactory factory) throws java.io.IOException
Run the diff operation. Until this is called, all lists will be empty. Usediff(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
- theRepositoryBuilderFactory
to use to create builders to create submodule repositories, if needed; ifnull
, submodule repositories will be built using a plainRepositoryBuilder
.- Returns:
- if anything is different between index, tree, and workdir
- Throws:
java.io.IOException
- Since:
- 5.6
-
diff
public boolean diff(ProgressMonitor monitor, int estWorkTreeSize, int estIndexSize, java.lang.String title) throws java.io.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
- for reporting progress, may be nullestWorkTreeSize
- number or estimated files in the working treeestIndexSize
- number of estimated entries in the cachetitle
- aString
object.- Returns:
- if anything is different between index, tree, and workdir
- Throws:
java.io.IOException
-
diff
public boolean diff(ProgressMonitor monitor, int estWorkTreeSize, int estIndexSize, java.lang.String title, RepositoryBuilderFactory factory) throws java.io.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
- for reporting progress, may be nullestWorkTreeSize
- number or estimated files in the working treeestIndexSize
- number of estimated entries in the cachetitle
- aString
object.factory
- theRepositoryBuilderFactory
to use to create builders to create submodule repositories, if needed; ifnull
, submodule repositories will be built using a plainRepositoryBuilder
.- Returns:
- if anything is different between index, tree, and workdir
- Throws:
java.io.IOException
- Since:
- 5.6
-
hasFiles
private boolean hasFiles(java.io.File directory)
-
recordFileMode
private void recordFileMode(java.lang.String path, FileMode mode)
-
isEntryGitLink
private boolean isEntryGitLink(AbstractTreeIterator ti)
-
addConflict
private void addConflict(java.lang.String path, int stage)
-
getAdded
public java.util.Set<java.lang.String> getAdded()
Get list of files added to the index, not in the tree- Returns:
- list of files added to the index, not in the tree
-
getChanged
public java.util.Set<java.lang.String> getChanged()
Get list of files changed from tree to index- Returns:
- list of files changed from tree to index
-
getRemoved
public java.util.Set<java.lang.String> getRemoved()
Get list of files removed from index, but in tree- Returns:
- list of files removed from index, but in tree
-
getMissing
public java.util.Set<java.lang.String> getMissing()
Get list of files in index, but not filesystem- Returns:
- list of files in index, but not filesystem
-
getModified
public java.util.Set<java.lang.String> getModified()
Get list of files modified on disk relative to the index- Returns:
- list of files modified on disk relative to the index
-
getUntracked
public java.util.Set<java.lang.String> getUntracked()
Get list of files that are not ignored, and not in the index.- Returns:
- list of files that are not ignored, and not in the index.
-
getConflicting
public java.util.Set<java.lang.String> getConflicting()
Get list of files that are in conflict, corresponds to the keys ofgetConflictingStageStates()
- Returns:
- list of files that are in conflict, corresponds to the keys of
getConflictingStageStates()
-
getConflictingStageStates
public java.util.Map<java.lang.String,IndexDiff.StageState> getConflictingStageStates()
Get the map from each path ofgetConflicting()
to its correspondingIndexDiff.StageState
- Returns:
- the map from each path of
getConflicting()
to its correspondingIndexDiff.StageState
- Since:
- 3.0
-
getIgnoredNotInIndex
public java.util.Set<java.lang.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:
- list of files / folders that are ignored
-
getAssumeUnchanged
public java.util.Set<java.lang.String> getAssumeUnchanged()
Get list of files with the flag assume-unchanged- Returns:
- list of files with the flag assume-unchanged
-
getUntrackedFolders
public java.util.Set<java.lang.String> getUntrackedFolders()
Get list of folders containing only untracked files/folders- Returns:
- list of folders containing only untracked files/folders
-
getIndexMode
public FileMode getIndexMode(java.lang.String path)
Get the file mode of the given path in the index- Parameters:
path
- aString
object.- Returns:
- file mode
-
getPathsWithIndexMode
public java.util.Set<java.lang.String> getPathsWithIndexMode(FileMode mode)
Get the list of paths that IndexDiff has detected to differ and have the given file mode- Parameters:
mode
- aFileMode
object.- Returns:
- the list of paths that IndexDiff has detected to differ and have the given file mode
- Since:
- 3.6
-
-