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

[PATCH 2/2] fast-import: allow to tag newly created objects

From
Dmitry Ivankov <divanorama@gmail.com>
Date
Aug 22, 2011, 12:10 UTC
Message-ID
<1314015019-6636-3-git-send-email-divanorama@gmail.com>
In-Reply-To
<1314015019-6636-1-git-send-email-divanorama@gmail.com>

fast-import allows to tag objects by sha1 and to query sha1 of objects being imported. So it should allow to tag these objects, make it do so.

Signed-off-by: Dmitry Ivankov <divanorama@gmail.com>
---
 fast-import.c          |   10 +++++++---
 t/t9300-fast-import.sh |   26 ++++++++++++++++++++++++++
 2 files changed, 33 insertions(+), 3 deletions(-)
diff --git a/fast-import.c b/fast-import.c
index 0b0f598..11eb6bf 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -2690,9 +2690,13 @@ static void parse_new_tag(void)
 		type = oe->type;
 		hashcpy(sha1, oe->idx.sha1);
 	} else if (!get_sha1(from, sha1)) {
-		type = sha1_object_info(sha1, NULL);
-		if (type < 0)
-			die("Not a valid object: %s", from);
+		struct object_entry *oe = find_object(sha1);
+		if (!oe) {
+			type = sha1_object_info(sha1, NULL);
+			if (type < 0)
+				die("Not a valid object: %s", from);
+		} else
+			type = oe->type;
 	} else
 		die("Invalid ref name or SHA1 expression: %s", from);
 	read_next_command();
diff --git a/t/t9300-fast-import.sh b/t/t9300-fast-import.sh
index 41f0d02..efe9779 100755
--- a/t/t9300-fast-import.sh
+++ b/t/t9300-fast-import.sh
@@ -188,12 +188,32 @@ test_expect_success \
 	test_cmp expect marks.new'
 
 test_tick
+new_blob=$(echo testing | git hash-object --stdin)
 cat >input <<INPUT_END
 tag series-A-blob-2
 from $(git rev-parse refs/heads/master:file3)
 data <<EOF
 Tag blob by sha1.
 EOF
+
+blob
+mark :6
+data <<EOF
+testing
+EOF
+
+commit refs/heads/new_blob
+committer  <> 0 +0000
+data 0
+M 644 :6 new_blob
+#pretend we got sha1 from fast-import
+ls "new_blob"
+
+tag series-A-blob-3
+from $new_blob
+data <<EOF
+Tag new_blob.
+EOF
 INPUT_END
 
 cat >expect <<EOF
@@ -202,12 +222,18 @@ type blob
 tag series-A-blob-2
 
 Tag blob by sha1.
+object $new_blob
+type blob
+tag series-A-blob-3
+
+Tag new_blob.
 EOF
 
 test_expect_success \
 	'A: tag blob by sha1' \
 	'git fast-import <input &&
 	git cat-file tag tags/series-A-blob-2 >actual &&
+	git cat-file tag tags/series-A-blob-3 >>actual &&
 	test_cmp expect actual'
 
 test_tick
-- 
1.7.3.4
Previous: Dmitry IvankovNext: Junio C Hamano
Message 3 of 4 in “fast-import: tag any object by sha1”
  1. 0/2 fast-import: tag any object by sha1Dmitry Ivankov, Aug 22, 2011
  2. 1/2 fast-import: add tests for tagging blobsDmitry Ivankov, Aug 22, 2011
  3. 2/2 fast-import: allow to tag newly created objectsDmitry Ivankov, Aug 22, 2011
  4. Junio C HamanoAug 23, 2011

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.