fast-import: make tagger information optional
Even though newer Porcelain tools always record the tagger information when creating new tags, export/import pair should be able to faithfully reproduce ancient tag objects that lack tagger information. Signed-off-by: Junio C Hamano <gitster@pobox.com> Acked-by: Shawn O. Pearce <spearce@spearce.org>
Junio C Hamano committed
Dec 19, 2008 at 14:41 UTC
88fbf67b78c7bbe6c94150e7cd05f9398b571c48
2 files changed
+33
-11
fast-import.c
+15
-11
@@ -43,7 +43,7 @@ Format of STDIN stream:
43
44
new_tag ::= 'tag' sp tag_str lf
45
'from' sp (ref_str | hexsha1 | sha1exp_str | idnum) lf
46
- 'tagger' sp name '<' email '>' when lf
46
+ ('tagger' sp name '<' email '>' when lf)?
47
tag_msg;
48
tag_msg ::= data;
49
@@ -2264,23 +2264,27 @@ static void parse_new_tag(void)
2264
read_next_command();
2265
2266
/* tagger ... */
2267
- if (prefixcmp(command_buf.buf, "tagger "))
2268
- die("Expected tagger command, got %s", command_buf.buf);
2269
- tagger = parse_ident(command_buf.buf + 7);
2267
+ if (!prefixcmp(command_buf.buf, "tagger ")) {
2268
+ tagger = parse_ident(command_buf.buf + 7);
2269
+ read_next_command();
2270
+ } else
2271
+ tagger = NULL;
2272
2273
/* tag payload/message */
2272
- read_next_command();
2274
parse_data(&msg);
2275
2276
/* build the tag object */
2277
strbuf_reset(&new_data);
2278
+
2279
strbuf_addf(&new_data,
2278
- "object %s\n"
2279
- "type %s\n"
2280
- "tag %s\n"
2281
- "tagger %s\n"
2282
- "\n",
2283
- sha1_to_hex(sha1), commit_type, t->name, tagger);
2280
+ "object %s\n"
2281
+ "type %s\n"
2282
+ "tag %s\n",
2283
+ sha1_to_hex(sha1), commit_type, t->name);
2284
+ if (tagger)
2285
+ strbuf_addf(&new_data,
2286
+ "tagger %s\n", tagger);
2287
+ strbuf_addch(&new_data, '\n');
2288
strbuf_addbuf(&new_data, &msg);
2289
free(tagger);
2290
t/t9300-fast-import.sh
+18
@@ -56,6 +56,12 @@ M 644 :2 file2
56
M 644 :3 file3
57
M 755 :4 file4
58
59
+tag series-A
60
+from :5
61
+data <<EOF
62
+An annotated tag without a tagger
63
+EOF
64
+
65
INPUT_END
66
test_expect_success \
67
'A: create pack from stdin' \
@@ -101,6 +107,18 @@ test_expect_success \
107
'A: verify file4' \
108
'git cat-file blob master:file4 >actual && test_cmp expect actual'
109
110
+cat >expect <<EOF
111
+object $(git rev-parse refs/heads/master)
112
+type commit
113
+tag series-A
114
+
115
+An annotated tag without a tagger
116
+EOF
117
+test_expect_success 'A: verify tag/series-A' '
118
+ git cat-file tag tags/series-A >actual &&
119
+ test_cmp expect actual
120
+'
121
+
122
cat >expect <<EOF
123
:2 `git rev-parse --verify master:file2`
124
:3 `git rev-parse --verify master:file3`