/** * Detect renames in the current file set. * <p> * This convenience function runs without a progress monitor. * * @return an unmodifiable list of {@link org.eclipse.jgit.diff.DiffEntry}s * representing all files that have been changed. * @throws java.io.IOException * file contents cannot be read from the repository. */ public List<DiffEntry> compute() throws IOException { return compute(NullProgressMonitor.INSTANCE); }
/** * Detect renames in the current file set. * * @param pm * report progress during the detection phases. * @return an unmodifiable list of {@link org.eclipse.jgit.diff.DiffEntry}s * representing all files that have been changed. * @throws java.io.IOException * file contents cannot be read from the repository. * @throws CancelledException * if rename detection was cancelled */ // TODO(ms): use org.eclipse.jgit.api.errors.CanceledException in next major // version public List<DiffEntry> compute(ProgressMonitor pm) throws IOException, CancelledException { if (!done) { try { return compute(objectReader, pm); } finally { objectReader.close(); } } return Collections.unmodifiableList(entries); }
private List<DiffEntry> detectRenames(List<DiffEntry> files) throws IOException { renameDetector.reset(); renameDetector.addAll(files); try { return renameDetector.compute(reader, progressMonitor); } catch (CancelledException e) { // TODO: consider propagating once bug 536323 is tackled // (making DiffEntry.scan() and DiffFormatter.scan() and // format() cancellable). return Collections.emptyList(); } }
/** * Detect renames in the current file set. * * @param reader * reader to obtain objects from the repository with. * @param pm * report progress during the detection phases. * @return an unmodifiable list of {@link org.eclipse.jgit.diff.DiffEntry}s * representing all files that have been changed. * @throws java.io.IOException * file contents cannot be read from the repository. * @throws CancelledException * if rename detection was cancelled */ // TODO(ms): use org.eclipse.jgit.api.errors.CanceledException in next major // version public List<DiffEntry> compute(ObjectReader reader, ProgressMonitor pm) throws IOException, CancelledException { final ContentSource cs = ContentSource.create(reader); return compute(new ContentSource.Pair(cs, cs), pm); }
private DiffEntry findRename(RevCommit parent, RevCommit commit, PathFilter path) throws IOException { if (renameDetector == null) return null; treeWalk.setFilter(TreeFilter.ANY_DIFF); treeWalk.reset(parent.getTree(), commit.getTree()); renameDetector.reset(); renameDetector.addAll(DiffEntry.scan(treeWalk)); for (DiffEntry ent : renameDetector.compute()) { if (isRename(ent) && ent.getNewPath().equals(path.getPath())) return ent; } return null; }
/** * Detect renames in the current file set. * <p> * This convenience function runs without a progress monitor. * * @return an unmodifiable list of {@link org.eclipse.jgit.diff.DiffEntry}s * representing all files that have been changed. * @throws java.io.IOException * file contents cannot be read from the repository. */ public List<DiffEntry> compute() throws IOException { return compute(NullProgressMonitor.INSTANCE); }
/** * Detect renames in the current file set. * <p> * This convenience function runs without a progress monitor. * * @return an unmodifiable list of {@link DiffEntry}s representing all files * that have been changed. * @throws IOException * file contents cannot be read from the repository. */ public List<DiffEntry> compute() throws IOException { return compute(NullProgressMonitor.INSTANCE); }
private void updateFollowFilter(ObjectId[] trees, DiffConfig cfg) throws MissingObjectException, IncorrectObjectTypeException, CorruptObjectException, IOException { TreeWalk tw = pathFilter; FollowFilter oldFilter = (FollowFilter) tw.getFilter(); tw.setFilter(TreeFilter.ANY_DIFF); tw.reset(trees); List<DiffEntry> files = DiffEntry.scan(tw); RenameDetector rd = new RenameDetector(tw.getObjectReader(), cfg); rd.addAll(files); files = rd.compute(); TreeFilter newFilter = oldFilter; for (DiffEntry ent : files) { if (isRename(ent) && ent.getNewPath().equals(oldFilter.getPath())) { newFilter = FollowFilter.create(ent.getOldPath(), cfg); RenameCallback callback = oldFilter.getRenameCallback(); if (callback != null) { callback.renamed(ent); // forward the callback to the new follow filter ((FollowFilter) newFilter).setRenameCallback(callback); } break; } } tw.setFilter(newFilter); }
/** * Detect renames in the current file set. * * @param pm * report progress during the detection phases. * @return an unmodifiable list of {@link DiffEntry}s representing all files * that have been changed. * @throws IOException * file contents cannot be read from the repository. */ public List<DiffEntry> compute(ProgressMonitor pm) throws IOException { if (!done) { try { return compute(objectReader, pm); } finally { objectReader.close(); } } return Collections.unmodifiableList(entries); }
/** * Detect renames in the current file set. * * @param pm * report progress during the detection phases. * @return an unmodifiable list of {@link org.eclipse.jgit.diff.DiffEntry}s * representing all files that have been changed. * @throws java.io.IOException * file contents cannot be read from the repository. * @throws CancelledException * if rename detection was cancelled */ // TODO(ms): use org.eclipse.jgit.api.errors.CanceledException in next major // version public List<DiffEntry> compute(ProgressMonitor pm) throws IOException, CancelledException { if (!done) { try { return compute(objectReader, pm); } finally { objectReader.close(); } } return Collections.unmodifiableList(entries); }
private List<DiffEntry> detectRenames(List<DiffEntry> files) throws IOException { renameDetector.reset(); renameDetector.addAll(files); try { return renameDetector.compute(reader, progressMonitor); } catch (CancelledException e) { // TODO: consider propagating once bug 536323 is tackled // (making DiffEntry.scan() and DiffFormatter.scan() and // format() cancellable). return Collections.emptyList(); } }
private List<DiffEntry> detectRenames(List<DiffEntry> files) throws IOException { renameDetector.reset(); renameDetector.addAll(files); return renameDetector.compute(reader, progressMonitor); }
/** * Detect renames in the current file set. * * @param reader * reader to obtain objects from the repository with. * @param pm * report progress during the detection phases. * @return an unmodifiable list of {@link DiffEntry}s representing all files * that have been changed. * @throws IOException * file contents cannot be read from the repository. */ public List<DiffEntry> compute(ObjectReader reader, ProgressMonitor pm) throws IOException { final ContentSource cs = ContentSource.create(reader); return compute(new ContentSource.Pair(cs, cs), pm); }
/** * Detect renames in the current file set. * * @param reader * reader to obtain objects from the repository with. * @param pm * report progress during the detection phases. * @return an unmodifiable list of {@link org.eclipse.jgit.diff.DiffEntry}s * representing all files that have been changed. * @throws java.io.IOException * file contents cannot be read from the repository. * @throws CancelledException * if rename detection was cancelled */ // TODO(ms): use org.eclipse.jgit.api.errors.CanceledException in next major // version public List<DiffEntry> compute(ObjectReader reader, ProgressMonitor pm) throws IOException, CancelledException { final ContentSource cs = ContentSource.create(reader); return compute(new ContentSource.Pair(cs, cs), pm); }
TreeWalk tw = new TreeWalk(repository); tw.setRecursive(true); tw.addTree(CommitUtils.getHead(repository).getTree()); tw.addTree(new FileTreeIterator(repository)); RenameDetector rd = new RenameDetector(repository); rd.addAll(DiffEntry.scan(tw)); List<DiffEntry> lde = rd.compute(tw.getObjectReader(), null); for (DiffEntry de : lde) { if (de.getScore() >= rd.getRenameScore()) { System.out.println("file: " + de.getOldPath() + " copied/moved to: " + de.getNewPath()); } }
private DiffEntry findRename(RevCommit parent, RevCommit commit, PathFilter path) throws IOException { if (renameDetector == null) return null; treeWalk.setFilter(TreeFilter.ANY_DIFF); treeWalk.reset(parent.getTree(), commit.getTree()); renameDetector.reset(); renameDetector.addAll(DiffEntry.scan(treeWalk)); for (DiffEntry ent : renameDetector.compute()) { if (isRename(ent) && ent.getNewPath().equals(path.getPath())) return ent; } return null; }
@NotNull private Map<String, String> collectRename(@NotNull GitFile oldTree, @NotNull GitFile newTree) throws IOException { if (!renameDetection) { return Collections.emptyMap(); } 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; }
private DiffEntry findRename(RevCommit parent, RevCommit commit, PathFilter path) throws IOException { if (renameDetector == null) return null; treeWalk.setFilter(TreeFilter.ANY_DIFF); treeWalk.reset(parent.getTree(), commit.getTree()); renameDetector.reset(); renameDetector.addAll(DiffEntry.scan(treeWalk)); for (DiffEntry ent : renameDetector.compute()) { if (isRename(ent) && ent.getNewPath().equals(path.getPath())) return ent; } return null; }
protected String getPreviousPath(Repository repository, ObjectReader reader, RevCommit headCommit, RevCommit previousCommit, String path) throws IOException { TreeWalk walk = new TreeWalk(reader); walk.setRecursive(true); walk.addTree(previousCommit.getTree()); walk.addTree(headCommit.getTree()); List<DiffEntry> entries = DiffEntry.scan(walk); if (entries.size() < 2) return path; for (DiffEntry diff : entries) if (diff.getChangeType() == ChangeType.MODIFY && path.equals(diff.getNewPath())) return path; RenameDetector detector = new RenameDetector(repository); detector.addAll(entries); List<DiffEntry> renames = detector.compute(walk.getObjectReader(), NullProgressMonitor.INSTANCE); for (DiffEntry diff : renames) if (diff.getChangeType() == ChangeType.RENAME && path.equals(diff.getNewPath())) return diff.getOldPath(); return path; }
private void updateFollowFilter(ObjectId[] trees, DiffConfig cfg) throws MissingObjectException, IncorrectObjectTypeException, CorruptObjectException, IOException { TreeWalk tw = pathFilter; FollowFilter oldFilter = (FollowFilter) tw.getFilter(); tw.setFilter(TreeFilter.ANY_DIFF); tw.reset(trees); List<DiffEntry> files = DiffEntry.scan(tw); RenameDetector rd = new RenameDetector(tw.getObjectReader(), cfg); rd.addAll(files); files = rd.compute(); TreeFilter newFilter = oldFilter; for (DiffEntry ent : files) { if (isRename(ent) && ent.getNewPath().equals(oldFilter.getPath())) { newFilter = FollowFilter.create(ent.getOldPath(), cfg); RenameCallback callback = oldFilter.getRenameCallback(); if (callback != null) { callback.renamed(ent); // forward the callback to the new follow filter ((FollowFilter) newFilter).setRenameCallback(callback); } break; } } tw.setFilter(newFilter); }