Skip to content

Commit c4458ec

Browse files
apelissegitster
authored andcommitted
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>
1 parent 6ff8d4e commit c4458ec

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

Documentation/git-fast-export.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ produced incorrect results if you gave these options.
6666
incremental runs. As <file> is only opened and truncated
6767
at completion, the same path can also be safely given to
6868
\--import-marks.
69+
The file will not be written if no new object has been
70+
marked/exported.
6971

7072
--import-marks=<file>::
7173
Before processing any input, load the marks specified in

builtin/fast-export.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -618,9 +618,12 @@ static void import_marks(char *input_file)
618618
|| *mark_end != ' ' || get_sha1(mark_end + 1, sha1))
619619
die("corrupt mark line: %s", line);
620620

621+
if (last_idnum < mark)
622+
last_idnum = mark;
623+
621624
object = parse_object(sha1);
622625
if (!object)
623-
die ("Could not read blob %s", sha1_to_hex(sha1));
626+
continue;
624627

625628
if (object->flags & SHOWN)
626629
error("Object %s already has a mark", sha1_to_hex(sha1));
@@ -630,8 +633,6 @@ static void import_marks(char *input_file)
630633
continue;
631634

632635
mark_object(object, mark);
633-
if (last_idnum < mark)
634-
last_idnum = mark;
635636

636637
object->flags |= SHOWN;
637638
}
@@ -645,6 +646,7 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix)
645646
struct string_list extra_refs = STRING_LIST_INIT_NODUP;
646647
struct commit *commit;
647648
char *export_filename = NULL, *import_filename = NULL;
649+
uint32_t lastimportid;
648650
struct option options[] = {
649651
OPT_INTEGER(0, "progress", &progress,
650652
N_("show progress after <n> objects")),
@@ -688,6 +690,7 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix)
688690

689691
if (import_filename)
690692
import_marks(import_filename);
693+
lastimportid = last_idnum;
691694

692695
if (import_filename && revs.prune_data.nr)
693696
full_tree = 1;
@@ -710,7 +713,7 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix)
710713

711714
handle_tags_and_duplicates(&extra_refs);
712715

713-
if (export_filename)
716+
if (export_filename && lastimportid != last_idnum)
714717
export_marks(export_filename);
715718

716719
if (use_done_feature)

0 commit comments

Comments
 (0)