-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Prefer younger merge bases over older ones. #1681
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
Conversation
git-core prefers younger merge bases over older ones in case that multiple valid merge bases exists.
This fixes #1679 |
I just added a test case that is failing without my my change. |
seems reasonable 👍 |
This is closer to Eventually we'll want to fix this to actually look at the graph and decide which of the merge bases isn't an ancestor, but this is good as a fix. |
Prefer younger merge bases over older ones.
@carlosmn The way that merge bases are calculated is already correct, and follows the The issue here is/was that we have 2 "best" merge bases, which is correct, and where you could use any of them to do diffs/merges. |
The "best" merge base is defined as the one that's not an ancestor to any other, which means that we can't have two best merge bases unless neither is an ancestor which I'm fairly confident can't happen. Anyway, we agree that those two merges from This is where the definition for "best" from the manpage comes into play. We chose the one that's not an ancestor of the other one. In all sane cases it is going to be the one with the newest timestamp. However, I can create a merge base today with a date of one year from now. Next week you create a new merge base with a correct timestamp and run this. The older (in real terms) commit would be returned. Conversely I could create a new one which is older than the existing ones. Lange Rede kurzer Sinn, what I'm trying to say is that these decisions should happen by looking at the graph as we can't always trust timestamps and this is what the merge-base manpage says it does. |
@carlosmn (don't want to argue with you but) |
That's for showing all, not determining which is the best for single-output mode. I'll get home shortly and I'll investigate further |
@carlosmn https://github.com/git/git/blob/master/builtin/merge-base.c#L6 just takes the first result when |
Also, even the man page specifies that there can be multiple "best" merge bases, in case there is a criss-cross merge. |
Oh, and that example that I have in my test-case atually looks like a criss-cross merge I think. |
Yes, I was confusing which stage we were at. The list is indeed of merge bases so we have already taken the history into account. If we do actually have multiple merge bases, then we have a criss-cross merge and it's undefined what we show when the user doesn't ask for all of them. So in the end this isn't any more correct, just happens to have the same implementation detail as git-core. |
Prefer younger merge bases over older ones.
git-core prefers younger merge bases over older ones in case that multiple valid merge bases exists.
I'm not sure whether
git_commit_list_insert_by_date
is the correct place to make this change, but this function is only ever called bygit_merge__bases_many
, so I hope that's ok.I can also prepare a real test case for this, if the location of this change is determined to be ok. 😄