本文整理汇总了Java中org.eclipse.jgit.treewalk.filter.TreeFilter类的典型用法代码示例。如果您正苦于以下问题:Java TreeFilter类的具体用法?Java TreeFilter怎么用?Java TreeFilter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TreeFilter类属于org.eclipse.jgit.treewalk.filter包,在下文中一共展示了TreeFilter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: hasMatchingChanges
import org.eclipse.jgit.treewalk.filter.TreeFilter; //导入依赖的package包/类
private boolean hasMatchingChanges(Revision from, Revision to, PathPatternFilter filter) {
try (RevWalk revWalk = new RevWalk(jGitRepository)) {
final List<DiffEntry> diff =
compareTrees(toTreeId(revWalk, from), toTreeId(revWalk, to), TreeFilter.ALL);
for (DiffEntry e : diff) {
final String path;
switch (e.getChangeType()) {
case ADD:
path = e.getNewPath();
break;
case MODIFY:
case DELETE:
path = e.getOldPath();
break;
default:
throw new Error();
}
if (filter.matches(path)) {
return true;
}
}
}
return false;
}
示例2: notifyWatchers
import org.eclipse.jgit.treewalk.filter.TreeFilter; //导入依赖的package包/类
private void notifyWatchers(Revision newRevision, ObjectId prevTreeId, ObjectId nextTreeId) {
final List<DiffEntry> diff = compareTrees(prevTreeId, nextTreeId, TreeFilter.ALL);
for (DiffEntry e: diff) {
switch (e.getChangeType()) {
case ADD:
commitWatchers.notify(newRevision, e.getNewPath());
break;
case MODIFY:
case DELETE:
commitWatchers.notify(newRevision, e.getOldPath());
break;
default:
throw new Error();
}
}
}
示例3: getChangedFiles
import org.eclipse.jgit.treewalk.filter.TreeFilter; //导入依赖的package包/类
private Set<String> getChangedFiles(Project project, ObjectId oldObjectId, ObjectId newObjectId) {
Set<String> changedFiles = new HashSet<>();
try (TreeWalk treeWalk = new TreeWalk(project.getRepository())) {
treeWalk.setFilter(TreeFilter.ANY_DIFF);
treeWalk.setRecursive(true);
RevCommit oldCommit = project.getRevCommit(oldObjectId);
RevCommit newCommit = project.getRevCommit(newObjectId);
treeWalk.addTree(oldCommit.getTree());
treeWalk.addTree(newCommit.getTree());
while (treeWalk.next()) {
changedFiles.add(treeWalk.getPathString());
}
} catch (IOException e) {
throw new RuntimeException(e);
}
return changedFiles;
}
示例4: filterOutOtherModulesChanges
import org.eclipse.jgit.treewalk.filter.TreeFilter; //导入依赖的package包/类
private void filterOutOtherModulesChanges(final String modulePath, final List<String> childModules,
final RevWalk walk) {
final boolean isRootModule = ".".equals(modulePath);
final boolean isMultiModuleProject = !isRootModule || !childModules.isEmpty();
final List<TreeFilter> treeFilters = new LinkedList<>();
treeFilters.add(TreeFilter.ANY_DIFF);
if (isMultiModuleProject) {
if (!isRootModule) {
// for sub-modules, look for changes only in the sub-module
// path...
treeFilters.add(PathFilter.create(modulePath));
}
// ... but ignore any sub-modules of the current sub-module, because
// they can change independently of the current module
for (final String childModule : childModules) {
final String path = isRootModule ? childModule : modulePath + "/" + childModule;
treeFilters.add(PathFilter.create(path).negate());
}
}
final TreeFilter treeFilter = treeFilters.size() == 1 ? treeFilters.get(0) : AndTreeFilter.create(treeFilters);
walk.setTreeFilter(treeFilter);
}
示例5: filterOutOtherModulesChanges
import org.eclipse.jgit.treewalk.filter.TreeFilter; //导入依赖的package包/类
private void filterOutOtherModulesChanges(String modulePath, List<String> childModules, RevWalk walk) {
boolean isRootModule = ".".equals(modulePath);
boolean isMultiModuleProject = !isRootModule || !childModules.isEmpty();
List<TreeFilter> treeFilters = new ArrayList<TreeFilter>();
treeFilters.add(TreeFilter.ANY_DIFF);
if (isMultiModuleProject) {
if (!isRootModule) {
// for sub-modules, look for changes only in the sub-module path...
treeFilters.add(PathFilter.create(modulePath));
}
// ... but ignore any sub-modules of the current sub-module, because they can change independently of the current module
for (String childModule : childModules) {
String path = isRootModule ? childModule : modulePath + "/" + childModule;
treeFilters.add(PathFilter.create(path).negate());
}
}
TreeFilter treeFilter = treeFilters.size() == 1 ? treeFilters.get(0) : AndTreeFilter.create(treeFilters);
walk.setTreeFilter(treeFilter);
}
示例6: getRevisaoMaisRecenteDoBranch
import org.eclipse.jgit.treewalk.filter.TreeFilter; //导入依赖的package包/类
public Optional<Revisao> getRevisaoMaisRecenteDoBranch(String branchRef, Path caminhoRelativo) {
RevCommit commit = comRepositorioAberto(uncheckedFunction(git -> {
Repository repo = git.getRepository();
RevWalk revWalk = new RevWalk(repo);
revWalk.setTreeFilter(AndTreeFilter.create(PathFilter.create(caminhoRelativo.toString()), TreeFilter.ANY_DIFF));
revWalk.markStart(revWalk.lookupCommit(repo.resolve(branchRef)));
Iterator<RevCommit> revs = revWalk.iterator();
if (revs.hasNext()) {
return revs.next();
}
return null;
}));
if (commit == null) {
return empty();
}
return of(new Revisao(commit));
}
示例7: listFiles
import org.eclipse.jgit.treewalk.filter.TreeFilter; //导入依赖的package包/类
private void listFiles() throws GitException {
RevWalk revWalk = new RevWalk(repository);
TreeWalk walk = new TreeWalk(repository);
try {
List<GitFileInfo> result;
walk.reset();
walk.setRecursive(true);
RevCommit parentCommit = null;
if (revCommit.getParentCount() > 0) {
for (RevCommit commit : revCommit.getParents()) {
revWalk.markStart(revWalk.lookupCommit(commit));
}
revWalk.setRevFilter(RevFilter.MERGE_BASE);
Iterator<RevCommit> it = revWalk.iterator();
if (it.hasNext()) {
parentCommit = it.next();
}
if (parentCommit != null) {
walk.addTree(parentCommit.getTree().getId());
}
}
walk.addTree(revCommit.getTree().getId());
walk.setFilter(AndTreeFilter.create(TreeFilter.ANY_DIFF, PathFilter.ANY_DIFF));
if (parentCommit != null) {
result = Utils.getDiffEntries(repository, walk, GitClassFactoryImpl.getInstance());
} else {
result = new ArrayList<GitFileInfo>();
while (walk.next()) {
result.add(new GitFileInfo(new File(repository.getWorkTree(), walk.getPathString()), walk.getPathString(), GitFileInfo.Status.ADDED, null, null));
}
}
this.modifiedFiles = result.toArray(new GitFileInfo[result.size()]);
} catch (IOException ex) {
throw new GitException(ex);
} finally {
revWalk.release();
walk.release();
}
}
示例8: detectRenames
import org.eclipse.jgit.treewalk.filter.TreeFilter; //导入依赖的package包/类
private Map<String, DiffEntry> detectRenames (Repository repository, DirCache cache, ObjectId commitId) {
List<DiffEntry> entries;
TreeWalk treeWalk = new TreeWalk(repository);
try {
treeWalk.setRecursive(true);
treeWalk.reset();
if (commitId != null) {
treeWalk.addTree(new RevWalk(repository).parseTree(commitId));
} else {
treeWalk.addTree(new EmptyTreeIterator());
}
// Index
treeWalk.addTree(new DirCacheIterator(cache));
treeWalk.setFilter(TreeFilter.ANY_DIFF);
entries = DiffEntry.scan(treeWalk);
RenameDetector d = new RenameDetector(repository);
d.addAll(entries);
entries = d.compute();
} catch (IOException ex) {
entries = Collections.<DiffEntry>emptyList();
} finally {
treeWalk.release();
}
Map<String, DiffEntry> renames = new HashMap<String, DiffEntry>();
for (DiffEntry e : entries) {
if (e.getChangeType().equals(DiffEntry.ChangeType.COPY) || e.getChangeType().equals(DiffEntry.ChangeType.RENAME)) {
renames.put(e.getNewPath(), e);
}
}
return renames;
}
示例9: getSubtreeFilters
import org.eclipse.jgit.treewalk.filter.TreeFilter; //导入依赖的package包/类
private static Collection<TreeFilter> getSubtreeFilters(Collection<PathFilter> filters, String path) {
List<TreeFilter> subtreeFilters = new LinkedList<TreeFilter>();
for (PathFilter filter : filters) {
if (filter.getPath().startsWith(path + "/")) { //NOI18N
subtreeFilters.add(filter);
}
}
return subtreeFilters;
}
示例10: run
import org.eclipse.jgit.treewalk.filter.TreeFilter; //导入依赖的package包/类
@Override
protected void run () throws GitException {
Repository repository = getRepository();
TreeWalk walk = new TreeWalk(repository);
try {
walk.reset();
walk.setRecursive(true);
walk.addTree(Utils.findCommit(repository, revisionFirst).getTree());
walk.addTree(Utils.findCommit(repository, revisionSecond).getTree());
Collection<PathFilter> pathFilters = Utils.getPathFilters(repository.getWorkTree(), roots);
if (pathFilters.isEmpty()) {
walk.setFilter(AndTreeFilter.create(TreeFilter.ANY_DIFF, PathFilter.ANY_DIFF));
} else {
walk.setFilter(AndTreeFilter.create(new TreeFilter[] {
TreeFilter.ANY_DIFF,
PathFilter.ANY_DIFF,
PathFilterGroup.create(pathFilters)
}));
}
List<GitRevisionInfo.GitFileInfo> infos = Utils.getDiffEntries(repository, walk, getClassFactory());
for (GitRevisionInfo.GitFileInfo info : infos) {
statuses.put(info.getFile(), info);
}
} catch (IOException ex) {
throw new GitException(ex);
} finally {
walk.release();
}
}
示例11: applyCriteria
import org.eclipse.jgit.treewalk.filter.TreeFilter; //导入依赖的package包/类
private void applyCriteria (RevWalk walk, SearchCriteria criteria,
final RevFlag partOfResultFlag, DiffConfig diffConfig) {
File[] files = criteria.getFiles();
if (files.length > 0) {
Collection<PathFilter> pathFilters = Utils.getPathFilters(getRepository().getWorkTree(), files);
if (!pathFilters.isEmpty()) {
if (criteria.isFollow() && pathFilters.size() == 1) {
walk.setTreeFilter(FollowFilter.create(pathFilters.iterator().next().getPath(), diffConfig));
} else {
walk.setTreeFilter(AndTreeFilter.create(TreeFilter.ANY_DIFF, PathFilterGroup.create(pathFilters)));
}
}
}
RevFilter filter;
if (criteria.isIncludeMerges()) {
filter = RevFilter.ALL;
} else {
filter = RevFilter.NO_MERGES;
}
filter = AndRevFilter.create(filter, new CancelRevFilter(monitor));
filter = AndRevFilter.create(filter, new RevFilter() {
@Override
public boolean include (RevWalk walker, RevCommit cmit) {
return cmit.has(partOfResultFlag);
}
@Override
public RevFilter clone () {
return this;
}
@Override
public boolean requiresCommitBody () {
return false;
}
});
String username = criteria.getUsername();
if (username != null && !(username = username.trim()).isEmpty()) {
filter = AndRevFilter.create(filter, OrRevFilter.create(CommitterRevFilter.create(username), AuthorRevFilter.create(username)));
}
String message = criteria.getMessage();
if (message != null && !(message = message.trim()).isEmpty()) {
filter = AndRevFilter.create(filter, MessageRevFilter.create(message));
}
Date from = criteria.getFrom();
Date to = criteria.getTo();
if (from != null && to != null) {
filter = AndRevFilter.create(filter, CommitTimeRevFilter.between(from, to));
} else if (from != null) {
filter = AndRevFilter.create(filter, CommitTimeRevFilter.after(from));
} else if (to != null) {
filter = AndRevFilter.create(filter, CommitTimeRevFilter.before(to));
}
// this must be at the end, limit filter must apply as the last
if (criteria.getLimit() != -1) {
filter = AndRevFilter.create(filter, MaxCountRevFilter.create(criteria.getLimit()));
}
walk.setRevFilter(filter);
}
示例12: getExcludeExactPathsFilter
import org.eclipse.jgit.treewalk.filter.TreeFilter; //导入依赖的package包/类
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;
}
示例13: compareTrees
import org.eclipse.jgit.treewalk.filter.TreeFilter; //导入依赖的package包/类
/**
* Compares the old tree and the new tree to get the list of the affected files.
*/
private List<DiffEntry> compareTrees(ObjectId prevTreeId, ObjectId nextTreeId, TreeFilter filter) {
try (DiffFormatter diffFormatter = new DiffFormatter(NullOutputStream.INSTANCE)) {
diffFormatter.setRepository(jGitRepository);
diffFormatter.setPathFilter(filter);
return diffFormatter.scan(prevTreeId, nextTreeId);
} catch (IOException e) {
throw new StorageException("failed to compare two trees: " + prevTreeId + " vs. " + nextTreeId, e);
}
}
示例14: updateFollowFilter
import org.eclipse.jgit.treewalk.filter.TreeFilter; //导入依赖的package包/类
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);
}
示例15: RevWalk
import org.eclipse.jgit.treewalk.filter.TreeFilter; //导入依赖的package包/类
private RevWalk(ObjectReader or, boolean closeReader) {
reader = or;
idBuffer = new MutableObjectId();
objects = new ObjectIdOwnerMap<>();
roots = new ArrayList<>();
queue = new DateRevQueue();
pending = new StartGenerator(this);
sorting = EnumSet.of(RevSort.NONE);
filter = RevFilter.ALL;
treeFilter = TreeFilter.ALL;
this.closeReader = closeReader;
}