-
Notifications
You must be signed in to change notification settings - Fork 524
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Grit::GitRuby::Repository.rev_list can produce results in the wrong order (parent before child) #38
Comments
Looks like GitHub-Flavoured Markdown was a bit too smart inside the code block there, those shouldn't be links of course... |
Crap, I clicked "comment and close" by accident! Can you please re-open? Thanks. |
Sounds reasonable to me. I feel like Grit::GitRuby should have some tests that compare the GitRuby implementation against the native git version too. If you could come up with a test case that passes with the native command, and fails with GitRuby, that'd be awesome. |
@technoweenie: I have created a repository with three commits; the second one was committed before the other ones (by setting the system clock). There's a clone at https://github.com/zmalltalker/strange_order/commits/master I have a failing test that creates a Grit::Repo from this repo, collects the commits of it (repo.commits) and verifies that their SHAs are in the wrong order. This test is probably at a too high level, but I'm having a hard time figuring out how to target the tests in a better way, probably because I don't really get what Grit::GitRuby::Repository#rev_list actually does. Would it help at all putting up that test case, or do you have any ideas on how to target the test better? |
@technoweenie I have a similar repo which exhibits this issue at https://github.com/philandstuff/grit-rev-list-problem-example The following session demonstrates the difference in order between cmd-line git and git-ruby:
|
Here's a simple fix for the case where the commit dates are equal(so like https://github.com/philandstuff/grit-rev-list-problem-example but not like https://github.com/zmalltalker/strange_order/commits/master ): - log = log.sort { |a, b| a[2] <=> b[2] }.reverse
+ log = log.sort_by.with_index { |a, i| [a[2], -i] }.reverse This makes the sort stable (see http://bugs.ruby-lang.org/issues/1089) and is enough to fix the issue in this case. Since the commit dates of rebased commits are all equal, this is an important issue, see for example the wrong order at https://gitorious.org/~smarter/libav/smarter-libav/commits/hevc and the corresponding bug report at https://issues.gitorious.org/issues/94 . |
Grit is no longer maintained. See #183 and check out libgit2/rugged. |
First of all, thanks! Grit is awesome!!
This is my first time playing with Grit or even poking around in git internals, so I apologize if I've gotten confused somewhere here, but it looks like the pure-ruby version of rev_list is assuming that chronological order is correct, but it may not be if two commits have the same timestamp.
With "git rev-list --date-order" (the default ordering anyway) "no parent comes before all of its children".
But GitRuby::Repository.rev_list simply orders by date which can result in a parent coming after it's child if they have the same timestamp.
At least that's my best guess as to what's happening. The original problem I was having was that repo.commits.first wasn't actually the most recent commit, and I think this is the cause.
I know this sounds like a far-out edge case, but I'm using Grit to commit programmatically and it happens in all of my test cases.
Here's an example output from the ruby version of rev_list:
You can see that the second one is the parent of the first. "git rev-list --pretty=raw" outputs them in the opposite order.
If I comment out Grit::GitRuby.rev_list (and let method_missing take care of it), then I get the correct result.
If that all sounds right I'd be happy to try to fix it but I wanted to get a sanity check first.
Thanks.
The text was updated successfully, but these errors were encountered: