List of usage examples for org.eclipse.jgit.revwalk.filter CommitTimeRevFilter after
public static final RevFilter after(long ts)
From source file:com.gitblit.utils.JGitUtils.java
License:Apache License
/** * Returns a list of commits since the minimum date starting from the * specified object id.//from w w w. j a va 2s . c o m * * @param repository * @param objectId * if unspecified, HEAD is assumed. * @param minimumDate * @return list of commits */ public static List<RevCommit> getRevLog(Repository repository, String objectId, Date minimumDate) { List<RevCommit> list = new ArrayList<RevCommit>(); if (!hasCommits(repository)) { return list; } try { // resolve branch ObjectId branchObject; if (StringUtils.isEmpty(objectId)) { branchObject = getDefaultBranch(repository); } else { branchObject = repository.resolve(objectId); } RevWalk rw = new RevWalk(repository); rw.markStart(rw.parseCommit(branchObject)); rw.setRevFilter(CommitTimeRevFilter.after(minimumDate)); Iterable<RevCommit> revlog = rw; for (RevCommit rev : revlog) { list.add(rev); } rw.dispose(); } catch (Throwable t) { error(t, repository, "{0} failed to get {1} revlog for minimum date {2}", objectId, minimumDate); } return list; }
From source file:org.apache.maven.scm.provider.git.jgit.command.JGitUtils.java
License:Apache License
/** * Get a list of commits between two revisions. * * @param repo the repository to work on * @param sortings sorting/* ww w. j ava 2s. c o m*/ * @param fromRev start revision * @param toRev if null, falls back to head * @param fromDate from which date on * @param toDate until which date * @param maxLines max number of lines * @return a list of commits, might be empty, but never <code>null</code> * @throws IOException * @throws MissingObjectException * @throws IncorrectObjectTypeException */ public static List<RevCommit> getRevCommits(Repository repo, RevSort[] sortings, String fromRev, String toRev, final Date fromDate, final Date toDate, int maxLines) throws IOException, MissingObjectException, IncorrectObjectTypeException { List<RevCommit> revs = new ArrayList<RevCommit>(); RevWalk walk = new RevWalk(repo); ObjectId fromRevId = fromRev != null ? repo.resolve(fromRev) : null; ObjectId toRevId = toRev != null ? repo.resolve(toRev) : null; if (sortings == null || sortings.length == 0) { sortings = new RevSort[] { RevSort.TOPO, RevSort.COMMIT_TIME_DESC }; } for (final RevSort s : sortings) { walk.sort(s, true); } if (fromDate != null && toDate != null) { //walk.setRevFilter( CommitTimeRevFilter.between( fromDate, toDate ) ); walk.setRevFilter(new RevFilter() { @Override public boolean include(RevWalk walker, RevCommit cmit) throws StopWalkException, MissingObjectException, IncorrectObjectTypeException, IOException { int cmtTime = cmit.getCommitTime(); return (cmtTime >= (fromDate.getTime() / 1000)) && (cmtTime <= (toDate.getTime() / 1000)); } @Override public RevFilter clone() { return this; } }); } else { if (fromDate != null) { walk.setRevFilter(CommitTimeRevFilter.after(fromDate)); } if (toDate != null) { walk.setRevFilter(CommitTimeRevFilter.before(toDate)); } } if (fromRevId != null) { RevCommit c = walk.parseCommit(fromRevId); c.add(RevFlag.UNINTERESTING); RevCommit real = walk.parseCommit(c); walk.markUninteresting(real); } if (toRevId != null) { RevCommit c = walk.parseCommit(toRevId); c.remove(RevFlag.UNINTERESTING); RevCommit real = walk.parseCommit(c); walk.markStart(real); } else { final ObjectId head = repo.resolve(Constants.HEAD); if (head == null) { throw new RuntimeException("Cannot resolve " + Constants.HEAD); } RevCommit real = walk.parseCommit(head); walk.markStart(real); } int n = 0; for (final RevCommit c : walk) { n++; if (maxLines != -1 && n > maxLines) { break; } revs.add(c); } return revs; }
From source file:org.eclipse.orion.server.git.jobs.LogCommand.java
License:Eclipse Distribution License
public LogCommand setDateFilter(String fromDate, String toDate) { checkCallable();// w w w.ja va 2 s . c o m try { if (fromDate != null) { long fromD = Long.parseLong(fromDate); if (toDate != null) { long toD = Long.parseLong(toDate); dateFilter = CommitTimeRevFilter.between(fromD, toD); } else { dateFilter = CommitTimeRevFilter.after(fromD); } } else if (toDate != null) { Long toD = Long.parseLong(toDate); if (toD != null) dateFilter = CommitTimeRevFilter.before(toD); } } catch (NumberFormatException ex) { } return this; }