[PATCH] format-patch: dereference tags with --ignore-if-in-upstream
- From
brian m. carlson <sandals@crustytoothpaste.net>
- Date
- Jun 1, 2015, 01:03 UTC
- Message-ID
- <1433120593-186980-1-git-send-email-sandals@crustytoothpaste.net>
- In-Reply-To
- <CAP8UFD1phg8E0JCgkz88CMUo9H-W=s5JDuKeCMOkf1=UYBJt+g@mail.gmail.com>
format-patch would segfault if provided a tag as one of the range endpoints in conjunction with --ignore-if-in-upstream, as it assumed the object was a commit and attempted to cast it to struct commit. Dereference the tag as soon as possible to prevent this, but not until after copying the necessary flags.
Reported-by: Bruce Korb <bruce.korb@gmail.com> Diagnosed-by: Christian Couder <christian.couder@gmail.com> Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> --- builtin/log.c | 6 ++++++ t/t4014-format-patch.sh | 10 ++++++++++ 2 files changed, 16 insertions(+)
diff --git a/builtin/log.c b/builtin/log.c index dd8f3fc..e0465ba 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -807,6 +807,12 @@ static void get_patch_ids(struct rev_info *rev, struct patch_ids *ids) o2 = rev->pending.objects[1].item; flags2 = o2->flags; + o1 = deref_tag(o1, NULL, 0); + o2 = deref_tag(o2, NULL, 0); + + if (!o1 || !o2) + die(_("Invalid tag.")); + if ((flags1 & UNINTERESTING) == (flags2 & UNINTERESTING)) die(_("Not a range.")); diff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh index c39e500..60b9875 100755 --- a/t/t4014-format-patch.sh +++ b/t/t4014-format-patch.sh @@ -57,6 +57,16 @@ test_expect_success "format-patch --ignore-if-in-upstream" ' ' +test_expect_success "format-patch --ignore-if-in-upstream handles tags" ' + + git tag -a v1 -m tag side && + git format-patch --stdout \ + --ignore-if-in-upstream master..v1 >patch1 && + cnt=$(grep "^From " patch1 | wc -l) && + test $cnt = 2 + +' + test_expect_success "format-patch doesn't consider merge commits" ' git checkout -b slave master &&
-- 2.4.0