Take the 2-minute tour ×

I need to draw a graph out of a Git repository using JGit.

I've been thinking about different ways to traverse the commits. I need to be able to draw a graph/graphs out of the branches/commits, and I also need to be able to do it within arbitrary ranges, like let's say from 200th commit to 250th commit (skipping the 200 most recently made commits).

How should I traverse the repository? Using RevWalk? I'd like to keep it adequately performant, and I was wondering if there's a one definite way to do this well.

Update: Basically I'm looking into making something like git log --graph -n 50 --skip 200 which shows a graph of the repository between 200-250 commits in creation order. Now I just want to do this myself. :)

Update 2: It would be nice if I could also iterate over the ones that are dangling (have no references), and draw them in gray color.

share|improve this question
Maybe gitective is usefull for you. The library offers a lot simple methods to handle commits with JGit. –  Sonson123 Oct 6 '12 at 20:27

1 Answer 1

Yup I agree with you, you should use RevWalk. JGit offers porcelain API that would be like the log call, but it offers interesting entry-points in the lower layer.

It is probably much more efficient than using the porcelain API or any Git-based approach.

I don't really see what you mean by unreferenced commits. Those that are not in a branch?

Another thing is I am not sure you can query all the commits at once, I mean you should query each branch, but I guess you already thought of it. I've always wondered if there was a faster way than querying each branch (if they're short and have a huge common history it's a big loss of time)

share|improve this answer
There's a LogCommand. E.g. new Git(repo).log().call() which returns an Iterable. I'm not sure if I should use this. –  Tower Sep 12 '12 at 16:40
you can try, but as I wrote it's probably not the same performance. You can try to find the source for LogCommand.call(), I guess it uses RevWalk. It would be a good start for your project. –  Vince Sep 12 '12 at 20:02

Your Answer


