Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jgit-dev] RevWalk not happy with RevCommit?

On Tue, Aug 20, 2013 at 9:01 PM, Brad Larson <bklarson@xxxxxxxxx> wrote:
I'm trying to walk a commit history to parse some commit messages.  I'm passed in two RevCommits as start and end points.  For some reason, the RevWalk isn't happy with these commits - returns null.  However if I create duplicate RevCommits from the same Object IDs, RevWalk is fine.  I've noticed there are a couple extra flags in the 'bad' versions - is creating new RevCommits the way to go?  Or what am I doing wrong?

String getLog(RevCommit start, RevCommit end, Repository db) {
    RevWalk rw = new RevWalk(db);
    RevCommit a = rw.parseCommit(start.getId());
    RevCommit b = rw.parseCommit(end.getId());
    for(RevCommit c : rw) {
        String msg = c.getFullMessage();

end : commit 339db54924b607eb6657a11dadb5f59de88d1f80 1376329171 -t--sp
b: commit 339db54924b607eb6657a11dadb5f59de88d1f80 1376329171 ----sp

start: commit 5195c009b3b0f9e58fe4b1f4e94d46c6331020e0 1376329090 -tr-sp
a: commit 5195c009b3b0f9e58fe4b1f4e94d46c6331020e0 1376329090 ---usp

Can I make this work with start/end or must I use a/b?

the RevCommits passed to RevWalk must have been parsed
by the same RevWalk instance, see the javadoc of RevWalk.markStart(RevCommit).

So in short: pass around AnyObjectId instances which only represent the ID
and parse the start/end commits before passing them to markStart, markUninteresting.
If necessary set filters before walking. And remember you can walk only once, for
a second walk either create a new RevWalk or reset it.

If you need examples have a look at these classes:

org.eclipse.jgit.pgm.RevWalkTextBuiltin and its subclasses


Back to the top