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>
maint
Antoine Pelisse 2013-04-06 19:04:31 +02:00 committed by Junio C Hamano
parent 6ff8d4e748
commit c4458ecdc5
2 changed files with 9 additions and 4 deletions

View File

@ -66,6 +66,8 @@ produced incorrect results if you gave these options.
incremental runs. As <file> is only opened and truncated incremental runs. As <file> is only opened and truncated
at completion, the same path can also be safely given to at completion, the same path can also be safely given to
\--import-marks. \--import-marks.
The file will not be written if no new object has been
marked/exported.


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

View File

@ -618,9 +618,12 @@ static void import_marks(char *input_file)
|| *mark_end != ' ' || get_sha1(mark_end + 1, sha1)) || *mark_end != ' ' || get_sha1(mark_end + 1, sha1))
die("corrupt mark line: %s", line); die("corrupt mark line: %s", line);


if (last_idnum < mark)
last_idnum = mark;

object = parse_object(sha1); object = parse_object(sha1);
if (!object) if (!object)
die ("Could not read blob %s", sha1_to_hex(sha1)); continue;


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


mark_object(object, mark); mark_object(object, mark);
if (last_idnum < mark)
last_idnum = mark;


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


if (import_filename) if (import_filename)
import_marks(import_filename); import_marks(import_filename);
lastimportid = last_idnum;


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


handle_tags_and_duplicates(&extra_refs); handle_tags_and_duplicates(&extra_refs);


if (export_filename) if (export_filename && lastimportid != last_idnum)
export_marks(export_filename); export_marks(export_filename);


if (use_done_feature) if (use_done_feature)