commit-graph: extract fill_oids_from_commit_hex()

The write_commit_graph() method is too complex, so we are extracting helper functions 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 <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Derrick Stolee committed Jun 12, 2019 at 06:29 UTC 4c9efe850d75115a6deedd57072f1d7383bc03da
1 file changed +40 -32
commit-graph.c
+40 -32
@@ -912,6 +912,44 @@ static int fill_oids_from_packs(struct write_commit_graph_context *ctx,
912 return 0;
913 }
914
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 +
953 int write_commit_graph(const char *obj_dir,
954 struct string_list *pack_indexes,
955 struct string_list *commit_hex,
@@ -965,38 +1003,8 @@ int write_commit_graph(const char *obj_dir,
1003 goto cleanup;
1004 }
1005
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);
1008
1009 if (!pack_indexes && !commit_hex) {
1010 if (ctx->report_progress)