]> git.ipfire.org Git - thirdparty/git.git/commitdiff
mktag: allow omitting the header/body \n separator
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Tue, 5 Jan 2021 19:42:49 +0000 (20:42 +0100)
committerJunio C Hamano <gitster@pobox.com>
Tue, 5 Jan 2021 22:58:29 +0000 (14:58 -0800)
Change mktag's acceptance rules to accept an empty body without an
empty line after the header again. This fixes an ancient unintended
dregression in "mktag".

When "mktag" was introduced in ec4465adb3 (Add "tag" objects that can
be used to sign other objects., 2005-04-25) the input checks were much
looser. When it was documented it 6cfec03680 (mktag: minimally update
the description., 2007-06-10) it was clearly intended for this \n to
be optional:

    The message, when [it] exists, is separated by a blank line from
    the header.

But then in e0aaf781f6 (mktag.c: improve verification of tagger field
and tests, 2008-03-27) this was made an error, seemingly by
accident. It was just a result of the general header checks, and all
the tests after that patch have a trailing empty line (but did not
before).

Let's allow this again, and tweak the test semantics changed in
e0aaf781f6 to remove the redundant empty line. New tests added in
previous commits of mine already added an explicit test for allowing
the empty line between header and body.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
fsck.c
t/t3800-mktag.sh

diff --git a/fsck.c b/fsck.c
index 9c3a5942d2a0f36ceb31ab679758a2d9eb47bf66..69d0049e4d7c954f694d8ad8a42e7acf8503840e 100644 (file)
--- a/fsck.c
+++ b/fsck.c
@@ -987,6 +987,8 @@ int fsck_tag_standalone(const struct object_id *oid, const char *buffer,
        }
        else
                ret = fsck_ident(&buffer, oid, OBJ_TAG, options);
+       if (!*buffer)
+               goto done;
 
        if (!starts_with(buffer, "\n")) {
                /*
index 929bb9f492f9dc67fe583a4047fc701eac939ad6..1fd97def3302b30bd1c54e125e039903d834d266 100755 (executable)
@@ -446,7 +446,7 @@ tagger T A Gger <tagger@example.com> 1206478233 -0500
 
 EOF
 
-test_expect_mktag_success 'require a blank line before an empty body (1)'
+test_expect_mktag_success 'allow a blank line before an empty body (1)'
 
 cat >tag.sig <<EOF
 object $head
@@ -455,8 +455,7 @@ tag mytag
 tagger T A Gger <tagger@example.com> 1206478233 -0500
 EOF
 
-check_verify_failure 'require a blank line before an empty body (2)' \
-       '^error:.* extraHeaderEntry:'
+test_expect_mktag_success 'allow no blank line before an empty body (2)'
 
 ############################################################
 # 24. create valid tag
@@ -466,7 +465,6 @@ object $head
 type commit
 tag mytag
 tagger T A Gger <tagger@example.com> 1206478233 -0500
-
 EOF
 
 test_expect_mktag_success 'create valid tag object'