Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jgit-dev] RevWalk not iterating over any commits

On Tue, Jan 11, 2011 at 08:59, Jan Finis <finis@xxxxxxxxx> wrote:
> the API of RevWalk is quite ambiguous. When creating a RevWalk from a
> Repository, shouldn't that RevWalk contain all commits of that repository,
> or at least any? The constructor taking a Repository does not state this.

You need to add one or more start points of the commit DAG before the
RevWalk is able to perform any traversal.

> So what am I doing wrong here? I want to loop over all commits of a
> repository, prefarrably in a chronological order. Can you tell me how to do
> this best (since RevWalk seems not to do it)?

Repository repo = ...;
RevWalk rw = new RevWalk(repo);

for (Ref ref : repo.getAllRefs().values()) {
  try {
    rw.markStart(rw.parseCommit(ref.getObjectId()));
  } catch (IncorrectObjectException notACommit) {
    continue;
  }
}

for (RevCommit c : walk) {
  System.out.println(c.name());
}

-- 
Shawn.


Back to the top