/** * Returns a list of commits since the minimum date starting from the specified object id. * * @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 (objectId == null) { 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) { // todo Logger.error(t, t.getMessage()); } return list; }
// the RevWalk must be reset by the caller upon return! private ArrayList<RevCommit> findCommits( RevWalk walk, ArrayList<RevCommit> included, ArrayList<RevCommit> excluded, boolean getBody, long after) throws MissingObjectException, IncorrectObjectTypeException, IOException { ArrayList<RevCommit> commits = new ArrayList<RevCommit>(); commits.ensureCapacity(allBranches.size()); // heuristic workaround walk.sort(RevSort.COMMIT_TIME_DESC, true); walk.sort(RevSort.TOPO, true); walk.setRetainBody(getBody); if (after > 0) walk.setRevFilter(CommitTimeRevFilter.after(after)); else walk.setRevFilter(null); walk.markStart(included); RevCommit c; Iterator<RevCommit> it = excluded.iterator(); while (it.hasNext()) { walk.markUninteresting(it.next()); } it = walk.iterator(); while (it.hasNext()) { c = it.next(); if (getBody) walk.parseBody(c); // addUnique(commits, c); // commits are naturally ordered by SHA-1 commits.add(c); } return commits.size() > 0 ? commits : null; }
private void markReachable(final Set<ObjectId> have, final int maxTime) throws IOException { for (final Ref r : local.getAllRefs().values()) { try { final RevCommit o = walk.parseCommit(r.getObjectId()); o.add(REACHABLE); reachableCommits.add(o); } catch (IOException readError) { // If we cannot read the value of the ref skip it. } } for (final ObjectId id : have) { try { final RevCommit o = walk.parseCommit(id); o.add(REACHABLE); reachableCommits.add(o); } catch (IOException readError) { // If we cannot read the value of the ref skip it. } } if (maxTime > 0) { // Mark reachable commits until we reach maxTime. These may // wind up later matching up against things we want and we // can avoid asking for something we already happen to have. // final Date maxWhen = new Date(maxTime * 1000L); walk.sort(RevSort.COMMIT_TIME_DESC); walk.markStart(reachableCommits); walk.setRevFilter(CommitTimeRevFilter.after(maxWhen)); for (; ; ) { final RevCommit c = walk.next(); if (c == null) break; if (c.has(ADVERTISED) && !c.has(COMMON)) { // This is actually going to be a common commit, but // our peer doesn't know that fact yet. // c.add(COMMON); c.carry(COMMON); reachableCommits.add(c); } } } }