本文整理汇总了Java中org.eclipse.jgit.treewalk.filter.AndTreeFilter类的典型用法代码示例。如果您正苦于以下问题:Java AndTreeFilter类的具体用法?Java AndTreeFilter怎么用?Java AndTreeFilter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AndTreeFilter类属于org.eclipse.jgit.treewalk.filter包,在下文中一共展示了AndTreeFilter类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: filterOutOtherModulesChanges
import org.eclipse.jgit.treewalk.filter.AndTreeFilter; //导入依赖的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);
}
示例2: filterOutOtherModulesChanges
import org.eclipse.jgit.treewalk.filter.AndTreeFilter; //导入依赖的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);
}
示例3: getRevisaoMaisRecenteDoBranch
import org.eclipse.jgit.treewalk.filter.AndTreeFilter; //导入依赖的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));
}
示例4: listFiles
import org.eclipse.jgit.treewalk.filter.AndTreeFilter; //导入依赖的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();
}
}
示例5: run
import org.eclipse.jgit.treewalk.filter.AndTreeFilter; //导入依赖的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();
}
}
示例6: applyCriteria
import org.eclipse.jgit.treewalk.filter.AndTreeFilter; //导入依赖的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);
}
示例7: getFileRevisions
import org.eclipse.jgit.treewalk.filter.AndTreeFilter; //导入依赖的package包/类
@Nonnull
public static List<RevCommit> getFileRevisions(String path, AnyObjectId start, int skip, int limit, ObjectReader reader) throws IOException {
path = normalizeNodePath(path);
TreeFilter filter = AndTreeFilter.create(PathFilterGroup.createFromStrings(path), ANY_DIFF);
return getHistory(start, skip, limit, filter, reader);
}
示例8: getCommitDiffFiles
import org.eclipse.jgit.treewalk.filter.AndTreeFilter; //导入依赖的package包/类
private List<DiffCommitFile> getCommitDiffFiles(RevCommit revCommit, String pattern)
throws IOException {
List<DiffEntry> diffs;
TreeFilter filter = null;
if (!isNullOrEmpty(pattern)) {
filter =
AndTreeFilter.create(
PathFilterGroup.createFromStrings(Collections.singleton(pattern)),
TreeFilter.ANY_DIFF);
}
List<DiffCommitFile> commitFilesList = new ArrayList<>();
try (TreeWalk tw = new TreeWalk(repository)) {
tw.setRecursive(true);
// get the current commit parent in order to compare it with the current commit
// and to get the list of DiffEntry.
if (revCommit.getParentCount() > 0) {
RevCommit parent = parseCommit(revCommit.getParent(0));
tw.reset(parent.getTree(), revCommit.getTree());
if (filter != null) {
tw.setFilter(filter);
} else {
tw.setFilter(TreeFilter.ANY_DIFF);
}
diffs = DiffEntry.scan(tw);
} else {
// If the current commit has no parents (which means it is the initial commit),
// then create an empty tree and compare it to the current commit to get the
// list of DiffEntry.
try (RevWalk rw = new RevWalk(repository);
DiffFormatter diffFormat = new DiffFormatter(NullOutputStream.INSTANCE)) {
diffFormat.setRepository(repository);
if (filter != null) {
diffFormat.setPathFilter(filter);
}
diffs =
diffFormat.scan(
new EmptyTreeIterator(),
new CanonicalTreeParser(null, rw.getObjectReader(), revCommit.getTree()));
}
}
}
if (diffs != null) {
commitFilesList.addAll(
diffs
.stream()
.map(
diff ->
newDto(DiffCommitFile.class)
.withOldPath(diff.getOldPath())
.withNewPath(diff.getNewPath())
.withChangeType(diff.getChangeType().name()))
.collect(toList()));
}
return commitFilesList;
}
示例9: writeTo
import org.eclipse.jgit.treewalk.filter.AndTreeFilter; //导入依赖的package包/类
@Override
public final void writeTo(OutputStream out) throws IOException {
DiffFormatter formatter = new DiffFormatter(new BufferedOutputStream(out));
formatter.setRepository(repository);
List<String> rawFileFilter = params.getFileFilter();
TreeFilter pathFilter =
(rawFileFilter != null && rawFileFilter.size() > 0)
? PathFilterGroup.createFromStrings(rawFileFilter)
: TreeFilter.ALL;
formatter.setPathFilter(AndTreeFilter.create(TreeFilter.ANY_DIFF, pathFilter));
try {
String commitA = params.getCommitA();
String commitB = params.getCommitB();
boolean cached = params.isCached();
List<DiffEntry> diff;
if (commitA == null && commitB == null && !cached) {
diff = indexToWorkingTree(formatter);
} else if (commitA != null && commitB == null && !cached) {
diff = commitToWorkingTree(commitA, formatter);
} else if (commitA == null && commitB != null) {
diff = emptyToCommit(commitB, formatter);
} else if (commitB == null) {
diff = commitToIndex(commitA, formatter);
} else {
diff = commitToCommit(commitA, commitB, formatter);
}
DiffType type = params.getType();
if (type == DiffType.NAME_ONLY) {
writeNames(diff, out);
} else if (type == DiffType.NAME_STATUS) {
writeNamesAndStatus(diff, out);
} else {
writeRawDiff(diff, formatter);
}
} catch (GitException e) {
LOG.error(e.getMessage());
} finally {
formatter.close();
repository.close();
}
}
示例10: determineVersions
import org.eclipse.jgit.treewalk.filter.AndTreeFilter; //导入依赖的package包/类
@Override
public TestVersionResult determineVersions(final String fetchRevision) throws StoreException.ReadException {
try {
final RevWalk walk = new RevWalk(git.getRepository());
final ObjectId commitId = ObjectId.fromString(fetchRevision);
final RevCommit headTree = walk.parseCommit(commitId);
final RevTree tree = headTree.getTree();
// now use a TreeWalk to iterate over all files in the Tree recursively
// you can set Filters to narrow down the results if needed
TreeWalk treeWalk = new TreeWalk(git.getRepository());
treeWalk.addTree(tree);
treeWalk.setFilter(AndTreeFilter
.create(PathFilter.create(testDefinitionsDirectory), PathSuffixFilter.create("definition.json")));
treeWalk.setRecursive(true);
final List<TestVersionResult.Test> tests = Lists.newArrayList();
while (treeWalk.next()) {
final ObjectId id = treeWalk.getObjectId(0);
// final RevTree revTree = walk.lookupTree(id);
final String path = treeWalk.getPathString();
final String[] pieces = path.split("/");
final String testname = pieces[pieces.length - 2]; // tree / parent directory name
// testname, blobid pair
// note this is the blobid hash - not a commit hash
// RevTree.id and RevBlob.id
tests.add(new TestVersionResult.Test(testname, id.name()));
}
walk.dispose();
return new TestVersionResult(
tests,
new Date(Long.valueOf(headTree.getCommitTime()) * 1000 /* convert seconds to milliseconds */),
headTree.getAuthorIdent().toExternalString(),
headTree.toObjectId().getName(),
headTree.getFullMessage()
);
} catch (IOException e) {
throw new StoreException.ReadException(e);
}
}