fast-export: allow user to request tags be marked with --mark-tags

Add a new option, --mark-tags, which will output mark identifiers with each tag object. This improves the incremental export story with --export-marks since it will allow us to record that annotated tags have been exported, and it is also needed as a step towards supporting nested 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 a1638cfe12ab06bd83068347ee8fc7a522c81e7b
3 files changed +34 -4
Documentation/git-fast-export.txt
+13 -4
@@ -75,11 +75,20 @@ produced incorrect results if you gave these options.
75 Before processing any input, load the marks specified in
76 <file>. The input file must exist, must be readable, and
77 must use the same format as produced by --export-marks.
78 +
79 +--mark-tags::
80 + In addition to labelling blobs and commits with mark ids, also
81 + label tags. This is useful in conjunction with
82 + `--export-marks` and `--import-marks`, and is also useful (and
83 + necessary) for exporting of nested tags. It does not hurt
84 + other cases and would be the default, but many fast-import
85 + frontends are not prepared to accept tags with mark
86 + identifiers.
87 +
79 -Any commits that have already been marked will not be exported again.
80 -If the backend uses a similar --import-marks file, this allows for
81 -incremental bidirectional exporting of the repository by keeping the
82 -marks the same across runs.
88 +Any commits (or tags) that have already been marked will not be
89 +exported again. If the backend uses a similar --import-marks file,
90 +this allows for incremental bidirectional exporting of the repository
91 +by keeping the marks the same across runs.
92
93 --fake-missing-tagger::
94 Some old repositories have tags without a tagger. The
builtin/fast-export.c
+7
@@ -40,6 +40,7 @@ static int no_data;
40 static int full_tree;
41 static int reference_excluded_commits;
42 static int show_original_ids;
43 +static int mark_tags;
44 static struct string_list extra_refs = STRING_LIST_INIT_NODUP;
45 static struct string_list tag_refs = STRING_LIST_INIT_NODUP;
46 static struct refspec refspecs = REFSPEC_INIT_FETCH;
@@ -861,6 +862,10 @@ static void handle_tag(const char *name, struct tag *tag)
862 if (starts_with(name, "refs/tags/"))
863 name += 10;
864 printf("tag %s\n", name);
865 + if (mark_tags) {
866 + mark_next_object(&tag->object);
867 + printf("mark :%"PRIu32"\n", last_idnum);
868 + }
869 if (tagged_mark)
870 printf("from :%d\n", tagged_mark);
871 else
@@ -1165,6 +1170,8 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix)
1170 &reference_excluded_commits, N_("Reference parents which are not in fast-export stream by object id")),
1171 OPT_BOOL(0, "show-original-ids", &show_original_ids,
1172 N_("Show original object ids of blobs/commits")),
1173 + OPT_BOOL(0, "mark-tags", &mark_tags,
1174 + N_("Label tags with mark ids")),
1175
1176 OPT_END()
1177 };
t/t9350-fast-export.sh
+14
@@ -66,6 +66,20 @@ test_expect_success 'fast-export ^muss^{commit} muss' '
66 test_cmp expected actual
67 '
68
69 +test_expect_success 'fast-export --mark-tags ^muss^{commit} muss' '
70 + git fast-export --mark-tags --tag-of-filtered-object=rewrite ^muss^{commit} muss >actual &&
71 + cat >expected <<-EOF &&
72 + tag muss
73 + mark :1
74 + from $(git rev-parse --verify muss^{commit})
75 + $(git cat-file tag muss | grep tagger)
76 + data 9
77 + valentin
78 +
79 + EOF
80 + test_cmp expected actual
81 +'
82 +
83 test_expect_success 'fast-export master~2..master' '
84
85 git fast-export master~2..master >actual &&