aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2010-07-12 17:27:46 -0700
committerJunio C Hamano <gitster@pobox.com>2010-07-13 13:53:20 -0700
commitc008c0ff2087da7b98adfa760247776619b32224 (patch)
tree6e31414f8d7a4a04bb85a4e9bcfae77a182f666c
parent29981380d03ffa63765dbeaea53a7ac9e8d6bc4f (diff)
downloadgit-c008c0ff2087da7b98adfa760247776619b32224.tar.gz
git-c008c0ff2087da7b98adfa760247776619b32224.tar.xz
diff A...B: give one possible diff when there are more than one merge-base
We instead showed a combined diff that explains one of the randomly chosen merge-base as if it were the result of merging all the other merge bases and two tips given, which made no sense at all. An alternative is to simply fail such a request, telling the user that there are criss-cross merges, but it wouldn't be so helpful. Noticed by James Pickens. Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--builtin-diff.c31
1 files changed, 23 insertions, 8 deletions
diff --git a/builtin-diff.c b/builtin-diff.c
index 2e51f408f..62b483bd5 100644
--- a/builtin-diff.c
+++ b/builtin-diff.c
@@ -405,17 +405,32 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
result = builtin_diff_index(&rev, argc, argv);
else if (ents == 2)
result = builtin_diff_tree(&rev, argc, argv, ent);
- else if ((ents == 3) && (ent[0].item->flags & UNINTERESTING)) {
- /* diff A...B where there is one sane merge base between
- * A and B. We have ent[0] == merge-base, ent[1] == A,
- * and ent[2] == B. Show diff between the base and B.
+ else if (ent[0].item->flags & UNINTERESTING) {
+ /*
+ * Perhaps the user gave us A...B, which expands
+ * to a list of negative merge bases followed by
+ * A (symmetric-left) and B? Let's make sure...
*/
- ent[1] = ent[2];
+ for (i = 1; i < ents; i++)
+ if (!(ent[i].item->flags & UNINTERESTING))
+ break;
+ if (ents != i + 2 ||
+ (ent[i+1].item->flags & UNINTERESTING) ||
+ (!(ent[i].item->flags & SYMMETRIC_LEFT)) ||
+ (ent[i+1].item->flags & SYMMETRIC_LEFT))
+ die("what do you mean by that?");
+ /*
+ * diff A...B where there is at least one merge base
+ * between A and B. We have ent[0] == merge-base,
+ * ent[ents-2] == A, and ent[ents-1] == B. Show diff
+ * between the base and B. Note that we pick one
+ * merge base at random if there are more than one.
+ */
+ ent[1] = ent[ents-1];
result = builtin_diff_tree(&rev, argc, argv, ent);
- }
- else
+ } else
result = builtin_diff_combined(&rev, argc, argv,
- ent, ents);
+ ent, ents);
result = diff_result_code(&rev.diffopt, result);
if (1 < rev.diffopt.skip_stat_unmatch)
refresh_index_quietly();