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

public Class RenameDetector

extends Object
Class Inheritance
Static Imports
org.eclipse.jgit.diff.DiffEntry.Side.NEW, .DiffEntry.Side.OLD, org.eclipse.jgit.storage.pack.PackConfig.DEFAULT_BIG_FILE_THRESHOLD

Detect and resolve object renames.

Field Summary

Modifier and TypeField and Description
private List<DiffEntry>
private int
bigFileThreshold

File size threshold (in bytes) for detecting renames.

private int
breakScore

Similarity score required to keep modified file pairs together.

private List<DiffEntry>
private static final Comparator<DiffEntry>
private boolean
private List<DiffEntry>
private static final int
private final ObjectReader
private boolean
overRenameLimit

Set if the number of adds or deletes was over the limit.

private int
renameLimit

Limit in the number of files to consider for renames.

private int
renameScore

Similarity score required to pair an add/delete as a rename.

private boolean
skipContentRenamesForBinaryFiles

Skip detecting content renames for binary files.

Constructor Summary

AccessConstructor and Description
public
RenameDetector(Repository
the repository to use for rename detection
repo
)

Create a new rename detector for the given repository

public
RenameDetector(ObjectReader
reader to obtain objects from the repository with.
reader
,
DiffConfig
diff config specifying rename detection options.
cfg
)

Create a new rename detector with a specified reader and diff config.

Method Summary

Modifier and TypeMethod and Description
public void
add(DiffEntry
to add.
entry
)

Add an entry to be considered for rename detection.

public void
addAll(Collection<DiffEntry>
one or more entries to add.
entriesToAdd
)

Add entries to be considered for rename detection.

private void
private static DiffEntry

Returns:

the DiffEntry from <list> who's file path best matches <src>
bestPathMatch
(DiffEntry
the DiffEntry to try to find a match for
src
,
List<DiffEntry>
a list of DiffEntrys to search through
list
)

Find the best match by file path for a given DiffEntry from a list of DiffEntrys.

private void
private int
public List<DiffEntry>

Returns:

an unmodifiable list of org.eclipse.jgit.diff.DiffEntrys representing all files that have been changed.
compute
()

Detect renames in the current file set.

public List<DiffEntry>

Returns:

an unmodifiable list of org.eclipse.jgit.diff.DiffEntrys representing all files that have been changed.
compute
(ProgressMonitor
report progress during the detection phases.
pm
)

Detect renames in the current file set.

public List<DiffEntry>

Returns:

an unmodifiable list of org.eclipse.jgit.diff.DiffEntrys representing all files that have been changed.
compute
(ObjectReader
reader to obtain objects from the repository with.
reader
,
ProgressMonitor
report progress during the detection phases.
pm
)

Detect renames in the current file set.

public List<DiffEntry>

Returns:

an unmodifiable list of org.eclipse.jgit.diff.DiffEntrys representing all files that have been changed.
compute
(ContentSource.Pair
reader to obtain objects from the repository with.
reader
,
ProgressMonitor
report progress during the detection phases.
pm
)

Detect renames in the current file set.

private static DiffEntry
private static DiffEntry
private void
private void
public int

Returns:

threshold in bytes of the file size.
getBigFileThreshold
()

Get file size threshold for detecting renames.

public int

Returns:

the similarity score required to keep modified file pairs together. Any modify pairs that score below this will be broken apart into separate add/deletes. Values less than or equal to zero indicate that no modifies will be broken apart. Values over 100 cause all modify pairs to be broken.
getBreakScore
()

Get break score

public int

Returns:

limit on number of paths to perform inexact rename detection
getRenameLimit
()

Get rename limit

public int

Returns:

minimum score required to pair an add/delete as a rename. The score ranges are within the bounds of (0, 100).
getRenameScore
()

Get rename score

public boolean

Returns:

true if content renames should be skipped for binary files, false otherwise.
getSkipContentRenamesForBinaryFiles
()

Get skipping detecting content renames for binary files.

private static AbbreviatedObjectId
public boolean

Returns:

true if the detector has more file additions or removals than the rename limit is currently set to. In such configurations the detector will skip expensive computation.
isOverRenameLimit
()

Check if the detector is over the rename limit.

private static FileMode
private static String
private HashMap<AbbreviatedObjectId, Object>
private void
public void
reset()

Reset this rename detector for another rename detection pass.

pack-priv static boolean
public void
setBigFileThreshold(int
file size threshold in bytes.
threshold
)

Set the file size threshold for detecting renames.

public void
setBreakScore(int
the similarity score required to keep modified file pairs together. Any modify pairs that score below this will be broken apart into separate add/deletes. Values less than or equal to zero indicate that no modifies will be broken apart. Values over 100 cause all modify pairs to be broken.
breakScore
)

Set break score

public void
setRenameLimit(int
new file limit. 0 means no limit; a negative number means no inexact rename detection will be performed, only exact rename detection.
limit
)

