git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 1/8] fast-export: fix exporting a tag and nothing else

From
Elijah Newren <newren@gmail.com>
Date
Sep 30, 2019, 21:10 UTC
Message-ID
<20190930211018.23633-2-newren@gmail.com>
In-Reply-To
<20190930211018.23633-1-newren@gmail.com>

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>
---
 builtin/fast-export.c  |  7 ++++++-
 t/t9350-fast-export.sh | 13 +++++++++++++
 2 files changed, 19 insertions(+), 1 deletion(-)
diff --git a/builtin/fast-export.c b/builtin/fast-export.c
index f541f55d33..5822271c6b 100644
--- a/builtin/fast-export.c
+++ b/builtin/fast-export.c
@@ -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",
diff --git a/t/t9350-fast-export.sh b/t/t9350-fast-export.sh
index b4004e05c2..d32ff41859 100755
--- a/t/t9350-fast-export.sh
+++ b/t/t9350-fast-export.sh
@@ -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 &&
-- 
2.23.0.264.gac739dbb79
Previous: Elijah NewrenNext: Elijah Newren
Message 11 of 33 in “fast export/import: handle nested tags, improve incremental exports”
  1. 0/8 fast export/import: handle nested tags, improve incremental exportsElijah Newren, Sep 25, 2019
  2. 1/8 fast-export: fix exporting a tag and nothing elseElijah Newren, Sep 25, 2019
  3. 2/8 fast-import: fix handling of deleted tagsElijah Newren, Sep 25, 2019
  4. 3/8 fast-import: allow tags to be identified by mark labelsElijah Newren, Sep 25, 2019
  5. 4/8 fast-import: add support for new 'alias' commandElijah Newren, Sep 25, 2019
  6. 6/8 fast-export: allow user to request tags be marked with --mark-tagsElijah Newren, Sep 25, 2019
  7. 5/8 fast-export: add support for --import-marks-if-existsElijah Newren, Sep 25, 2019
  8. 7/8 t9350: add tests for tags of things other than a commitElijah Newren, Sep 25, 2019
  9. 8/8 fast-export: handle nested tagsElijah Newren, Sep 25, 2019
  10. 0/8 fast export/import: handle nested tags, improve incremental exportsElijah Newren, Sep 30, 2019
  11. 1/8 fast-export: fix exporting a tag and nothing elseElijah Newren, Sep 30, 2019
  12. 2/8 fast-import: fix handling of deleted tagsElijah Newren, Sep 30, 2019
  13. René ScharfeOct 3, 2019
  14. 3/8 fast-import: allow tags to be identified by mark labelsElijah Newren, Sep 30, 2019
  15. 4/8 fast-import: add support for new 'alias' commandElijah Newren, Sep 30, 2019
  16. 5/8 fast-export: add support for --import-marks-if-existsElijah Newren, Sep 30, 2019
  17. 6/8 fast-export: allow user to request tags be marked with --mark-tagsElijah Newren, Sep 30, 2019
  18. 7/8 t9350: add tests for tags of things other than a commitElijah Newren, Sep 30, 2019
  19. 8/8 fast-export: handle nested tagsElijah Newren, Sep 30, 2019
  20. Elijah NewrenOct 2, 2019
  21. Junio C HamanoOct 2, 2019
  22. Elijah NewrenOct 2, 2019
  23. Junio C HamanoOct 3, 2019
  24. 0/8 fast export/import: handle nested tags, improve incremental exportsElijah Newren, Oct 3, 2019
  25. 1/8 fast-export: fix exporting a tag and nothing elseElijah Newren, Oct 3, 2019
  26. 2/8 fast-import: fix handling of deleted tagsElijah Newren, Oct 3, 2019
  27. 3/8 fast-import: allow tags to be identified by mark labelsElijah Newren, Oct 3, 2019
  28. 4/8 fast-import: add support for new 'alias' commandElijah Newren, Oct 3, 2019
  29. 5/8 fast-export: add support for --import-marks-if-existsElijah Newren, Oct 3, 2019
  30. 7/8 t9350: add tests for tags of things other than a commitElijah Newren, Oct 3, 2019
  31. 8/8 fast-export: handle nested tagsElijah Newren, Oct 3, 2019
  32. 6/8 fast-export: allow user to request tags be marked with --mark-tagsElijah Newren, Oct 3, 2019
  33. Junio C HamanoOct 4, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.