Package org.eclipse.jgit.diff
Class DiffEntry
java.lang.Object
org.eclipse.jgit.diff.DiffEntry
- Direct Known Subclasses:
FileHeader
A value class representing a change to a file
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
General type of change a single file-level patch describes.static enum
Specify the old or new side for more generalized access. -
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final AbbreviatedObjectId
Magical SHA1 used for file adds or deletesprotected DiffEntry.ChangeType
General type of change indicated by the patch.static final String
Magical file name used for file adds or deletes.protected Attribute
diff filter attributeprotected AbbreviatedObjectId
ObjectId listed on the index line for the new (post-image)protected FileMode
New mode of the file, if described by the patch, else null.protected String
File name of the new (post-image).protected AbbreviatedObjectId
ObjectId listed on the index line for the old (pre-image)protected FileMode
Old mode of the file, if described by the patch, else null.protected String
File name of the old (pre-image).protected int
Similarity score ifchangeType
is a copy or rename.private int
Bitset for marked flags of tree filters passed toscan(TreeWalk, boolean, TreeFilter...)
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) static DiffEntry
add
(String path, AnyObjectId id) breakModify
(DiffEntry entry) Breaks apart a DiffEntry into two entries, one DELETE and one ADD.(package private) static DiffEntry
delete
(String path, AnyObjectId id) Get the change typegetId
(DiffEntry.Side side) Get the object id.getMode
(DiffEntry.Side side) Get the mode associated with this file.getNewId()
Get the new object id from theindex
.Get the new file modeGet the new name associated with this file.getOldId()
Get the old object id from theindex
.Get the old file modeGet the old name associated with this file.getPath
(DiffEntry.Side side) Get the path associated with this file.int
getScore()
Get similarity scoreint
Get the raw tree filter marks, as set duringscan(TreeWalk, boolean, TreeFilter...)
.boolean
isMarked
(int index) Whether the mark tree filter with the specified index matched during scan or not, seescan(TreeWalk, boolean, TreeFilter...)
.(package private) static DiffEntry
(package private) static DiffEntry
pair
(DiffEntry.ChangeType changeType, DiffEntry src, DiffEntry dst, int score) Convert the TreeWalk into DiffEntry headers.Convert the TreeWalk into DiffEntry headers, depending onincludeTrees
it will add tree objects into result or not.scan
(TreeWalk walk, boolean includeTrees, TreeFilter[] markTreeFilters) Convert the TreeWalk into DiffEntry headers, depending onincludeTrees
it will add tree objects into result or not.toString()
-
Field Details
-
A_ZERO
Magical SHA1 used for file adds or deletes -
DEV_NULL
Magical file name used for file adds or deletes.- See Also:
-
oldPath
File name of the old (pre-image). -
newPath
File name of the new (post-image). -
diffAttribute
diff filter attribute- Since:
- 4.11
-
oldMode
Old mode of the file, if described by the patch, else null. -
newMode
New mode of the file, if described by the patch, else null. -
changeType
General type of change indicated by the patch. -
score
protected int scoreSimilarity score ifchangeType
is a copy or rename. -
oldId
ObjectId listed on the index line for the old (pre-image) -
newId
ObjectId listed on the index line for the new (post-image) -
treeFilterMarks
private int treeFilterMarksBitset for marked flags of tree filters passed toscan(TreeWalk, boolean, TreeFilter...)
-
-
Constructor Details
-
DiffEntry
protected DiffEntry()Create an empty DiffEntry
-
-
Method Details
-
scan
Convert the TreeWalk into DiffEntry headers.- Parameters:
walk
- the TreeWalk to walk through. Must have exactly two trees.- Returns:
- headers describing the changed files.
- Throws:
IOException
- the repository cannot be accessed.IllegalArgumentException
- When given TreeWalk doesn't have exactly two trees.
-
scan
Convert the TreeWalk into DiffEntry headers, depending onincludeTrees
it will add tree objects into result or not.- Parameters:
walk
- the TreeWalk to walk through. Must have exactly two trees and whenincludeTrees
parameter istrue
it can't be recursive.includeTrees
- include tree objects.- Returns:
- headers describing the changed files.
- Throws:
IOException
- the repository cannot be accessed.IllegalArgumentException
- whenincludeTrees
is true and given TreeWalk is recursive. Or when given TreeWalk doesn't have exactly two trees
-
scan
public static List<DiffEntry> scan(TreeWalk walk, boolean includeTrees, TreeFilter[] markTreeFilters) throws IOException Convert the TreeWalk into DiffEntry headers, depending onincludeTrees
it will add tree objects into result or not.- Parameters:
walk
- the TreeWalk to walk through. Must have exactly two trees and whenincludeTrees
parameter istrue
it can't be recursive.includeTrees
- include tree objects.markTreeFilters
- array of tree filters which will be tested for each entry. If an entry matches, the entry will later return true when queried through {isMarked(int)
(with the index from this passed array).- Returns:
- headers describing the changed files.
- Throws:
IOException
- the repository cannot be accessed.IllegalArgumentException
- whenincludeTrees
is true and given TreeWalk is recursive. Or when given TreeWalk doesn't have exactly two trees- Since:
- 2.3
-
add
-
delete
-
modify
-
breakModify
Breaks apart a DiffEntry into two entries, one DELETE and one ADD.- Parameters:
entry
- the DiffEntry to break apart.- Returns:
- a list containing two entries. Calling
getChangeType()
on the first entry will return ChangeType.DELETE. Calling it on the second entry will return ChangeType.ADD.
-
pair
-
getOldPath
Get the old name associated with this file.The meaning of the old name can differ depending on the semantic meaning of this patch:
- file add: always
/dev/null
- file modify: always
getNewPath()
- file delete: always the file being deleted
- file copy: source file the copy originates from
- file rename: source file the rename originates from
- Returns:
- old name for this file.
- file add: always
-
getNewPath
Get the new name associated with this file.The meaning of the new name can differ depending on the semantic meaning of this patch:
- file add: always the file being created
- file modify: always
getOldPath()
- file delete: always
/dev/null
- file copy: destination file the copy ends up at
- file rename: destination file the rename ends up at
- Returns:
- new name for this file.
-
getPath
Get the path associated with this file.- Parameters:
side
- which path to obtain.- Returns:
- name for this file.
-
getDiffAttribute
- Returns:
- the
Attribute
determining filters to be applied. - Since:
- 4.11
-
getOldMode
Get the old file mode- Returns:
- the old file mode, if described in the patch
-
getNewMode
Get the new file mode- Returns:
- the new file mode, if described in the patch
-
getMode
Get the mode associated with this file.- Parameters:
side
- which mode to obtain.- Returns:
- the mode.
-
getChangeType
Get the change type- Returns:
- the type of change this patch makes on
getNewPath()
-
getScore
public int getScore()Get similarity score- Returns:
- similarity score between
getOldPath()
andgetNewPath()
ifgetChangeType()
isDiffEntry.ChangeType.COPY
orDiffEntry.ChangeType.RENAME
.
-
getOldId
Get the old object id from theindex
.- Returns:
- the object id; null if there is no index line
-
getNewId
Get the new object id from theindex
.- Returns:
- the object id; null if there is no index line
-
isMarked
public boolean isMarked(int index) Whether the mark tree filter with the specified index matched during scan or not, seescan(TreeWalk, boolean, TreeFilter...)
. Example:TreeFilter filterA = ...; TreeFilter filterB = ...; List<DiffEntry> entries = DiffEntry.scan(walk, false, filterA, filterB); DiffEntry entry = entries.get(0); boolean filterAMatched = entry.isMarked(0); boolean filterBMatched = entry.isMarked(1);
Note that 0 corresponds to filterA because it was the first filter that was passed to scan.
To query more than one flag at once, see
getTreeFilterMarks()
.- Parameters:
index
- the index of the tree filter to check for (must be between 0 andInteger.SIZE
).- Returns:
- a boolean.
- Since:
- 2.3
-
getTreeFilterMarks
public int getTreeFilterMarks()Get the raw tree filter marks, as set duringscan(TreeWalk, boolean, TreeFilter...)
. SeeisMarked(int)
to query each mark individually.- Returns:
- the bitset of tree filter marks
- Since:
- 2.3
-
getId
Get the object id.- Parameters:
side
- the side of the id to get.- Returns:
- the object id; null if there is no index line
-
toString
-