Set the limit on the number of files to perform inexact rename detection.

public void
setRenameScore(int
new rename score, must be within [0, 100].
score
)

Set the minimum score required to pair an add/delete as a rename.

public void
setSkipContentRenamesForBinaryFiles(boolean
true if content renames should be skipped for binary files, false otherwise.
value
)

Sets skipping detecting content renames for binary files.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

addedback to summary
private List<DiffEntry> added
bigFileThresholdback to summary
private int bigFileThreshold

File size threshold (in bytes) for detecting renames. Files larger than this size will not be processed for renames.

breakScoreback to summary
private int breakScore

Similarity score required to keep modified file pairs together. Any modified file pairs with a similarity score below this will be broken apart.

deletedback to summary
private List<DiffEntry> deleted
DIFF_COMPARATORback to summary
private static final Comparator<DiffEntry> DIFF_COMPARATOR
doneback to summary
private boolean done
entriesback to summary
private List<DiffEntry> entries
EXACT_RENAME_SCOREback to summary
private static final int EXACT_RENAME_SCORE
objectReaderback to summary
private final ObjectReader objectReader
overRenameLimitback to summary
private boolean overRenameLimit

Set if the number of adds or deletes was over the limit.

renameLimitback to summary
private int renameLimit

Limit in the number of files to consider for renames.

renameScoreback to summary
private int renameScore

Similarity score required to pair an add/delete as a rename.

skipContentRenamesForBinaryFilesback to summary
private boolean skipContentRenamesForBinaryFiles

Skip detecting content renames for binary files. Content renames are those that are not exact, that is with a slight content modification between the two files.

Constructor Detail

RenameDetectorback to summary
public RenameDetector(Repository repo)

Create a new rename detector for the given repository

Parameters
repo:Repository

the repository to use for rename detection

RenameDetectorback to summary
public RenameDetector(ObjectReader reader, DiffConfig cfg)

Create a new rename detector with a specified reader and diff config.

Parameters
reader:ObjectReader

reader to obtain objects from the repository with.

cfg:DiffConfig

diff config specifying rename detection options.

Since
3.0

Method Detail

addback to summary
public void add(DiffEntry entry)

Add an entry to be considered for rename detection.

Parameters
entry:DiffEntry

to add.

Exceptions
IllegalStateException:
if getEntries was already invoked.
addAllback to summary
public void addAll(Collection<DiffEntry> entriesToAdd)

Add entries to be considered for rename detection.

Parameters
entriesToAdd:Collection<DiffEntry>

one or more entries to add.

Exceptions
IllegalStateException:
if getEntries was already invoked.
advanceOrCancelback to summary
private void advanceOrCancel(ProgressMonitor pm) throws CanceledException
bestPathMatchback to summary
private static DiffEntry bestPathMatch(DiffEntry src, List<DiffEntry> list)

Find the best match by file path for a given DiffEntry from a list of DiffEntrys. The returned DiffEntry will be of the same type as <src>. If no DiffEntry can be found that has the same type, this method will return null.

Parameters
src:DiffEntry

the DiffEntry to try to find a match for

list:List<DiffEntry>

a list of DiffEntrys to search through

Returns:DiffEntry

the DiffEntry from <list> who's file path best matches <src>

breakModifiesback to summary
private void breakModifies(ContentSource.Pair reader, ProgressMonitor pm) throws IOException, CanceledException
calculateModifyScoreback to summary
private int calculateModifyScore(ContentSource.Pair reader, DiffEntry d) throws IOException
computeback to summary
public List<DiffEntry> compute() throws IOException

Detect renames in the current file set.

This convenience function runs without a progress monitor.

Returns:List<DiffEntry>

an unmodifiable list of org.eclipse.jgit.diff.DiffEntrys representing all files that have been changed.

Exceptions
IOException:
file contents cannot be read from the repository.
computeback to summary
public List<DiffEntry> compute(ProgressMonitor pm) throws IOException, CanceledException

Detect renames in the current file set.

Parameters
pm:ProgressMonitor

report progress during the detection phases.

Returns:List<DiffEntry>

an unmodifiable list of org.eclipse.jgit.diff.DiffEntrys representing all files that have been changed.

Exceptions
IOException:
file contents cannot be read from the repository.
CanceledException:
if rename detection was cancelled
computeback to summary
public List<DiffEntry> compute(ObjectReader reader, ProgressMonitor pm) throws IOException, CanceledException

Detect renames in the current file set.

Parameters
reader:ObjectReader

reader to obtain objects from the repository with.

pm:ProgressMonitor

report progress during the detection phases.

Returns:List<DiffEntry>

an unmodifiable list of org.eclipse.jgit.diff.DiffEntrys representing all files that have been changed.

Exceptions
IOException:
file contents cannot be read from the repository.
CanceledException:
if rename detection was cancelled
computeback to summary
public List<DiffEntry> compute(ContentSource.Pair reader, ProgressMonitor pm) throws IOException, CanceledException

