fast-import: allow tags to be identified by mark labels

Mark identifiers are used in fast-export and fast-import to provide a label to refer to earlier content. Blobs are given labels because they need to be referenced in the commits where they first appear with a given filename, and commits are given labels because they can be the parents of other commits. Tags were never given labels, probably because they were viewed as unnecessary, but that presents two problems: 1. It leaves us without a way of referring to previous tags if we want to create a tag of a tag (or higher nestings). 2. It leaves us with no way of recording that a tag has already been imported when using --export-marks and --import-marks. Fix these problems by allowing an optional mark label for tags. Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Elijah Newren committed Oct 3, 2019 at 13:27 UTC f73b2aba05788208ccd9b48f350b90cbfe57e1c4
3 files changed +22 -1
Documentation/git-fast-import.txt
+1
@@ -774,6 +774,7 @@ lightweight (non-annotated) tags see the `reset` command below.
774
775 ....
776 'tag' SP <name> LF
777 + mark?
778 'from' SP <commit-ish> LF
779 original-oid?
780 'tagger' (SP <name>)? SP LT <email> GT SP <when> LF
fast-import.c
+2 -1
@@ -2713,6 +2713,7 @@ static void parse_new_tag(const char *arg)
2713 first_tag = t;
2714 last_tag = t;
2715 read_next_command();
2716 + parse_mark();
2717
2718 /* from ... */
2719 if (!skip_prefix(command_buf.buf, "from ", &from))
@@ -2769,7 +2770,7 @@ static void parse_new_tag(const char *arg)
2770 strbuf_addbuf(&new_data, &msg);
2771 free(tagger);
2772
2772 - if (store_object(OBJ_TAG, &new_data, NULL, &t->oid, 0))
2773 + if (store_object(OBJ_TAG, &new_data, NULL, &t->oid, next_mark))
2774 t->pack_id = MAX_PACK_ID;
2775 else
2776 t->pack_id = pack_id;
t/t9300-fast-import.sh
+19
@@ -94,6 +94,23 @@ test_expect_success 'A: create pack from stdin' '
94 reset refs/tags/to-be-deleted
95 from 0000000000000000000000000000000000000000
96
97 + tag nested
98 + mark :6
99 + from :4
100 + data <<EOF
101 + Tag of our lovely commit
102 + EOF
103 +
104 + reset refs/tags/nested
105 + from 0000000000000000000000000000000000000000
106 +
107 + tag nested
108 + mark :7
109 + from :6
110 + data <<EOF
111 + Tag of tag of our lovely commit
112 + EOF
113 +
114 INPUT_END
115 git fast-import --export-marks=marks.out <input &&
116 git whatchanged master
@@ -176,6 +193,8 @@ test_expect_success 'A: verify marks output' '
193 :3 $(git rev-parse --verify master:file3)
194 :4 $(git rev-parse --verify master:file4)
195 :5 $(git rev-parse --verify master^0)
196 + :6 $(git cat-file tag nested | grep object | cut -d" " -f 2)
197 + :7 $(git rev-parse --verify nested)
198 EOF
199 test_cmp expect marks.out
200 '