Skip to content

Commit af2abd8

Browse files
newrengitster
authored andcommitted
fast-export: fix exporting a tag and nothing else
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4c86140 commit af2abd8

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

builtin/fast-export.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,12 @@ static void handle_tag(const char *name, struct tag *tag)
860860

861861
if (starts_with(name, "refs/tags/"))
862862
name += 10;
863-
printf("tag %s\nfrom :%d\n", name, tagged_mark);
863+
printf("tag %s\n", name);
864+
if (tagged_mark)
865+
printf("from :%d\n", tagged_mark);
866+
else
867+
printf("from %s\n", oid_to_hex(&tagged->oid));
868+
864869
if (show_original_ids)
865870
printf("original-oid %s\n", oid_to_hex(&tag->object.oid));
866871
printf("%.*s%sdata %d\n%.*s\n",

t/t9350-fast-export.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,19 @@ test_expect_success 'fast-export | fast-import' '
5353
5454
'
5555

56+
test_expect_success 'fast-export ^muss^{commit} muss' '
57+
git fast-export --tag-of-filtered-object=rewrite ^muss^{commit} muss >actual &&
58+
cat >expected <<-EOF &&
59+
tag muss
60+
from $(git rev-parse --verify muss^{commit})
61+
$(git cat-file tag muss | grep tagger)
62+
data 9
63+
valentin
64+
65+
EOF
66+
test_cmp expected actual
67+
'
68+
5669
test_expect_success 'fast-export master~2..master' '
5770
5871
git fast-export master~2..master >actual &&

0 commit comments

Comments
 (0)