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

public Class DiffEntry

extends Object
Class Inheritance
Known Direct Subclasses
org.eclipse.jgit.patch.FileHeader
Imports
java.io.IOException, java.util.ArrayList, .Arrays, .List, org.eclipse.jgit.attributes.Attribute, org.eclipse.jgit.internal.JGitText, org.eclipse.jgit.lib.AbbreviatedObjectId, .AnyObjectId, .Constants, .FileMode, .MutableObjectId, .ObjectId, org.eclipse.jgit.treewalk.TreeWalk, org.eclipse.jgit.treewalk.filter.TreeFilter, .TreeFilterMarker

A value class representing a change to a file

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum
DiffEntry.ChangeType

General type of change a single file-level patch describes.

public static enum
DiffEntry.Side

Specify the old or new side for more generalized access.

Field Summary

Modifier and TypeField and Description
pack-priv static final AbbreviatedObjectId
A_ZERO

Magical SHA1 used for file adds or deletes

protected DiffEntry.ChangeType
changeType

General type of change indicated by the patch.

public static final String
DEV_NULL

Magical file name used for file adds or deletes.

protected Attribute
diffAttribute

diff filter attribute

protected AbbreviatedObjectId
newId

ObjectId listed on the index line for the new (post-image)

protected FileMode
newMode

New mode of the file, if described by the patch, else null.

protected String
newPath

File name of the new (post-image).

protected AbbreviatedObjectId
oldId

ObjectId listed on the index line for the old (pre-image)

protected FileMode
oldMode

Old mode of the file, if described by the patch, else null.

protected String
oldPath

File name of the old (pre-image).

protected int
score

Similarity score if changeType is a copy or rename.

private int
treeFilterMarks

Bitset for marked flags of tree filters passed to scan(TreeWalk, boolean, TreeFilter...)

Constructor Summary

AccessConstructor and Description
protected
DiffEntry()

Create an empty DiffEntry

Method Summary

Modifier and TypeMethod and Description
pack-priv static DiffEntry
pack-priv static List<DiffEntry>

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.
breakModify
(DiffEntry
the DiffEntry to break apart.
entry
)

Breaks apart a DiffEntry into two entries, one DELETE and one ADD.

pack-priv static DiffEntry
public DiffEntry.ChangeType

Returns:

the type of change this patch makes on getNewPath()
getChangeType
()

Get the change type

public Attribute

Returns:

the Attribute determining filters to be applied.
getDiffAttribute
()

Get diff attribute

public AbbreviatedObjectId

Returns:

the object id; null if there is no index line
getId
(DiffEntry.Side
the side of the id to get.
side
)

Get the object id.

public FileMode

Returns:

the mode.
getMode
(DiffEntry.Side
which mode to obtain.
side
)

Get the mode associated with this file.

public AbbreviatedObjectId

Returns:

the object id; null if there is no index line
getNewId
()

Get the new object id from the index.

public FileMode

Returns:

the new file mode, if described in the patch
getNewMode
()

Get the new file mode

public String

Returns:

new name for this file.
getNewPath
()

Get the new name associated with this file.

public AbbreviatedObjectId

Returns:

the object id; null if there is no index line
getOldId
()

Get the old object id from the index.

public FileMode

Returns:

the old file mode, if described in the patch
getOldMode
()

Get the old file mode

public String

Returns:

old name for this file.
getOldPath
()

Get the old name associated with this file.

public String

Returns:

name for this file.
getPath
(DiffEntry.Side
which path to obtain.
side
)

Get the path associated with this file.

public int
public int

Returns:

the bitset of tree filter marks
getTreeFilterMarks
()

Get the raw tree filter marks, as set during scan(TreeWalk, boolean, TreeFilter...).

public boolean

Returns:

a boolean.
isMarked
(int
the index of the tree filter to check for (must be between 0 and java.lang.Integer#SIZE).
index
)

Whether the mark tree filter with the specified index matched during scan or not, see scan(TreeWalk, boolean, TreeFilter...).

pack-priv static DiffEntry
modify(String path)

pack-priv static DiffEntry
pair(DiffEntry.ChangeType changeType, DiffEntry src, DiffEntry dst, int score)

public static List<DiffEntry>

Returns:

headers describing the changed files.
scan
(TreeWalk
the TreeWalk to walk through. Must have exactly two trees.
walk
)

Convert the TreeWalk into DiffEntry headers.

public static List<DiffEntry>

Returns:

headers describing the changed files.
scan
(TreeWalk
the TreeWalk to walk through. Must have exactly two trees and when includeTrees parameter is true it can't be recursive.
walk
,
boolean
include tree objects.
includeTrees
)

Convert the TreeWalk into DiffEntry headers, depending on includeTrees it will add tree objects into result or not.

public static List<DiffEntry>

Returns:

headers describing the changed files.
scan
(TreeWalk
the TreeWalk to walk through. Must have exactly two trees and when includeTrees parameter is true it can't be recursive.
walk
,
boolean
include tree objects.
includeTrees
,
TreeFilter[]
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).
markTreeFilters
)

