]> granicus.if.org Git - git/commitdiff
fast-export: fix exporting a tag and nothing else
authorElijah Newren <newren@gmail.com>
Wed, 25 Sep 2019 01:39:58 +0000 (18:39 -0700)
committerJunio C Hamano <gitster@pobox.com>
Sat, 28 Sep 2019 09:54:40 +0000 (18:54 +0900)
fast-export allows specifying revision ranges, which can be used to
export a tag without exporting the commit it tags.  fast-export handled
this rather poorly: it would emit a "from :0" directive.  Since marks
start at 1 and increase, this means it refers to an unknown commit and
fast-import will choke on the input.

When we are unable to look up a mark for the object being tagged, use a
"from $HASH" directive instead to fix this problem.

Note that this is quite similar to the behavior fast-export exhibits
with commits and parents when --reference-excluded-parents is passed
along with an excluded commit range.  For tags of excluded commits we do
not require the --reference-excluded-parents flag because we always have
to tag something.  By contrast, when dealing with commits, pruning a
parent is always a viable option, so we need the flag to specify that
parent pruning is not wanted.  (It is slightly weird that
--reference-excluded-parents isn't the default with a separate
--prune-excluded-parents flag, but backward compatibility concerns
resulted in the current defaults.)

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/fast-export.c
t/t9350-fast-export.sh

index f541f55d333b7a29fcdca88919dc316a1fe0b931..5822271c6b0a12ebdab58513f7ea83d62489b4fd 100644 (file)
@@ -860,7 +860,12 @@ static void handle_tag(const char *name, struct tag *tag)
 
        if (starts_with(name, "refs/tags/"))
                name += 10;
-       printf("tag %s\nfrom :%d\n", name, tagged_mark);
+       printf("tag %s\n", name);
+       if (tagged_mark)
+               printf("from :%d\n", tagged_mark);
+       else
+               printf("from %s\n", oid_to_hex(&tagged->oid));
+
        if (show_original_ids)
                printf("original-oid %s\n", oid_to_hex(&tag->object.oid));
        printf("%.*s%sdata %d\n%.*s\n",
index b4004e05c2a72c4daf95c4ce74b2145a9486efc4..d32ff41859e7e9d31adad144c2b2432c1cb55a33 100755 (executable)
@@ -53,6 +53,19 @@ test_expect_success 'fast-export | fast-import' '
 
 '
 
+test_expect_success 'fast-export ^muss^{commit} muss' '
+       git fast-export --tag-of-filtered-object=rewrite ^muss^{commit} muss >actual &&
+       cat >expected <<-EOF &&
+       tag muss
+       from $(git rev-parse --verify muss^{commit})
+       $(git cat-file tag muss | grep tagger)
+       data 9
+       valentin
+
+       EOF
+       test_cmp expected actual
+'
+
 test_expect_success 'fast-export master~2..master' '
 
        git fast-export master~2..master >actual &&