Skip to content

Commit d83160e

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

File tree

1 file changed

+47
-36
lines changed

1 file changed

+47
-36
lines changed

commit-graph.c

Lines changed: 47 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -867,6 +867,51 @@ int write_commit_graph_reachable(const char *obj_dir, unsigned int flags)
867867
return result;
868868
}
869869

870+
static int fill_oids_from_packs(struct write_commit_graph_context *ctx,
871+
struct string_list *pack_indexes)
872+
{
873+
uint32_t i;
874+
struct strbuf progress_title = STRBUF_INIT;
875+
struct strbuf packname = STRBUF_INIT;
876+
int dirlen;
877+
878+
strbuf_addf(&packname, "%s/pack/", ctx->obj_dir);
879+
dirlen = packname.len;
880+
if (ctx->report_progress) {
881+
strbuf_addf(&progress_title,
882+
Q_("Finding commits for commit graph in %d pack",
883+
"Finding commits for commit graph in %d packs",
884+
pack_indexes->nr),
885+
pack_indexes->nr);
886+
ctx->progress = start_delayed_progress(progress_title.buf, 0);
887+
ctx->progress_done = 0;
888+
}
889+
for (i = 0; i < pack_indexes->nr; i++) {
890+
struct packed_git *p;
891+
strbuf_setlen(&packname, dirlen);
892+
strbuf_addstr(&packname, pack_indexes->items[i].string);
893+
p = add_packed_git(packname.buf, packname.len, 1);
894+
if (!p) {
895+
error(_("error adding pack %s"), packname.buf);
896+
return 1;
897+
}
898+
if (open_pack_index(p)) {
899+
error(_("error opening index for %s"), packname.buf);
900+
return 1;
901+
}
902+
for_each_object_in_pack(p, add_packed_commits, ctx,
903+
FOR_EACH_OBJECT_PACK_ORDER);
904+
close_pack(p);
905+
free(p);
906+
}
907+
908+
stop_progress(&ctx->progress);
909+
strbuf_reset(&progress_title);
910+
strbuf_release(&packname);
911+
912+
return 0;
913+
}
914+
870915
int write_commit_graph(const char *obj_dir,
871916
struct string_list *pack_indexes,
872917
struct string_list *commit_hex,
@@ -916,42 +961,8 @@ int write_commit_graph(const char *obj_dir,
916961
}
917962

918963
if (pack_indexes) {
919-
struct strbuf packname = STRBUF_INIT;
920-
int dirlen;
921-
strbuf_addf(&packname, "%s/pack/", obj_dir);
922-
dirlen = packname.len;
923-
if (ctx->report_progress) {
924-
strbuf_addf(&progress_title,
925-
Q_("Finding commits for commit graph in %d pack",
926-
"Finding commits for commit graph in %d packs",
927-
pack_indexes->nr),
928-
pack_indexes->nr);
929-
ctx->progress = start_delayed_progress(progress_title.buf, 0);
930-
ctx->progress_done = 0;
931-
}
932-
for (i = 0; i < pack_indexes->nr; i++) {
933-
struct packed_git *p;
934-
strbuf_setlen(&packname, dirlen);
935-
strbuf_addstr(&packname, pack_indexes->items[i].string);
936-
p = add_packed_git(packname.buf, packname.len, 1);
937-
if (!p) {
938-
error(_("error adding pack %s"), packname.buf);
939-
res = 1;
940-
goto cleanup;
941-
}
942-
if (open_pack_index(p)) {
943-
error(_("error opening index for %s"), packname.buf);
944-
res = 1;
945-
goto cleanup;
946-
}
947-
for_each_object_in_pack(p, add_packed_commits, ctx,
948-
FOR_EACH_OBJECT_PACK_ORDER);
949-
close_pack(p);
950-
free(p);
951-
}
952-
stop_progress(&ctx->progress);
953-
strbuf_reset(&progress_title);
954-
strbuf_release(&packname);
964+
if ((res = fill_oids_from_packs(ctx, pack_indexes)))
965+
goto cleanup;
955966
}
956967

957968
if (commit_hex) {

0 commit comments

Comments
 (0)