Skip to contentSkip to conversation

fast-import: tag may point to any object type

PATCH NAK Dmitry Potapov 2 participants 5 messages Jun 15, 2016 – Aug 13, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fast-import: tag may point to any object type

If you tried to export the official git repository, and then to import it back then git-fast-import would die complaining that "Mark :1 not a commit".

Accordingly to a generated crash file, Mark 1 is not a commit but a blob, which is pointed by junio-gpg-pub tag. Because git-tag allows to create such tags, git-fast-import should import them.

---
 fast-import.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
fast-import.c +3 -3
index cd87049..e99990d 100644
@@ -2305,6 +2305,7 @@ static void parse_new_tag(void)
 	struct tag *t;
 	uintmax_t from_mark = 0;
 	unsigned char sha1[20];
+	enum object_type type = OBJ_COMMIT;
 
 	/* Obtain the new tag name from the rest of our command */
 	sp = strchr(command_buf.buf, ' ') + 1;
@@ -2329,8 +2330,7 @@ static void parse_new_tag(void)
 		struct object_entry *oe;
 		from_mark = strtoumax(from + 1, NULL, 10);
 		oe = find_mark(from_mark);
-		if (oe->type != OBJ_COMMIT)
-			die("Mark :%" PRIuMAX " not a commit", from_mark);
+		type = oe->type;
 		hashcpy(sha1, oe->sha1);
 	} else if (!get_sha1(from, sha1)) {
 		unsigned long size;
@@ -2362,7 +2362,7 @@ static void parse_new_tag(void)
 		    "object %s\n"
 		    "type %s\n"
 		    "tag %s\n",
-		    sha1_to_hex(sha1), commit_type, t->name);
+		    sha1_to_hex(sha1), typename(type), t->name);
 	if (tagger)
 		strbuf_addf(&new_data,
 			    "tagger %s\n", tagger);
Signature · 1 line
1.6.6
#1 lore raw
Quoted 17 lines · Dmitry Potapov

If you tried to export the official git repository, and then to import it back then git-fast-import would die complaining that "Mark :1 not a commit".

Accordingly to a generated crash file, Mark 1 is not a commit but a blob, which is pointed by junio-gpg-pub tag. Because git-tag allows to create such tags, git-fast-import should import them.

---
 fast-import.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
fast-import.c +0 -0
index cd87049..e99990d 100644

fast-import.c static void parse_new_tag(void) · line 2308

Quoted 4 lines
fast-import.c +1 -0
@@ -2305,6 +2305,7 @@ static void parse_new_tag(void)
 	struct tag *t;
 	uintmax_t from_mark = 0;
 	unsigned char sha1[20];
+	enum object_type type = OBJ_COMMIT;

NAK.

Your patch is the right idea. But you need to make sure all of the branch arms are handled correctly.

That is, if we do this, the get_sha1() on line 2459 should also permit non-commit objects, and the lookup_branch() earlier up on line 2451 should do "type = OBJ_COMMIT".

Signature · 1 line
Shawn.
#2 lore raw

PATCH v2 1/1 fast-import: tag may point to any object type

If you tried to export the official git repository, and then to import it back then git-fast-import would die complaining that "Mark :1 not a commit".

Accordingly to a generated crash file, Mark 1 is not a commit but a blob, which is pointed by junio-gpg-pub tag. Because git-tag allows to create such tags, git-fast-import should import them.

---

Quoted 7 lines · Shawn O. Pearce

Your patch is the right idea. But you need to make sure all of the branch arms are handled correctly.

That is, if we do this, the get_sha1() on line 2459 should also permit non-commit objects, and the lookup_branch() earlier up on line 2451 should do "type = OBJ_COMMIT".

Thank you for guideliness. I do not understand this code well. I hope I got it right this time.

 fast-import.c |   10 ++++++----
 1 files changed, 6 insertions(+), 4 deletions(-)
fast-import.c +6 -4
index cd87049..4fdf809 100644
@@ -2305,6 +2305,7 @@ static void parse_new_tag(void)
 	struct tag *t;
 	uintmax_t from_mark = 0;
 	unsigned char sha1[20];
+	enum object_type type;
 
 	/* Obtain the new tag name from the rest of our command */
 	sp = strchr(command_buf.buf, ' ') + 1;
