format-patch: do not feed tags to clear_commit_marks()

"git format-patch --ignore-if-in-upstream A..B", when either A or B is a tag, failed miserably. This is because the code passes the tips it used for traversal to clear_commit_marks(), after running a temporary revision traversal to enumerate the commits on both branches to find if they have commits that make equivalent changes. The revision traversal machinery knows how to enumerate commits reachable starting from a tag, but clear_commit_marks() wants to take nothing but a commit. In the longer term, it might be a more correct fix to teach clear_commit_marks() to do the same "committish to commit" dereferencing that is done in the revision traversal machinery, but for now this fix should suffice. Reported-by: Bruce Korb <bruce.korb@gmail.com> Helped-by: Christian Couder <christian.couder@gmail.com> Helped-by: brian m. carlson <sandals@crustytoothpaste.net> Helped-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Jun 1, 2015 at 10:44 UTC 9b7a61d7dab1635607b1b5be480ac78944cafb45
2 files changed +14 -6
builtin/log.c
+6 -6
@@ -795,7 +795,7 @@ static int reopen_stdout(struct commit *commit, const char *subject,
795 static void get_patch_ids(struct rev_info *rev, struct patch_ids *ids)
796 {
797 struct rev_info check_rev;
798 - struct commit *commit;
798 + struct commit *commit, *c1, *c2;
799 struct object *o1, *o2;
800 unsigned flags1, flags2;
801
@@ -803,9 +803,11 @@ static void get_patch_ids(struct rev_info *rev, struct patch_ids *ids)
803 die(_("Need exactly one range."));
804
805 o1 = rev->pending.objects[0].item;
806 - flags1 = o1->flags;
806 o2 = rev->pending.objects[1].item;
807 + flags1 = o1->flags;
808 flags2 = o2->flags;
809 + c1 = lookup_commit_reference(o1->sha1);
810 + c2 = lookup_commit_reference(o2->sha1);
811
812 if ((flags1 & UNINTERESTING) == (flags2 & UNINTERESTING))
813 die(_("Not a range."));
@@ -827,10 +829,8 @@ static void get_patch_ids(struct rev_info *rev, struct patch_ids *ids)
829 }
830
831 /* reset for next revision walk */
830 - clear_commit_marks((struct commit *)o1,
831 - SEEN | UNINTERESTING | SHOWN | ADDED);
832 - clear_commit_marks((struct commit *)o2,
833 - SEEN | UNINTERESTING | SHOWN | ADDED);
832 + clear_commit_marks(c1, SEEN | UNINTERESTING | SHOWN | ADDED);
833 + clear_commit_marks(c2, SEEN | UNINTERESTING | SHOWN | ADDED);
834 o1->flags = flags1;
835 o2->flags = flags2;
836 }
t/t4014-format-patch.sh
+8
@@ -57,6 +57,14 @@ test_expect_success "format-patch --ignore-if-in-upstream" '
57
58 '
59
60 +test_expect_success "format-patch --ignore-if-in-upstream handles tags" '
61 + git tag -a v1 -m tag side &&
62 + git tag -a v2 -m tag master &&
63 + git format-patch --stdout --ignore-if-in-upstream v2..v1 >patch1 &&
64 + cnt=$(grep "^From " patch1 | wc -l) &&
65 + test $cnt = 2
66 +'
67 +
68 test_expect_success "format-patch doesn't consider merge commits" '
69
70 git checkout -b slave master &&