@matheusbsbs / matheus-bagliano / commits / 2d8ad46919
Fork 0

fast-export: Add a --tag-of-filtered-object option for newly dangling tags

When providing a list of paths to limit what is exported, the object that a tag points to can be filtered out entirely. This new switch allows the user to specify what should happen to the tag in such a case. The default action, 'abort' will exit with an error message. With 'drop', the tag will simply be omitted from the output. With 'rewrite', if the object tagged was a commit, the tag will be modified to tag an alternate commit. The alternate commit is determined by treating the original commit as the "parent" of the tag and then using the parent rewriting algorithm of the revision traversal machinery (related to the "--parents" option of "git rev-list") Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Elijah Newren committed Jun 25, 2009 at 22:48 UTC 2d8ad46919213ebbd7bb72eb5b56cca8cc3ae07f
2 files changed +68 -2
Documentation/git-fast-export.txt
+11
@@ -36,6 +36,17 @@ when encountering a signed tag. With 'strip', the tags will be made
36 unsigned, with 'verbatim', they will be silently exported
37 and with 'warn', they will be exported, but you will see a warning.
38
39 +--tag-of-filtered-object=(abort|drop|rewrite)::
40 + Specify how to handle tags whose tagged objectis filtered out.
41 + Since revisions and files to export can be limited by path,
42 + tagged objects may be filtered completely.
43 ++
44 +When asking to 'abort' (which is the default), this program will die
45 +when encountering such a tag. With 'drop' it will omit such tags from
46 +the output. With 'rewrite', if the tagged object is a commit, it will
47 +rewrite the tag to tag an ancestor commit (via parent rewriting; see
48 +linkgit:git-rev-list[1])
49 +
50 -M::
51 -C::
52 Perform move and/or copy detection, as described in the
builtin-fast-export.c
+57 -2
@@ -23,7 +23,8 @@ static const char *fast_export_usage[] = {
23 };
24
25 static int progress;
26 -static enum { VERBATIM, WARN, STRIP, ABORT } signed_tag_mode = ABORT;
26 +static enum { ABORT, VERBATIM, WARN, STRIP } signed_tag_mode = ABORT;
27 +static enum { ERROR, DROP, REWRITE } tag_of_filtered_mode = ABORT;
28 static int fake_missing_tagger;
29
30 static int parse_opt_signed_tag_mode(const struct option *opt,
@@ -42,6 +43,20 @@ static int parse_opt_signed_tag_mode(const struct option *opt,
43 return 0;
44 }
45
46 +static int parse_opt_tag_of_filtered_mode(const struct option *opt,
47 + const char *arg, int unset)
48 +{
49 + if (unset || !strcmp(arg, "abort"))
50 + tag_of_filtered_mode = ABORT;
51 + else if (!strcmp(arg, "drop"))
52 + tag_of_filtered_mode = DROP;
53 + else if (!strcmp(arg, "rewrite"))
54 + tag_of_filtered_mode = REWRITE;
55 + else
56 + return error("Unknown tag-of-filtered mode: %s", arg);
57 + return 0;
58 +}
59 +
60 static struct decoration idnums;
61 static uint32_t last_idnum;
62
@@ -290,6 +305,8 @@ static void handle_tag(const char *name, struct tag *tag)
305 const char *tagger, *tagger_end, *message;
306 size_t message_size = 0;
307 struct object *tagged;
308 + int tagged_mark;
309 + struct commit *p;
310
311 /* Trees have no identifer in fast-export output, thus we have no way
312 * to output tags of trees, tags of tags of trees, etc. Simply omit
@@ -348,10 +365,45 @@ static void handle_tag(const char *name, struct tag *tag)
365 }
366 }
367
368 + /* handle tag->tagged having been filtered out due to paths specified */
369 + tagged = tag->tagged;
370 + tagged_mark = get_object_mark(tagged);
371 + if (!tagged_mark) {
372 + switch(tag_of_filtered_mode) {
373 + case ABORT:
374 + die ("Tag %s tags unexported object; use "
375 + "--tag-of-filtered-object=<mode> to handle it.",
376 + sha1_to_hex(tag->object.sha1));
377 + case DROP:
378 + /* Ignore this tag altogether */
379 + return;
380 + case REWRITE:
381 + if (tagged->type != OBJ_COMMIT) {
382 + die ("Tag %s tags unexported %s!",
383 + sha1_to_hex(tag->object.sha1),
384 + typename(tagged->type));
385 + }
386 + p = (struct commit *)tagged;
387 + for (;;) {
388 + if (p->parents && p->parents->next)
389 + break;
390 + if (p->object.flags & UNINTERESTING)
391 + break;
392 + if (!(p->object.flags & TREESAME))
393 + break;
394 + if (!p->parents)
395 + die ("Can't find replacement commit for tag %s\n",
396 + sha1_to_hex(tag->object.sha1));
397 + p = p->parents->item;
398 + }
399 + tagged_mark = get_object_mark(&p->object);
400 + }
401 + }
402 +
403 if (!prefixcmp(name, "refs/tags/"))
404 name += 10;
405 printf("tag %s\nfrom :%d\n%.*s%sdata %d\n%.*s\n",
354 - name, get_object_mark(tag->tagged),
406 + name, tagged_mark,
407 (int)(tagger_end - tagger), tagger,
408 tagger == tagger_end ? "" : "\n",
409 (int)message_size, (int)message_size, message ? message : "");
@@ -513,6 +565,9 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix)
565 OPT_CALLBACK(0, "signed-tags", &signed_tag_mode, "mode",
566 "select handling of signed tags",
567 parse_opt_signed_tag_mode),
568 + OPT_CALLBACK(0, "tag-of-filtered-object", &tag_of_filtered_mode, "mode",
569 + "select handling of tags that tag filtered objects",
570 + parse_opt_tag_of_filtered_mode),
571 OPT_STRING(0, "export-marks", &export_filename, "FILE",
572 "Dump marks to this file"),
573 OPT_STRING(0, "import-marks", &import_filename, "FILE",