use of org.eclipse.jgit.diff.RenameDetector in project che by eclipse.
the class JGitDiffPage method commitToWorkingTree.
/**
* Show changes between specified revision and working tree.
*
* @param commitId
* id of commit
* @param formatter
* diff formatter
* @return list of diff entries
* @throws IOException
* if any i/o errors occurs
*/
private List<DiffEntry> commitToWorkingTree(String commitId, DiffFormatter formatter) throws IOException {
ObjectId commitA = repository.resolve(commitId);
if (commitA == null) {
File heads = new File(repository.getWorkTree().getPath() + "/.git/refs/heads");
if (heads.exists() && heads.list().length == 0) {
return Collections.emptyList();
}
throw new IllegalArgumentException("Invalid commit id " + commitId);
}
RevTree treeA;
try (RevWalk revWalkA = new RevWalk(repository)) {
treeA = revWalkA.parseTree(commitA);
}
List<DiffEntry> diff;
try (ObjectReader reader = repository.newObjectReader()) {
CanonicalTreeParser iterA = new CanonicalTreeParser();
iterA.reset(reader, treeA);
FileTreeIterator iterB = new FileTreeIterator(repository);
// Seems bug in DiffFormatter when work with working. Disable detect
// renames by formatter and do it later.
formatter.setDetectRenames(false);
diff = formatter.scan(iterA, iterB);
if (!params.isNoRenames()) {
// Detect renames.
RenameDetector renameDetector = createRenameDetector();
ContentSource.Pair sourcePairReader = new ContentSource.Pair(ContentSource.create(reader), ContentSource.create(iterB));
renameDetector.addAll(diff);
diff = renameDetector.compute(sourcePairReader, NullProgressMonitor.INSTANCE);
}
}
return diff;
}
use of org.eclipse.jgit.diff.RenameDetector in project che by eclipse.
the class JGitDiffPage method createRenameDetector.
private RenameDetector createRenameDetector() {
RenameDetector renameDetector = new RenameDetector(repository);
int renameLimit = params.getRenameLimit();
if (renameLimit > 0) {
renameDetector.setRenameLimit(renameLimit);
}
return renameDetector;
}
use of org.eclipse.jgit.diff.RenameDetector in project che by eclipse.
the class JGitDiffPage method indexToWorkingTree.
/**
* Show changes between index and working tree.
*
* @param formatter
* diff formatter
* @return list of diff entries
* @throws IOException
* if any i/o errors occurs
*/
private List<DiffEntry> indexToWorkingTree(DiffFormatter formatter) throws IOException {
DirCache dirCache = null;
ObjectReader reader = repository.newObjectReader();
List<DiffEntry> diff;
try {
dirCache = repository.lockDirCache();
DirCacheIterator iterA = new DirCacheIterator(dirCache);
FileTreeIterator iterB = new FileTreeIterator(repository);
// Seems bug in DiffFormatter when work with working. Disable detect
// renames by formatter and do it later.
formatter.setDetectRenames(false);
diff = formatter.scan(iterA, iterB);
if (!params.isNoRenames()) {
// Detect renames.
RenameDetector renameDetector = createRenameDetector();
ContentSource.Pair sourcePairReader = new ContentSource.Pair(ContentSource.create(reader), ContentSource.create(iterB));
renameDetector.addAll(diff);
diff = renameDetector.compute(sourcePairReader, NullProgressMonitor.INSTANCE);
}
} finally {
reader.close();
if (dirCache != null) {
dirCache.unlock();
}
}
return diff;
}
Aggregations