Convert the TreeWalk into DiffEntry headers, depending on includeTrees it will add tree objects into result or not.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

A_ZEROback to summary
pack-priv static final AbbreviatedObjectId A_ZERO

Magical SHA1 used for file adds or deletes

changeTypeback to summary
protected DiffEntry.ChangeType changeType

General type of change indicated by the patch.

DEV_NULLback to summary
public static final String DEV_NULL

Magical file name used for file adds or deletes.

diffAttributeback to summary
protected Attribute diffAttribute

diff filter attribute

Since
4.11
newIdback to summary
protected AbbreviatedObjectId newId

ObjectId listed on the index line for the new (post-image)

newModeback to summary
protected FileMode newMode

New mode of the file, if described by the patch, else null.

newPathback to summary
protected String newPath

File name of the new (post-image).

oldIdback to summary
protected AbbreviatedObjectId oldId

ObjectId listed on the index line for the old (pre-image)

oldModeback to summary
protected FileMode oldMode

Old mode of the file, if described by the patch, else null.

oldPathback to summary
protected String oldPath

File name of the old (pre-image).

scoreback to summary
protected int score

Similarity score if changeType is a copy or rename.

treeFilterMarksback to summary
private int treeFilterMarks

Bitset for marked flags of tree filters passed to scan(TreeWalk, boolean, TreeFilter...)

Constructor Detail

DiffEntryback to summary
protected DiffEntry()

Create an empty DiffEntry

Method Detail

addback to summary
pack-priv static DiffEntry add(String path, AnyObjectId id)
breakModifyback to summary
pack-priv static List<DiffEntry> breakModify(DiffEntry entry)

Breaks apart a DiffEntry into two entries, one DELETE and one ADD.

Parameters
entry:DiffEntry

the DiffEntry to break apart.

Returns:List<DiffEntry>

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.

deleteback to summary
pack-priv static DiffEntry delete(String path, AnyObjectId id)
getChangeTypeback to summary
public DiffEntry.ChangeType getChangeType()

Get the change type

Returns:DiffEntry.ChangeType

the type of change this patch makes on getNewPath()

getDiffAttributeback to summary
public Attribute getDiffAttribute()

Get diff attribute

Returns:Attribute

the Attribute determining filters to be applied.

Since
4.11
getIdback to summary
public AbbreviatedObjectId getId(DiffEntry.Side side)

Get the object id.

Parameters
side:DiffEntry.Side

the side of the id to get.

Returns:AbbreviatedObjectId

the object id; null if there is no index line

getModeback to summary
public FileMode getMode(DiffEntry.Side side)

Get the mode associated with this file.

Parameters
side:DiffEntry.Side

which mode to obtain.

Returns:FileMode

the mode.

getNewIdback to summary
public AbbreviatedObjectId getNewId()

Get the new object id from the index.

Returns:AbbreviatedObjectId

the object id; null if there is no index line

getNewModeback to summary
public FileMode getNewMode()

Get the new file mode

Returns:FileMode

the new file mode, if described in the patch

getNewPathback to summary
public String 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:String

new name for this file.

getOldIdback to summary
public AbbreviatedObjectId getOldId()

Get the old object id from the index.

Returns:AbbreviatedObjectId

the object id; null if there is no index line

getOldModeback to summary
public FileMode getOldMode()

Get the old file mode

Returns:FileMode

the old file mode, if described in the patch

getOldPathback to summary
public String 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:String

old name for this file.

getPathback to summary
public String getPath(DiffEntry.Side side)

Get the path associated with this file.

Parameters
side:DiffEntry.Side

which path to obtain.

Returns:String

name for this file.

getScoreback to summary
public int getScore()

Get similarity score

Returns:int

similarity score between getOldPath() and getNewPath() if getChangeType() is org.eclipse.jgit.diff.DiffEntry.ChangeType#COPY or org.eclipse.jgit.diff.DiffEntry.ChangeType#RENAME.

getTreeFilterMarksback to summary
public int getTreeFilterMarks()

Get the raw tree filter marks, as set during scan(TreeWalk, boolean, TreeFilter...). See isMarked(int) to query each mark individually.

Returns:int

the bitset of tree filter marks

Since
2.3
isMarkedback to summary
public boolean isMarked(int index)