@@ -2325,19 +2326,20 @@ static void parse_new_tag(void)
 	s = lookup_branch(from);
 	if (s) {
 		hashcpy(sha1, s->sha1);
+		type = OBJ_COMMIT;
 	} else if (*from == ':') {
 		struct object_entry *oe;
 		from_mark = strtoumax(from + 1, NULL, 10);
 		oe = find_mark(from_mark);
-		if (oe->type != OBJ_COMMIT)
-			die("Mark :%" PRIuMAX " not a commit", from_mark);
+		type = oe->type;
 		hashcpy(sha1, oe->sha1);
 	} else if (!get_sha1(from, sha1)) {
 		unsigned long size;
 		char *buf;
 
+		type = sha1_object_info(sha1, NULL);
 		buf = read_object_with_reference(sha1,
-			commit_type, &size, sha1);
+			typename(type), &size, sha1);
 		if (!buf || size < 46)
 			die("Not a valid commit: %s", from);
 		free(buf);
@@ -2362,7 +2364,7 @@ static void parse_new_tag(void)
 		    "object %s\n"
 		    "type %s\n"
 		    "tag %s\n",
-		    sha1_to_hex(sha1), commit_type, t->name);
+		    sha1_to_hex(sha1), typename(type), t->name);
 	if (tagger)
 		strbuf_addf(&new_data,
 			    "tagger %s\n", tagger);
Signature · 1 line
1.6.6.137.g1acb
Acked-by on v2 1/1
#3 lore raw
Quoted 2 lines · Dmitry Potapov

If you tried to export the official git repository, and then to import it back then git-fast-import would die complaining that "Mark :1 not a commit".

...

fast-import.c static void parse_new_tag(void) · line 2332

Quoted 13 lines
fast-import.c +2 -1
index cd87049..4fdf809 100644
@@ -2325,19 +2326,20 @@ static void parse_new_tag(void)
 	} else if (!get_sha1(from, sha1)) {
 		unsigned long size;
 		char *buf;
 
+		type = sha1_object_info(sha1, NULL);
 		buf = read_object_with_reference(sha1,
-			commit_type, &size, sha1);
+			typename(type), &size, sha1);

This is better spelled as:

  buf = read_sha1_file(sha1, &type, &size);

But otherwise the patch looks correct now, thanks.

If you could make this one change, add my

and resend so Junio can apply, thanks.

Signature · 1 line
Shawn.
#4 lore raw

PATCH v3 1/1 fast-import: tag may point to any object type

If you tried to export the official git repository, and then to import it back then git-fast-import would die complaining that "Mark :1 not a commit".

Accordingly to a generated crash file, Mark 1 is not a commit but a blob, which is pointed by junio-gpg-pub tag. Because git-tag allows to create such tags, git-fast-import should import them.

---

Quoted 10 lines · Shawn O. Pearce

Review

Quoted 5 lines · Dmitry Potapov
(quoted diff) +2 -1
+		type = sha1_object_info(sha1, NULL);
 		buf = read_object_with_reference(sha1,
-			commit_type, &size, sha1);
+			typename(type), &size, sha1);

This is better spelled as:

  buf = read_sha1_file(sha1, &type, &size);

Thank you for correction.

Quoted 8 lines

But otherwise the patch looks correct now, thanks.

If you could make this one change, add my

and resend so Junio can apply, thanks.

 fast-import.c |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)
fast-import.c +5 -5
index cd87049..60d0aa2 100644
@@ -2305,6 +2305,7 @@ static void parse_new_tag(void)
 	struct tag *t;
 	uintmax_t from_mark = 0;
 	unsigned char sha1[20];
+	enum object_type type;
 
 	/* Obtain the new tag name from the rest of our command */
 	sp = strchr(command_buf.buf, ' ') + 1;
@@ -2325,19 +2326,18 @@ static void parse_new_tag(void)
 	s = lookup_branch(from);
 	if (s) {
 		hashcpy(sha1, s->sha1);
+		type = OBJ_COMMIT;
 	} else if (*from == ':') {
 		struct object_entry *oe;
 		from_mark = strtoumax(from + 1, NULL, 10);
 		oe = find_mark(from_mark);
-		if (oe->type != OBJ_COMMIT)
-			die("Mark :%" PRIuMAX " not a commit", from_mark);
+		type = oe->type;
 		hashcpy(sha1, oe->sha1);
 	} else if (!get_sha1(from, sha1)) {
 		unsigned long size;
 		char *buf;
 
-		buf = read_object_with_reference(sha1,
-			commit_type, &size, sha1);
+		buf = read_sha1_file(sha1, &type, &size);
 		if (!buf || size < 46)
 			die("Not a valid commit: %s", from);
 		free(buf);
@@ -2362,7 +2362,7 @@ static void parse_new_tag(void)
 		    "object %s\n"
 		    "type %s\n"
 		    "tag %s\n",
-		    sha1_to_hex(sha1), commit_type, t->name);
+		    sha1_to_hex(sha1), typename(type), t->name);
 	if (tagger)
 		strbuf_addf(&new_data,
 			    "tagger %s\n", tagger);
Signature · 1 line
1.6.6.137.g1acb