Skip to content

Commit 1f30c90

Browse files
newrengitster
authored andcommitted
fast-export: avoid dying when filtering by paths and old tags exist
If --tag-of-filtered-object=rewrite is specified along with a set of paths to limit what is exported, then any tags pointing to old commits that do not contain any of those specified paths cause problems. Since the old tagged commit is not exported, fast-export attempts to rewrite such tags to an ancestor commit which was exported. If no such commit exists, then fast-export currently die()s. Five years after the tag rewriting logic was added to fast-export (see commit 2d8ad46, "fast-export: Add a --tag-of-filtered-object option for newly dangling tags", 2009-06-25), fast-import gained the ability to delete refs (see commit 4ee1b22, "fast-import: add support to delete refs", 2014-04-20), so now we do have a valid option to rewrite the tag to. Delete these tags instead of dying. Signed-off-by: Elijah Newren <[email protected]> Acked-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b93b81e commit 1f30c90

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

builtin/fast-export.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -775,9 +775,12 @@ static void handle_tag(const char *name, struct tag *tag)
775775
break;
776776
if (!(p->object.flags & TREESAME))
777777
break;
778-
if (!p->parents)
779-
die("can't find replacement commit for tag %s",
780-
oid_to_hex(&tag->object.oid));
778+
if (!p->parents) {
779+
printf("reset %s\nfrom %s\n\n",
780+
name, oid_to_hex(&null_oid));
781+
free(buf);
782+
return;
783+
}
781784
p = p->parents->item;
782785
}
783786
tagged_mark = get_object_mark(&p->object);

t/t9350-fast-export.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,22 @@ test_expect_success 'rewriting tag of filtered out object' '
325325
)
326326
'
327327

328+
test_expect_success 'rewrite tag predating pathspecs to nothing' '
329+
test_create_repo rewrite_tag_predating_pathspecs &&
330+
(
331+
cd rewrite_tag_predating_pathspecs &&
332+
333+
test_commit initial &&
334+
335+
git tag -a -m "Some old tag" v0.0.0.0.0.0.1 &&
336+
337+
test_commit bar &&
338+
339+
git fast-export --tag-of-filtered-object=rewrite --all -- bar.t >output &&
340+
grep from.$ZERO_OID output
341+
)
342+
'
343+
328344
cat > limit-by-paths/expected << EOF
329345
blob
330346
mark :1

0 commit comments

Comments
 (0)