Example usage for org.eclipse.jgit.diff DiffFormatter getRenameDetector

List of usage examples for org.eclipse.jgit.diff DiffFormatter getRenameDetector

Introduction

In this page you can find the example usage for org.eclipse.jgit.diff DiffFormatter getRenameDetector.

Prototype

public RenameDetector getRenameDetector() 

Source Link

Document

Get rename detector

Usage

From source file:org.eclipse.che.git.impl.jgit.JGitDiffPage.java

License:Open Source License

/**
 * Show changes between specified revision and index. If
 * <code>commitId == null</code> then view changes between HEAD and index.
 *
 * @param commitId/*  w ww  .j a v a  2 s.  c  om*/
 *            id of commit, pass <code>null</code> is the same as pass HEAD
 * @param formatter
 *            diff formatter
 * @return list of diff entries
 * @throws IOException
 *             if any i/o errors occurs
 */
private List<DiffEntry> commitToIndex(String commitId, DiffFormatter formatter) throws IOException {
    if (commitId == null) {
        commitId = Constants.HEAD;
    }

    ObjectId commitA = repository.resolve(commitId);
    if (commitA == null) {
        throw new IllegalArgumentException("Invalid commit id " + commitId);
    }
    RevTree treeA;
    try (RevWalk revWalkA = new RevWalk(repository)) {
        treeA = revWalkA.parseTree(commitA);
    }

    DirCache dirCache = null;
    List<DiffEntry> diff;
    try (ObjectReader reader = repository.newObjectReader()) {
        dirCache = repository.lockDirCache();
        CanonicalTreeParser iterA = new CanonicalTreeParser();
        iterA.reset(reader, treeA);
        DirCacheIterator iterB = new DirCacheIterator(dirCache);
        if (!request.isNoRenames()) {
            // Use embedded RenameDetector it works well with index and
            // revision history.
            formatter.setDetectRenames(true);
            int renameLimit = request.getRenameLimit();
            if (renameLimit > 0) {
                formatter.getRenameDetector().setRenameLimit(renameLimit);
            }
        }
        diff = formatter.scan(iterA, iterB);
    } finally {
        if (dirCache != null) {
            dirCache.unlock();
        }
    }
    return diff;
}

From source file:org.eclipse.che.git.impl.jgit.JGitDiffPage.java

License:Open Source License

/**
 * Show changes between specified two revisions and index. If
 * <code>commitAId == null</code> then view changes between HEAD and revision commitBId.
 *
 * @param commitAId//from   ww w  .j  a va 2 s .c  o m
 *            id of commit A, pass <code>null</code> is the same as pass HEAD
 * @param commitBId
 *            id of commit B
 * @param formatter
 *            diff formatter
 * @return list of diff entries
 * @throws IOException
 *             if any i/o errors occurs
 */
private List<DiffEntry> commitToCommit(String commitAId, String commitBId, DiffFormatter formatter)
        throws IOException {
    if (commitAId == null) {
        commitAId = Constants.HEAD;
    }

    ObjectId commitA = repository.resolve(commitAId);
    if (commitA == null) {
        throw new IllegalArgumentException("Invalid commit id " + commitAId);
    }
    ObjectId commitB = repository.resolve(commitBId);
    if (commitB == null) {
        throw new IllegalArgumentException("Invalid commit id " + commitBId);
    }

    RevTree treeA;
    try (RevWalk revWalkA = new RevWalk(repository)) {
        treeA = revWalkA.parseTree(commitA);
    }

    RevTree treeB;
    try (RevWalk revWalkB = new RevWalk(repository)) {
        treeB = revWalkB.parseTree(commitB);
    }

    if (!request.isNoRenames()) {
        // Use embedded RenameDetector it works well with index and revision
        // history.
        formatter.setDetectRenames(true);
        int renameLimit = request.getRenameLimit();
        if (renameLimit > 0) {
            formatter.getRenameDetector().setRenameLimit(renameLimit);
        }
    }
    return formatter.scan(treeA, treeB);
}