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 <newren@gmail.com> Acked-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Elijah Newren committed
Nov 15, 2018 at 23:59 UTC
f129c4275c81e908c1d14d1ac1e72f720e2aebb7
1 file changed
+22
-15
builtin/fast-export.c
+22
-15
@@ -187,6 +187,22 @@ static int get_object_mark(struct object *object)
187
return ptr_to_mark(decoration);
188
}
189
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
+
206
static void show_progress(void)
207
{
208
static int counter = 0;
@@ -767,21 +783,12 @@ static void handle_tag(const char *name, struct tag *tag)
783
oid_to_hex(&tag->object.oid),
784
type_name(tagged->type));
785
}
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;
792
}
793
tagged_mark = get_object_mark(&p->object);
794
}