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);
}
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;
}
}
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;
}
Aggregations