Java源码示例:org.eclipse.jgit.treewalk.filter.OrTreeFilter
示例1
private Map<String, BlobWrapper> getRevFileContentMap(
Git git, RevCommit commit, Set<String> filePathSet, ObjectReader reader) throws Exception {
if (filePathSet == null || filePathSet.isEmpty()) {
return Collections.emptyMap();
}
TreeFilter filter = filePathSet.size() > 1
? OrTreeFilter.create(filePathSet.stream()
.map(PathFilter::create)
.collect(Collectors.toList()))
: PathFilter.create(filePathSet.iterator().next());
return getContentMapByTreeAndFilter(git, new CanonicalTreeParser(null, reader, commit.getTree()), filter);
}
示例2
private Map<String, BlobWrapper> getIndexedFileContentMap(Git git, Set<String> filePathSet) throws Exception {
if (filePathSet == null || filePathSet.isEmpty()) {
return Collections.emptyMap();
}
DirCache index = git.getRepository().readDirCache();
TreeFilter filter = filePathSet.size() > 1
? OrTreeFilter.create(filePathSet.stream()
.map(PathFilter::create)
.collect(Collectors.toList()))
: PathFilter.create(filePathSet.iterator().next());
return getContentMapByTreeAndFilter(git, new DirCacheIterator(index), filter);
}
示例3
public static TreeFilter getExcludeExactPathsFilter (File workDir, File[] roots) {
Collection<String> relativePaths = getRelativePaths(workDir, roots);
TreeFilter filter = null;
if (relativePaths.size() > 0) {
Collection<PathFilter> filters = getPathFilters(relativePaths);
List<TreeFilter> exactPathFilters = new LinkedList<TreeFilter>();
for (PathFilter f : filters) {
exactPathFilters.add(ExactPathFilter.create(f));
}
return NotTreeFilter.create(exactPathFilters.size() == 1 ? exactPathFilters.get(0) : OrTreeFilter.create(exactPathFilters));
}
return filter;
}