Skip to content

Commit f129c42

Browse files
newrengitster
authored andcommitted
fast-export: move commit rewriting logic into a function for reuse
Logic to replace a filtered commit with an unfiltered ancestor is useful elsewhere; put it into a function we can call. Signed-off-by: Elijah Newren <[email protected]> Acked-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1f30c90 commit f129c42

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

builtin/fast-export.c

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,22 @@ static int get_object_mark(struct object *object)
187187
return ptr_to_mark(decoration);
188188
}
189189

190+
static struct commit *rewrite_commit(struct commit *p)
191+
{
192+
for (;;) {
193+
if (p->parents && p->parents->next)
194+
break;
195+
if (p->object.flags & UNINTERESTING)
196+
break;
197+
if (!(p->object.flags & TREESAME))
198+
break;
199+
if (!p->parents)
200+
return NULL;
201+
p = p->parents->item;
202+
}
203+
return p;
204+
}
205+
190206
static void show_progress(void)
191207
{
192208
static int counter = 0;
@@ -767,21 +783,12 @@ static void handle_tag(const char *name, struct tag *tag)
767783
oid_to_hex(&tag->object.oid),
768784
type_name(tagged->type));
769785
}
770-
p = (struct commit *)tagged;
771-
for (;;) {
772-
if (p->parents && p->parents->next)
773-
break;
774-
if (p->object.flags & UNINTERESTING)
775-
break;
776-
if (!(p->object.flags & TREESAME))
777-
break;
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-
}
784-
p = p->parents->item;
786+
p = rewrite_commit((struct commit *)tagged);
787+
if (!p) {
788+
printf("reset %s\nfrom %s\n\n",
789+
name, oid_to_hex(&null_oid));
790+
free(buf);
791+
return;
785792
}
786793
tagged_mark = get_object_mark(&p->object);
787794
}

0 commit comments

Comments
 (0)