Skip to content

Commit 63a8be6

Browse files
derrickstoleegitster
authored andcommitted
commit-graph: extract fill_oids_from_commit_hex()
The write_commit_graph() method is too complex, so we are extracting methods one by one. Extract fill_oids_from_commit_hex() that reads the given commit id list and fille the oid list in the context. Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d83160e commit 63a8be6

File tree

1 file changed

+40
-32
lines changed

1 file changed

+40
-32
lines changed

commit-graph.c

Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -912,6 +912,44 @@ static int fill_oids_from_packs(struct write_commit_graph_context *ctx,
912912
return 0;
913913
}
914914

915+
static void fill_oids_from_commit_hex(struct write_commit_graph_context *ctx,
916+
struct string_list *commit_hex)
917+
{
918+
uint32_t i;
919+
struct strbuf progress_title = STRBUF_INIT;
920+
921+
if (ctx->report_progress) {
922+
strbuf_addf(&progress_title,
923+
Q_("Finding commits for commit graph from %d ref",
924+
"Finding commits for commit graph from %d refs",
925+
commit_hex->nr),
926+
commit_hex->nr);
927+
ctx->progress = start_delayed_progress(
928+
progress_title.buf,
929+
commit_hex->nr);
930+
}
931+
for (i = 0; i < commit_hex->nr; i++) {
932+
const char *end;
933+
struct object_id oid;
934+
struct commit *result;
935+
936+
display_progress(ctx->progress, i + 1);
937+
if (commit_hex->items[i].string &&
938+
parse_oid_hex(commit_hex->items[i].string, &oid, &end))
939+
continue;
940+
941+
result = lookup_commit_reference_gently(ctx->r, &oid, 1);
942+
943+
if (result) {
944+
ALLOC_GROW(ctx->oids.list, ctx->oids.nr + 1, ctx->oids.alloc);
945+
oidcpy(&ctx->oids.list[ctx->oids.nr], &(result->object.oid));
946+
ctx->oids.nr++;
947+
}
948+
}
949+
stop_progress(&ctx->progress);
950+
strbuf_release(&progress_title);
951+
}
952+
915953
int write_commit_graph(const char *obj_dir,
916954
struct string_list *pack_indexes,
917955
struct string_list *commit_hex,
@@ -965,38 +1003,8 @@ int write_commit_graph(const char *obj_dir,
9651003
goto cleanup;
9661004
}
9671005

968-
if (commit_hex) {
969-
if (ctx->report_progress) {
970-
strbuf_addf(&progress_title,
971-
Q_("Finding commits for commit graph from %d ref",
972-
"Finding commits for commit graph from %d refs",
973-
commit_hex->nr),
974-
commit_hex->nr);
975-
ctx->progress = start_delayed_progress(
976-
progress_title.buf,
977-
commit_hex->nr);
978-
}
979-
for (i = 0; i < commit_hex->nr; i++) {
980-
const char *end;
981-
struct object_id oid;
982-
struct commit *result;
983-
984-
display_progress(ctx->progress, i + 1);
985-
if (commit_hex->items[i].string &&
986-
parse_oid_hex(commit_hex->items[i].string, &oid, &end))
987-
continue;
988-
989-
result = lookup_commit_reference_gently(ctx->r, &oid, 1);
990-
991-
if (result) {
992-
ALLOC_GROW(ctx->oids.list, ctx->oids.nr + 1, ctx->oids.alloc);
993-
oidcpy(&ctx->oids.list[ctx->oids.nr], &(result->object.oid));
994-
ctx->oids.nr++;
995-
}
996-
}
997-
stop_progress(&ctx->progress);
998-
strbuf_reset(&progress_title);
999-
}
1006+
if (commit_hex)
1007+
fill_oids_from_commit_hex(ctx, commit_hex);
10001008

10011009
if (!pack_indexes && !commit_hex) {
10021010
if (ctx->report_progress)

0 commit comments

Comments
 (0)