fast-export: Allow pruned-references in mark file

fast-export can fail because of some pruned-reference when importing a mark file. The problem happens in the following scenario: $ git fast-export --export-marks=MARKS master (rewrite master) $ git prune $ git fast-export --import-marks=MARKS master This might fail if some references have been removed by prune because some marks will refer to no longer existing commits. git-fast-export will not need these objects anyway as they were no longer reachable. We still need to update last_numid so we don't change the mapping between marks and objects for remote-helpers. Unfortunately, the mark file should not be rewritten without lost marks if no new objects has been exported, as we could lose track of the last last_numid. Signed-off-by: Antoine Pelisse <apelisse@gmail.com> Reviewed-by: Felipe Contreras <felipe.contreras@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Antoine Pelisse committed Apr 6, 2013 at 19:04 UTC c4458ecdc565fb63cc3247bd1e2d7525d9d6d2fa
2 files changed +9 -4
Documentation/git-fast-export.txt
+2
@@ -66,6 +66,8 @@ produced incorrect results if you gave these options.
66 incremental runs. As <file> is only opened and truncated
67 at completion, the same path can also be safely given to
68 \--import-marks.
69 + The file will not be written if no new object has been
70 + marked/exported.
71
72 --import-marks=<file>::
73 Before processing any input, load the marks specified in
builtin/fast-export.c
+7 -4
@@ -618,9 +618,12 @@ static void import_marks(char *input_file)
618 || *mark_end != ' ' || get_sha1(mark_end + 1, sha1))
619 die("corrupt mark line: %s", line);
620
621 + if (last_idnum < mark)
622 + last_idnum = mark;
623 +
624 object = parse_object(sha1);
625 if (!object)
623 - die ("Could not read blob %s", sha1_to_hex(sha1));
626 + continue;
627
628 if (object->flags & SHOWN)
629 error("Object %s already has a mark", sha1_to_hex(sha1));
@@ -630,8 +633,6 @@ static void import_marks(char *input_file)
633 continue;
634
635 mark_object(object, mark);
633 - if (last_idnum < mark)
634 - last_idnum = mark;
636
637 object->flags |= SHOWN;
638 }
@@ -645,6 +646,7 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix)
646 struct string_list extra_refs = STRING_LIST_INIT_NODUP;
647 struct commit *commit;
648 char *export_filename = NULL, *import_filename = NULL;
649 + uint32_t lastimportid;
650 struct option options[] = {
651 OPT_INTEGER(0, "progress", &progress,
652 N_("show progress after <n> objects")),
@@ -688,6 +690,7 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix)
690
691 if (import_filename)
692 import_marks(import_filename);
693 + lastimportid = last_idnum;
694
695 if (import_filename && revs.prune_data.nr)
696 full_tree = 1;
@@ -710,7 +713,7 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix)
713
714 handle_tags_and_duplicates(&extra_refs);
715
713 - if (export_filename)
716 + if (export_filename && lastimportid != last_idnum)
717 export_marks(export_filename);
718
719 if (use_done_feature)