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

[PATCH -v3 2/8] fast-import: fix handling of deleted tags

From
Elijah Newren <newren@gmail.com>
Date
Oct 3, 2019, 20:27 UTC
Message-ID
<20191003202709.26279-3-newren@gmail.com>
In-Reply-To
<20191003202709.26279-1-newren@gmail.com>

If our input stream includes a tag which is later deleted, we were not properly deleting it. We did have a step which would delete it, but we left a tag in the tag list noting that it needed to be updated, and the updating of annotated tags occurred AFTER ref deletion. So, when we record that a tag needs to be deleted, also remove it from the list of annotated tags to update.

While this has likely been something that has not happened in practice, it will come up more in order to support nested tags. For nested tags, we either need to give temporary names to the intermediate tags and then delete them, or else we need to use the final name for the intermediate tags. If we use the final name for the intermediate tags, then in order to keep the sanity check that someone doesn't try to update the same tag twice, we need to delete the ref after creating the intermediate tag. So, either way nested tags imply the need to delete temporary inner tag references.

Helped-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Elijah Newren <newren@gmail.com>
---
 fast-import.c          | 27 +++++++++++++++++++++++++++
 t/t9300-fast-import.sh | 13 +++++++++++++
 2 files changed, 40 insertions(+)
diff --git a/fast-import.c b/fast-import.c
index b44d6a467e..caae0819f5 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -2778,6 +2778,7 @@ static void parse_new_tag(const char *arg)
 static void parse_reset_branch(const char *arg)
 {
 	struct branch *b;
+	const char *tag_name;
 
 	b = lookup_branch(arg);
 	if (b) {
@@ -2793,6 +2794,32 @@ static void parse_reset_branch(const char *arg)
 		b = new_branch(arg);
 	read_next_command();
 	parse_from(b);
+	if (b->delete && skip_prefix(b->name, "refs/tags/", &tag_name)) {
+		/*
+		 * Elsewhere, we call dump_branches() before dump_tags(),
+		 * and dump_branches() will handle ref deletions first, so
+		 * in order to make sure the deletion actually takes effect,
+		 * we need to remove the tag from our list of tags to update.
+		 *
+		 * NEEDSWORK: replace list of tags with hashmap for faster
+		 * deletion?
+		 */
+		struct tag *t, *prev = NULL;
+		for (t = first_tag; t; t = t->next_tag) {
+			if (!strcmp(t->name, tag_name))
+				break;
+			prev = t;
+		}
+		if (t) {
+			if (prev)
+				prev->next_tag = t->next_tag;
+			else
+				first_tag = t->next_tag;
+			if (!t->next_tag)
+				last_tag = prev;
+			/* There is no mem_pool_free(t) function to call. */
+		}
+	}
 	if (command_buf.len > 0)
 		unread_command_buf = 1;
 }
diff --git a/t/t9300-fast-import.sh b/t/t9300-fast-import.sh
index 141b7fa35e..74bc41333b 100755
--- a/t/t9300-fast-import.sh
+++ b/t/t9300-fast-import.sh
@@ -85,6 +85,15 @@ test_expect_success 'A: create pack from stdin' '
 	An annotated tag that annotates a blob.
 	EOF
 
+	tag to-be-deleted
+	from :3
+	data <<EOF
+	Another annotated tag that annotates a blob.
+	EOF
+
+	reset refs/tags/to-be-deleted
+	from 0000000000000000000000000000000000000000
+
 	INPUT_END
 	git fast-import --export-marks=marks.out <input &&
 	git whatchanged master
@@ -157,6 +166,10 @@ test_expect_success 'A: verify tag/series-A-blob' '
 	test_cmp expect actual
 '
 
+test_expect_success 'A: verify tag deletion is successful' '
+	test_must_fail git rev-parse --verify refs/tags/to-be-deleted
+'
+
 test_expect_success 'A: verify marks output' '
 	cat >expect <<-EOF &&
 	:2 $(git rev-parse --verify master:file2)
-- 
2.23.0.264.g3b9f7f2fc6
Previous: Elijah NewrenNext: Elijah Newren
Message 26 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.