Example usage for org.eclipse.jgit.diff RenameDetector getRenameScore

List of usage examples for org.eclipse.jgit.diff RenameDetector getRenameScore

Introduction

In this page you can find the example usage for org.eclipse.jgit.diff RenameDetector getRenameScore.

Prototype

public int getRenameScore() 

Source Link

Document

Get rename score

Usage

From source file:svnserver.repository.git.GitRepository.java

License:GNU General Public License

@NotNull
private Map<String, String> collectRename(@NotNull GitFile oldTree, @NotNull GitFile newTree)
        throws IOException {
    if (!renameDetection) {
        return Collections.emptyMap();
    }/*  w  w  w  .j ava2s  .  c  o  m*/
    final GitObject<ObjectId> oldTreeId = oldTree.getObjectId();
    final GitObject<ObjectId> newTreeId = newTree.getObjectId();
    if (oldTreeId == null || newTreeId == null || !Objects.equals(oldTreeId.getRepo(), newTreeId.getRepo())) {
        return Collections.emptyMap();
    }
    final TreeWalk tw = new TreeWalk(repository);
    tw.setRecursive(true);
    tw.addTree(oldTree.getObjectId().getObject());
    tw.addTree(newTree.getObjectId().getObject());

    final RenameDetector rd = new RenameDetector(repository);
    rd.addAll(DiffEntry.scan(tw));

    final Map<String, String> result = new HashMap<>();
    for (DiffEntry diff : rd.compute(tw.getObjectReader(), null)) {
        if (diff.getScore() >= rd.getRenameScore()) {
            result.put(StringHelper.normalize(diff.getNewPath()), StringHelper.normalize(diff.getOldPath()));
        }
    }
    return result;
}