git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Elijah Newren <newren@gmail.com>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>, Elijah Newren <newren@gmail.com>
Subject: [PATCH v2 2/8] fast-import: fix handling of deleted tags
Date: Mon, 30 Sep 2019 14:10:12 -0700	[thread overview]
Message-ID: <20190930211018.23633-3-newren@gmail.com> (raw)
In-Reply-To: <20190930211018.23633-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.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 fast-import.c          | 29 +++++++++++++++++++++++++++++
 t/t9300-fast-import.sh | 13 +++++++++++++
 2 files changed, 42 insertions(+)

diff --git a/fast-import.c b/fast-import.c
index b44d6a467e..546da3a938 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -2793,6 +2793,35 @@ static void parse_reset_branch(const char *arg)
 		b = new_branch(arg);
 	read_next_command();
 	parse_from(b);
+	if (b->delete && !strncmp(b->name, "refs/tags/", 10)) {
+		/*
+		 * 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 strbuf tag_name = STRBUF_INIT;
+		struct tag *t, *prev = NULL;
+		for (t = first_tag; t; t = t->next_tag) {
+			strbuf_reset(&tag_name);
+			strbuf_addf(&tag_name, "refs/tags/%s", t->name);
+			if (!strcmp(b->name, tag_name.buf))
+				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.gac739dbb79


  parent reply	other threads:[~2019-09-30 21:10 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-25  1:39 [PATCH 0/8] fast export/import: handle nested tags, improve incremental exports Elijah Newren
2019-09-25  1:39 ` [PATCH 1/8] fast-export: fix exporting a tag and nothing else Elijah Newren
2019-09-25  1:39 ` [PATCH 2/8] fast-import: fix handling of deleted tags Elijah Newren
2019-09-25  1:40 ` [PATCH 3/8] fast-import: allow tags to be identified by mark labels Elijah Newren
2019-09-25  1:40 ` [PATCH 4/8] fast-import: add support for new 'alias' command Elijah Newren
2019-09-25  1:40 ` [PATCH 5/8] fast-export: add support for --import-marks-if-exists Elijah Newren
2019-09-25  1:40 ` [PATCH 6/8] fast-export: allow user to request tags be marked with --mark-tags Elijah Newren
2019-09-25  1:40 ` [PATCH 7/8] t9350: add tests for tags of things other than a commit Elijah Newren
2019-09-25  1:40 ` [PATCH 8/8] fast-export: handle nested tags Elijah Newren
2019-09-30 21:10 ` [PATCH v2 0/8] fast export/import: handle nested tags, improve incremental exports Elijah Newren
2019-09-30 21:10   ` [PATCH v2 1/8] fast-export: fix exporting a tag and nothing else Elijah Newren
2019-09-30 21:10   ` Elijah Newren [this message]
2019-10-03 11:53     ` [PATCH v2 2/8] fast-import: fix handling of deleted tags René Scharfe
2019-09-30 21:10   ` [PATCH v2 3/8] fast-import: allow tags to be identified by mark labels Elijah Newren
2019-09-30 21:10   ` [PATCH v2 4/8] fast-import: add support for new 'alias' command Elijah Newren
2019-09-30 21:10   ` [PATCH v2 5/8] fast-export: add support for --import-marks-if-exists Elijah Newren
2019-09-30 21:10   ` [PATCH v2 6/8] fast-export: allow user to request tags be marked with --mark-tags Elijah Newren
2019-09-30 21:10   ` [PATCH v2 7/8] t9350: add tests for tags of things other than a commit Elijah Newren
2019-09-30 21:10   ` [PATCH v2 8/8] fast-export: handle nested tags Elijah Newren
2019-10-02 15:54   ` [PATCH v2 0/8] fast export/import: handle nested tags, improve incremental exports Elijah Newren
2019-10-02 20:10     ` Junio C Hamano
2019-10-02 21:05       ` Elijah Newren
2019-10-03  1:07         ` Junio C Hamano
2019-10-03 20:27   ` [PATCH -v3 " Elijah Newren
2019-10-03 20:27     ` [PATCH -v3 1/8] fast-export: fix exporting a tag and nothing else Elijah Newren
2019-10-03 20:27     ` [PATCH -v3 2/8] fast-import: fix handling of deleted tags Elijah Newren
2019-10-03 20:27     ` [PATCH -v3 3/8] fast-import: allow tags to be identified by mark labels Elijah Newren
2019-10-03 20:27     ` [PATCH -v3 4/8] fast-import: add support for new 'alias' command Elijah Newren
2019-10-03 20:27     ` [PATCH -v3 5/8] fast-export: add support for --import-marks-if-exists Elijah Newren
2019-10-03 20:27     ` [PATCH -v3 6/8] fast-export: allow user to request tags be marked with --mark-tags Elijah Newren
2019-10-03 20:27     ` [PATCH -v3 7/8] t9350: add tests for tags of things other than a commit Elijah Newren
2019-10-03 20:27     ` [PATCH -v3 8/8] fast-export: handle nested tags Elijah Newren
2019-10-04  5:51     ` [PATCH -v3 0/8] fast export/import: handle nested tags, improve incremental exports Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190930211018.23633-3-newren@gmail.com \
    --to=newren@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).