Search in sources :

Example 1 with FollowFilter

use of org.eclipse.jgit.revwalk.FollowFilter in project egit by eclipse.

the class GitHistoryPage method createFollowFilterFor.

/**
 * Creates a filter for the given files, will make sure that renames/copies
 * of all files will be followed.
 * @param paths the list of files to follow, must not be <code>null</code> or empty
 * @return the ORed list of {@link FollowFilter follow filters}
 */
private TreeFilter createFollowFilterFor(List<String> paths) {
    if (paths == null || paths.isEmpty())
        // $NON-NLS-1$
        throw new IllegalArgumentException("paths must not be null nor empty");
    DiffConfig diffConfig = currentRepo.getConfig().get(DiffConfig.KEY);
    List<TreeFilter> followFilters = new ArrayList<>(paths.size());
    for (String path : paths) followFilters.add(createFollowFilter(path, diffConfig));
    if (followFilters.size() == 1) {
        FollowFilter followFilter = (FollowFilter) followFilters.get(0);
        renameTracker.reset(followFilter.getPath());
        return followFilters.get(0);
    }
    // FollowFilter for rename detection.
    return OrTreeFilter.create(followFilters);
}
Also used : FollowFilter(org.eclipse.jgit.revwalk.FollowFilter) ArrayList(java.util.ArrayList) TreeFilter(org.eclipse.jgit.treewalk.filter.TreeFilter) AndTreeFilter(org.eclipse.jgit.treewalk.filter.AndTreeFilter) OrTreeFilter(org.eclipse.jgit.treewalk.filter.OrTreeFilter) DiffConfig(org.eclipse.jgit.diff.DiffConfig)

Example 2 with FollowFilter

use of org.eclipse.jgit.revwalk.FollowFilter in project egit by eclipse.

the class RepositoryActionHandler method getHeadCommit.

protected RevCommit getHeadCommit(IResource resource) throws IOException {
    Repository repository = getRepository();
    if (resource == null) {
        return null;
    }
    RepositoryMapping mapping = RepositoryMapping.getMapping(resource);
    if (mapping == null) {
        return null;
    }
    String path = mapping.getRepoRelativePath(resource);
    if (path == null) {
        return null;
    }
    try (RevWalk rw = new RevWalk(repository)) {
        rw.sort(RevSort.COMMIT_TIME_DESC, true);
        rw.sort(RevSort.BOUNDARY, true);
        if (path.length() > 0) {
            DiffConfig diffConfig = repository.getConfig().get(DiffConfig.KEY);
            FollowFilter filter = FollowFilter.create(path, diffConfig);
            rw.setTreeFilter(filter);
        }
        Ref head = repository.findRef(Constants.HEAD);
        if (head == null) {
            return null;
        }
        RevCommit headCommit = rw.parseCommit(head.getObjectId());
        rw.close();
        return headCommit;
    }
}
Also used : Repository(org.eclipse.jgit.lib.Repository) Ref(org.eclipse.jgit.lib.Ref) FollowFilter(org.eclipse.jgit.revwalk.FollowFilter) RepositoryMapping(org.eclipse.egit.core.project.RepositoryMapping) RevWalk(org.eclipse.jgit.revwalk.RevWalk) DiffConfig(org.eclipse.jgit.diff.DiffConfig) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 3 with FollowFilter

use of org.eclipse.jgit.revwalk.FollowFilter in project egit by eclipse.

the class GitHistoryPage method createFollowFilter.

private FollowFilter createFollowFilter(String path, DiffConfig diffConfig) {
    FollowFilter followFilter = FollowFilter.create(path, diffConfig);
    followFilter.setRenameCallback(new RenameCallback() {

        @Override
        public void renamed(DiffEntry entry) {
            renameTracker.getCallback().renamed(entry);
            if (fileViewerInterestingPaths != null) {
                fileViewerInterestingPaths.add(entry.getOldPath());
                fileViewerInterestingPaths.add(entry.getNewPath());
            }
        }
    });
    return followFilter;
}
Also used : FollowFilter(org.eclipse.jgit.revwalk.FollowFilter) RenameCallback(org.eclipse.jgit.revwalk.RenameCallback) DiffEntry(org.eclipse.jgit.diff.DiffEntry)

Aggregations

FollowFilter (org.eclipse.jgit.revwalk.FollowFilter)3 DiffConfig (org.eclipse.jgit.diff.DiffConfig)2 ArrayList (java.util.ArrayList)1 RepositoryMapping (org.eclipse.egit.core.project.RepositoryMapping)1 DiffEntry (org.eclipse.jgit.diff.DiffEntry)1 Ref (org.eclipse.jgit.lib.Ref)1 Repository (org.eclipse.jgit.lib.Repository)1 RenameCallback (org.eclipse.jgit.revwalk.RenameCallback)1 RevCommit (org.eclipse.jgit.revwalk.RevCommit)1 RevWalk (org.eclipse.jgit.revwalk.RevWalk)1 AndTreeFilter (org.eclipse.jgit.treewalk.filter.AndTreeFilter)1 OrTreeFilter (org.eclipse.jgit.treewalk.filter.OrTreeFilter)1 TreeFilter (org.eclipse.jgit.treewalk.filter.TreeFilter)1