Whether the mark tree filter with the specified index matched during scan or not, see scan(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:int

the index of the tree filter to check for (must be between 0 and java.lang.Integer#SIZE).

Returns:boolean

a boolean.

Since
2.3
modifyback to summary
pack-priv static DiffEntry modify(String path)
pairback to summary
pack-priv static DiffEntry pair(DiffEntry.ChangeType changeType, DiffEntry src, DiffEntry dst, int score)
scanback to summary
public static List<DiffEntry> scan(TreeWalk walk) throws IOException

Convert the TreeWalk into DiffEntry headers.

Parameters
walk:TreeWalk

the TreeWalk to walk through. Must have exactly two trees.

Returns:List<DiffEntry>

headers describing the changed files.

Exceptions
IOException:
the repository cannot be accessed.
IllegalArgumentException:
When given TreeWalk doesn't have exactly two trees.
scanback to summary
public static List<DiffEntry> scan(TreeWalk walk, boolean includeTrees) throws IOException

Convert the TreeWalk into DiffEntry headers, depending on includeTrees it will add tree objects into result or not.

Parameters
walk:TreeWalk

the TreeWalk to walk through. Must have exactly two trees and when includeTrees parameter is true it can't be recursive.

includeTrees:boolean

include tree objects.

Returns:List<DiffEntry>

headers describing the changed files.

Exceptions
IOException:
the repository cannot be accessed.
IllegalArgumentException:
when includeTrees is true and given TreeWalk is recursive. Or when given TreeWalk doesn't have exactly two trees
scanback to summary
public static List<DiffEntry> scan(TreeWalk walk, boolean includeTrees, TreeFilter[] markTreeFilters) throws IOException

Convert the TreeWalk into DiffEntry headers, depending on includeTrees it will add tree objects into result or not.

Parameters
walk:TreeWalk

the TreeWalk to walk through. Must have exactly two trees and when includeTrees parameter is true it can't be recursive.

includeTrees:boolean

include tree objects.

markTreeFilters:TreeFilter[]

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:List<DiffEntry>

headers describing the changed files.

Exceptions
IOException:
the repository cannot be accessed.
IllegalArgumentException:
when includeTrees is true and given TreeWalk is recursive. Or when given TreeWalk doesn't have exactly two trees
Since
2.3
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@SuppressWarnings:nls
@Override
org.eclipse.jgit.diff back to summary

public final Enum DiffEntry.ChangeType

extends Enum<DiffEntry.ChangeType>
Class Inheritance

General type of change a single file-level patch describes.

Field Summary

Modifier and TypeField and Description
public static final DiffEntry.ChangeType
ADD

Add a new file to the project

public static final DiffEntry.ChangeType
COPY

Copy an existing file to a new location, keeping the original

public static final DiffEntry.ChangeType
DELETE

Delete an existing file from the project

public static final DiffEntry.ChangeType
MODIFY

Modify an existing file in the project (content and/or mode)

public static final DiffEntry.ChangeType
RENAME

Rename an existing file to a new location

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static DiffEntry.ChangeType
public static DiffEntry.ChangeType[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

ADDback to summary
public static final DiffEntry.ChangeType ADD

Add a new file to the project

COPYback to summary
public static final DiffEntry.ChangeType COPY

Copy an existing file to a new location, keeping the original

DELETEback to summary
public static final DiffEntry.ChangeType DELETE

Delete an existing file from the project

MODIFYback to summary
public static final DiffEntry.ChangeType MODIFY

Modify an existing file in the project (content and/or mode)

RENAMEback to summary
public static final DiffEntry.ChangeType RENAME

Rename an existing file to a new location

Constructor Detail

ChangeTypeback to summary
private ChangeType()

Method Detail

valueOfback to summary
public static DiffEntry.ChangeType valueOf(String name)
valuesback to summary
public static DiffEntry.ChangeType[] values()
org.eclipse.jgit.diff back to summary

public final Enum DiffEntry.Side

extends Enum<DiffEntry.Side>
Class Inheritance

Specify the old or new side for more generalized access.

Field Summary

Modifier and TypeField and Description
public static final DiffEntry.Side
NEW

The new side of a DiffEntry.

public static final DiffEntry.Side
OLD

The old side of a DiffEntry.

Constructor Summary

AccessConstructor and Description
private
Side()

Method Summary

Modifier and TypeMethod and Description
public static DiffEntry.Side
public static DiffEntry.Side[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

NEWback to summary
public static final DiffEntry.Side NEW

The new side of a DiffEntry.

OLDback to summary
public static final DiffEntry.Side OLD

The old side of a DiffEntry.

Constructor Detail

Sideback to summary
private Side()

Method Detail

valueOfback to summary
public static DiffEntry.Side valueOf(String name)
valuesback to summary
public static DiffEntry.Side[] values()