4

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.

Tower
  • 98,741
  • 129
  • 357
  • 507
  • 1
    Maybe [gitective](https://github.com/kevinsawicki/gitective) is usefull for you. The library offers a lot simple methods to handle commits with JGit. – Sonson123 Oct 06 '12 at 20:27

2 Answers2

2

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)

Vince
  • 1,570
  • 3
  • 27
  • 48
  • 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
0

I don't have an answer for you as yet, but I've been revisiting this topic, as I used to have an algorithm that worked reasonably ok for JGit 2.1.0 (2012-09-19), but then a few months back I upgraded to JGit 5.5.1 (2019-10-02) and the graphs started looking bizarre and broken.

I've been studying JGit source looking for clues and info, this very verbose and detailed commit message seems to go to great depths in describing the new algorithm, I just haven't come to grips with it as yet.

https://github.com/eclipse/jgit/commit/7d6dcd4b34fef87d73d7137b2cf66b3e15216a2f

If I do, I'll try update this answer with something more specific.

Gurce
  • 592
  • 7
  • 18