]> git.ipfire.org Git - thirdparty/git.git/commitdiff
fast-export: when using paths, avoid corrupt stream with non-existent mark
authorElijah Newren <newren@gmail.com>
Fri, 16 Nov 2018 07:59:52 +0000 (23:59 -0800)
committerJunio C Hamano <gitster@pobox.com>
Sat, 17 Nov 2018 09:43:51 +0000 (18:43 +0900)
If file paths are specified to fast-export and multiple refs point to a
commit that does not touch any of the relevant file paths, then
fast-export can hit problems.  fast-export has a list of additional refs
that it needs to explicitly set after exporting all blobs and commits,
and when it tries to get_object_mark() on the relevant commit, it can
get a mark of 0, i.e. "not found", because the commit in question did
not touch the relevant paths and thus was not exported.  Trying to
import a stream with a mark corresponding to an unexported object will
cause fast-import to crash.

Avoid this problem by taking the commit the ref points to and finding an
ancestor of it that was exported, and make the ref point to that commit
instead.

Signed-off-by: Elijah Newren <newren@gmail.com>
Acked-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/fast-export.c
t/t9350-fast-export.sh

index 43e98a38a8f81561853a0357efbedfd3552fc21c..227488ae843f815ef0fc0be380d60d3ecd6c41bf 100644 (file)
@@ -901,7 +901,18 @@ static void handle_tags_and_duplicates(void)
                        if (anonymize)
                                name = anonymize_refname(name);
                        /* create refs pointing to already seen commits */
-                       commit = (struct commit *)object;
+                       commit = rewrite_commit((struct commit *)object);
+                       if (!commit) {
+                               /*
+                                * Neither this object nor any of its
+                                * ancestors touch any relevant paths, so
+                                * it has been filtered to nothing.  Delete
+                                * it.
+                                */
+                               printf("reset %s\nfrom %s\n\n",
+                                      name, oid_to_hex(&null_oid));
+                               continue;
+                       }
                        printf("reset %s\nfrom :%d\n\n", name,
                               get_object_mark(&commit->object));
                        show_progress();
index 3400ebeb519efb50cd2a37d7c30d0d92f7c30852..299120ba706d9663649785b8713ab340457e1bc9 100755 (executable)
@@ -382,6 +382,26 @@ test_expect_success 'path limiting with import-marks does not lose unmodified fi
        grep file0 actual
 '
 
+test_expect_success 'avoid corrupt stream with non-existent mark' '
+       test_create_repo avoid_non_existent_mark &&
+       (
+               cd avoid_non_existent_mark &&
+
+               test_commit important-path &&
+
+               test_commit ignored &&
+
+               git branch A &&
+               git branch B &&
+
+               echo foo >>important-path.t &&
+               git add important-path.t &&
+               test_commit more changes &&
+
+               git fast-export --all -- important-path.t | git fast-import --force
+       )
+'
+
 test_expect_success 'full-tree re-shows unmodified files'        '
        git checkout -f simple &&
        git fast-export --full-tree simple >actual &&