List of usage examples for org.eclipse.jgit.revwalk.filter MaxCountRevFilter create
public static RevFilter create(int maxCount)
From source file:com.mycila.maven.plugin.license.git.GitLookup.java
License:Apache License
/** * Returns the year of the last change of the given {@code file} based on the history of the present git branch. The * year is taken either from the committer date or from the author identity depending on how {@link #dateSource} was * initialized./* w w w.j a v a2 s .c om*/ * <p> * See also the note on time zones in {@link #GitLookup(File, DateSource, TimeZone, int)}. * * @param file * @return * @throws NoHeadException * @throws GitAPIException * @throws IOException */ public int getYearOfLastChange(File file) throws NoHeadException, GitAPIException, IOException { String repoRelativePath = pathResolver.relativize(file); Status status = new Git(repository).status().addPath(repoRelativePath).call(); if (!status.isClean()) { /* Return the current year for modified and unstaged files */ return toYear(System.currentTimeMillis(), timeZone != null ? timeZone : DEFAULT_ZONE); } RevWalk walk = new RevWalk(repository); walk.markStart(walk.parseCommit(repository.resolve(Constants.HEAD))); walk.setTreeFilter(AndTreeFilter.create(PathFilter.create(repoRelativePath), TreeFilter.ANY_DIFF)); walk.setRevFilter(MaxCountRevFilter.create(checkCommitsCount)); walk.setRetainBody(false); int commitYear = 0; for (RevCommit commit : walk) { int y; switch (dateSource) { case COMMITER: int epochSeconds = commit.getCommitTime(); y = toYear(epochSeconds * 1000L, timeZone); break; case AUTHOR: PersonIdent id = commit.getAuthorIdent(); Date date = id.getWhen(); y = toYear(date.getTime(), id.getTimeZone()); break; default: throw new IllegalStateException("Unexpected " + DateSource.class.getName() + " " + dateSource); } if (y > commitYear) { commitYear = y; } } walk.dispose(); return commitYear; }
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.//from w w w .j a va 2 s.c om * * @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; }