List of usage examples for org.eclipse.jgit.treewalk.filter PathFilterGroup create
private static TreeFilter create(PathFilter[] p)
From source file:de.codesourcery.gittimelapse.GitHelper.java
License:Apache License
protected void visitCommits(File localPath, boolean retainCommitBody, ObjectId startCommit, ICommitVisitor func) throws RevisionSyntaxException, AmbiguousObjectException, IncorrectObjectTypeException, IOException { if (startCommit == null) { throw new RuntimeException("startCommit must not be NULL"); }/*from w w w. j ava 2 s . c o m*/ final RevWalk walk = new RevWalk(repository); try { final String path = stripRepoBaseDir(localPath); final PathFilter filter = createPathFilter(path); TreeFilter group = PathFilterGroup.create(Collections.singleton(filter)); walk.setTreeFilter(group); walk.setRevFilter(new RevFilter() { @Override public boolean include(RevWalk walker, RevCommit cmit) throws StopWalkException, MissingObjectException, IncorrectObjectTypeException, IOException { return commitChangesFile(path, filter, cmit); } @Override public RevFilter clone() { return this; } }); walk.setRetainBody(retainCommitBody); final RevCommit startingCommit = walk.parseCommit(startCommit); walk.markStart(startingCommit); visitCommits(walk, func); } finally { walk.dispose(); } }
From source file:org.eclipse.orion.server.git.jobs.LogCommand.java
License:Eclipse Distribution License
/** * Executes the {@code Log} command with all the options and parameters collected by the setter methods (e.g. {@link #add(AnyObjectId)}, * {@link #not(AnyObjectId)}, ..) of this class. Each instance of this class should only be used for one invocation of the command. Don't call this method * twice on an instance.//w w w . ja v a2s .c o m * * @return an iteration over RevCommits * @throws NoHeadException * of the references ref cannot be resolved */ @Override public Iterable<RevCommit> call() throws GitAPIException, NoHeadException { checkCallable(); ArrayList<RevFilter> filters = new ArrayList<RevFilter>(); if (pathFilters.size() > 0) walk.setTreeFilter(AndTreeFilter.create(PathFilterGroup.create(pathFilters), TreeFilter.ANY_DIFF)); if (msgFilter != null) filters.add(msgFilter); if (authorFilter != null) filters.add(authorFilter); if (committerFilter != null) filters.add(committerFilter); if (sha1Filter != null) filters.add(sha1Filter); if (dateFilter != null) filters.add(dateFilter); if (skip > -1) filters.add(SkipRevFilter.create(skip)); if (maxCount > -1) filters.add(MaxCountRevFilter.create(maxCount)); RevFilter filter = null; if (filters.size() > 1) { filter = AndRevFilter.create(filters); } else if (filters.size() == 1) { filter = filters.get(0); } if (filter != null) walk.setRevFilter(filter); if (!startSpecified) { try { ObjectId headId = repo.resolve(Constants.HEAD); if (headId == null) throw new NoHeadException(JGitText.get().noHEADExistsAndNoExplicitStartingRevisionWasSpecified); add(headId); } catch (IOException e) { // all exceptions thrown by add() shouldn't occur and represent // severe low-level exception which are therefore wrapped throw new JGitInternalException(JGitText.get().anExceptionOccurredWhileTryingToAddTheIdOfHEAD, e); } } setCallable(false); return walk; }
From source file:org.gitective.core.PathFilterUtils.java
License:Open Source License
private static TreeFilter group(final String... paths) { final int length = paths.length; final List<PathFilter> filters = new ArrayList<PathFilter>(length); for (int i = 0; i < length; i++) filters.add(PathFilter.create(paths[i])); return PathFilterGroup.create(filters); }
From source file:org.nbgit.util.GitCommand.java
License:Open Source License
public static RepositoryRevision.Walk getLogMessages(String rootPath, Set<File> files, String fromRevision, String toRevision, boolean showMerges, OutputLogger logger) { File root = new File(rootPath); Repository repo = Git.getInstance().getRepository(root); RepositoryRevision.Walk walk = new RepositoryRevision.Walk(repo); try {/*from ww w. jav a 2 s . c o m*/ if (fromRevision == null) { fromRevision = Constants.HEAD; } ObjectId from = repo.resolve(fromRevision); if (from == null) { return null; } walk.markStart(walk.parseCommit(from)); ObjectId to = toRevision != null ? repo.resolve(toRevision) : null; if (to != null) { walk.markUninteresting(walk.parseCommit(to)); } List<PathFilter> paths = new ArrayList<PathFilter>(); for (File file : files) { String path = getRelative(root, file); if (!(path.length() == 0)) { paths.add(PathFilter.create(path)); } } if (!paths.isEmpty()) { walk.setTreeFilter(PathFilterGroup.create(paths)); } if (!showMerges) { walk.setRevFilter(RevFilter.NO_MERGES); } } catch (IOException ioe) { return null; } return walk; }
From source file:org.nbgit.util.GitCommand.java
License:Open Source License
public static List<String[]> getRevisionsForFile(File root, File[] files, int limit) { Repository repo = Git.getInstance().getRepository(root); RevWalk walk = new RevWalk(repo); List<String[]> revs = new ArrayList<String[]>(); try {//w w w. ja v a 2 s .c om ObjectId from = repo.resolve(Constants.HEAD); if (from == null) { return null; } walk.markStart(walk.parseCommit(from)); if (files != null) { List<PathFilter> paths = new ArrayList<PathFilter>(); for (File file : files) { String path = getRelative(root, file); if (!(path.length() == 0)) { paths.add(PathFilter.create(path)); } } if (!paths.isEmpty()) { walk.setTreeFilter(PathFilterGroup.create(paths)); } } for (RevCommit rev : walk) { revs.add(new String[] { rev.getShortMessage(), rev.getId().name() }); if (--limit <= 0) { break; } } } catch (IOException ioe) { } return revs; }