Detect renames in the current file set.

Parameters
reader:ContentSource.Pair

reader to obtain objects from the repository with.

pm:ProgressMonitor

report progress during the detection phases.

Returns:List<DiffEntry>

an unmodifiable list of org.eclipse.jgit.diff.DiffEntrys representing all files that have been changed.

Exceptions
IOException:
file contents cannot be read from the repository.
CanceledException:
if rename detection was cancelled
exactCopyback to summary
private static DiffEntry exactCopy(DiffEntry src, DiffEntry dst)
exactRenameback to summary
private static DiffEntry exactRename(DiffEntry src, DiffEntry dst)
findContentRenamesback to summary
private void findContentRenames(ContentSource.Pair reader, ProgressMonitor pm) throws IOException, CanceledException
findExactRenamesback to summary
private void findExactRenames(ProgressMonitor pm) throws CanceledException
Annotations
@SuppressWarnings:unchecked
getBigFileThresholdback to summary
public int getBigFileThreshold()

Get file size threshold for detecting renames. Files larger than this size will not be processed for rename detection.

Returns:int

threshold in bytes of the file size.

Since
5.12
getBreakScoreback to summary
public int getBreakScore()

Get break score

Returns:int

the similarity score required to keep modified file pairs together. Any modify pairs that score below this will be broken apart into separate add/deletes. Values less than or equal to zero indicate that no modifies will be broken apart. Values over 100 cause all modify pairs to be broken.

getRenameLimitback to summary
public int getRenameLimit()

Get rename limit

Returns:int

limit on number of paths to perform inexact rename detection

getRenameScoreback to summary
public int getRenameScore()

Get rename score

Returns:int

minimum score required to pair an add/delete as a rename. The score ranges are within the bounds of (0, 100).

getSkipContentRenamesForBinaryFilesback to summary
public boolean getSkipContentRenamesForBinaryFiles()

Get skipping detecting content renames for binary files.

Returns:boolean

true if content renames should be skipped for binary files, false otherwise.

Since
5.12
idback to summary
private static AbbreviatedObjectId id(DiffEntry de)
isOverRenameLimitback to summary
public boolean isOverRenameLimit()

Check if the detector is over the rename limit.

This method can be invoked either before or after getEntries has been used to perform rename detection.

Returns:boolean

true if the detector has more file additions or removals than the rename limit is currently set to. In such configurations the detector will skip expensive computation.

modeback to summary
private static FileMode mode(DiffEntry de)
pathback to summary
private static String path(DiffEntry de)
populateMapback to summary
private HashMap<AbbreviatedObjectId, Object> populateMap(List<DiffEntry> diffEntries, ProgressMonitor pm) throws CanceledException
Annotations
@SuppressWarnings:unchecked
rejoinModifiesback to summary
private void rejoinModifies(ProgressMonitor pm) throws CanceledException
resetback to summary
public void reset()

Reset this rename detector for another rename detection pass.

sameTypeback to summary
pack-priv static boolean sameType(FileMode a, FileMode b)
setBigFileThresholdback to summary
public void setBigFileThreshold(int threshold)

Set the file size threshold for detecting renames. Files larger than this threshold will be skipped during rename detection computation.

Parameters
threshold:int

file size threshold in bytes.

Since
5.12
setBreakScoreback to summary
public void setBreakScore(int breakScore)

Set break score

Parameters
breakScore:int

the similarity score required to keep modified file pairs together. Any modify pairs that score below this will be broken apart into separate add/deletes. Values less than or equal to zero indicate that no modifies will be broken apart. Values over 100 cause all modify pairs to be broken.

setRenameLimitback to summary
public void setRenameLimit(int limit)

Set the limit on the number of files to perform inexact rename detection.

The rename detector has to build a square matrix of the rename limit on each side, then perform that many file compares to determine similarity. If 1000 files are added, and 1000 files are deleted, a 1000*1000 matrix must be allocated, and 1,000,000 file compares may need to be performed.

Parameters
limit:int

new file limit. 0 means no limit; a negative number means no inexact rename detection will be performed, only exact rename detection.

setRenameScoreback to summary
public void setRenameScore(int score)

Set the minimum score required to pair an add/delete as a rename.

When comparing two files together their score must be greater than or equal to the rename score for them to be considered a rename match. The score is computed based on content similarity, so a score of 60 implies that approximately 60% of the bytes in the files are identical.

Parameters
score:int

new rename score, must be within [0, 100].

Exceptions
IllegalArgumentException:
the score was not within [0, 100].
setSkipContentRenamesForBinaryFilesback to summary
public void setSkipContentRenamesForBinaryFiles(boolean value)

Sets skipping detecting content renames for binary files.

Parameters
value:boolean

true if content renames should be skipped for binary files, false otherwise.

Since
5.12