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); }
/** {@inheritDoc} */ @Override public TreeFilter clone() { return new FollowFilter(path.clone(), cfg); }
private List<DiffEntry> updateFollowFilter(List<DiffEntry> files) { String oldPath = ((FollowFilter) pathFilter).getPath(); for (DiffEntry ent : files) { if (isRename(ent) && ent.getNewPath().equals(oldPath)) { pathFilter = FollowFilter.create(ent.getOldPath(), diffCfg); return Collections.singletonList(ent); } } return Collections.emptyList(); }
private FollowFilter createFollowFilter(String path, DiffConfig diffConfig) { FollowFilter followFilter = FollowFilter.create(path, diffConfig); followFilter.setRenameCallback(new RenameCallback() { @Override public void renamed(DiffEntry entry) { if (fileViewerInterestingPaths != null) { fileViewerInterestingPaths.add(entry.getOldPath()); fileViewerInterestingPaths.add(entry.getNewPath()); } } }); return followFilter; }
private static @NonNull DiffEntry diffFile(Repository repo, String oldCommit, String newCommit, String path) throws IOException, GitAPIException { Config config = new Config(); config.setBoolean("diff", null, "renames", true); DiffConfig diffConfig = config.get(DiffConfig.KEY); try (Git git = new Git(repo)) { List<DiffEntry> diffList = git.diff(). setOldTree(prepareTreeParser(repo, oldCommit)). setNewTree(prepareTreeParser(repo, newCommit)). setPathFilter(FollowFilter.create(path, diffConfig)). call(); if (diffList.size() == 0) return null; if (diffList.size() > 1) throw new RuntimeException("invalid diff"); return diffList.get(0); } } }
private boolean isAdd(List<DiffEntry> files) { String oldPath = ((FollowFilter) pathFilter).getPath(); for (DiffEntry ent : files) { if (ent.getChangeType() == ADD && ent.getNewPath().equals(oldPath)) return true; } return false; }
private List<DiffEntry> updateFollowFilter(List<DiffEntry> files) { String oldPath = ((FollowFilter) pathFilter).getPath(); for (DiffEntry ent : files) { if (isRename(ent) && ent.getNewPath().equals(oldPath)) { pathFilter = FollowFilter.create(ent.getOldPath(), diffCfg); return Collections.singletonList(ent); } } return Collections.emptyList(); }
private TreeRevFilter createTreeRevFilter(final RevWalk rw, String curPath, final RenameCallback renameCallback) { final FollowFilter followFilter = FollowFilter.create(curPath, git.getRepository().getConfig().get(DiffConfig.KEY)); followFilter.setRenameCallback(renameCallback); final TreeRevFilter revFilter = new TreeRevFilter(rw, followFilter); return revFilter; }
private static @NonNull DiffEntry diffFile(Repository repo, String oldCommit, String newCommit, String path) throws IOException, GitAPIException { Config config = new Config(); config.setBoolean("diff", null, "renames", true); DiffConfig diffConfig = config.get(DiffConfig.KEY); try (Git git = new Git(repo)) { List<DiffEntry> diffList = git.diff(). setOldTree(prepareTreeParser(repo, oldCommit)). setNewTree(prepareTreeParser(repo, newCommit)). setPathFilter(FollowFilter.create(path, diffConfig)). call(); if (diffList.size() == 0) return null; if (diffList.size() > 1) throw new RuntimeException("invalid diff"); return diffList.get(0); } } }
private boolean isAdd(List<DiffEntry> files) { String oldPath = ((FollowFilter) pathFilter).getPath(); for (DiffEntry ent : files) { if (ent.getChangeType() == ADD && ent.getNewPath().equals(oldPath)) return true; } return false; }
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); }
private List<DiffEntry> updateFollowFilter(List<DiffEntry> files) { String oldPath = ((FollowFilter) pathFilter).getPath(); for (DiffEntry ent : files) { if (isRename(ent) && ent.getNewPath().equals(oldPath)) { pathFilter = FollowFilter.create(ent.getOldPath(), diffCfg); return Collections.singletonList(ent); } } return Collections.emptyList(); }
private TreeFilter createTreeFilter() { if (filterResources == null) return TreeFilter.ALL; List<TreeFilter> filters = new ArrayList<TreeFilter>(); for (IResource resource : filterResources) { RepositoryMapping mapping = RepositoryMapping.getMapping(resource); if (mapping != null) { DiffConfig diffConfig = mapping.getRepository().getConfig().get(DiffConfig.KEY); String path = mapping.getRepoRelativePath(resource); if (path != null && !"".equals(path)) { //$NON-NLS-1$ if (resource.getType() == IResource.FILE) filters.add(FollowFilter.create(path, diffConfig)); else filters.add(AndTreeFilter.create( PathFilter.create(path), TreeFilter.ANY_DIFF)); } } } if (filters.isEmpty()) return TreeFilter.ALL; else if (filters.size() == 1) return filters.get(0); else return OrTreeFilter.create(filters); } }
/** * Create a new tree filter for a user supplied path. * <p> * Path strings are relative to the root of the repository. If the user's * input should be assumed relative to a subdirectory of the repository the * caller must prepend the subdirectory's path prior to creating the filter. * <p> * Path strings use '/' to delimit directories on all platforms. * * @param path * the path to filter on. Must not be the empty string. All * trailing '/' characters will be trimmed before string's length * is checked or is used as part of the constructed filter. * @param cfg * diff config specifying rename detection options. * @return a new filter for the requested path. * @throws java.lang.IllegalArgumentException * the path supplied was the empty string. * @since 3.0 */ public static FollowFilter create(String path, DiffConfig cfg) { return new FollowFilter(PathFilter.create(path), cfg); }
private boolean isAdd(List<DiffEntry> files) { String oldPath = ((FollowFilter) pathFilter).getPath(); for (DiffEntry ent : files) { if (ent.getChangeType() == ADD && ent.getNewPath().equals(oldPath)) return true; } return false; }
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); }
DiffConfig diffConfig = repository.getConfig().get( DiffConfig.KEY); FollowFilter filter = FollowFilter.create(path, diffConfig); rw.setTreeFilter(filter);
/** {@inheritDoc} */ @Override public TreeFilter clone() { return new FollowFilter(path.clone(), cfg); }
if (pathFilter instanceof FollowFilter) { walk.setFilter(AndTreeFilter.create( PathFilter.create(((FollowFilter) pathFilter).getPath()), filter)); } else {
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); }