repack-promisor: extract function to finalize repacking

We're about to add a second caller that wants to finalize repacking of promisor objects. Split out the function which does this to prepare for that. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Jan 5, 2026 at 14:16 UTC dd8c4e12c2da850d67849ccfc221ee1dbf87ce55
1 file changed +39 -30
repack-promisor.c
+39 -30
@@ -34,39 +34,17 @@ static int write_oid(const struct object_id *oid,
34 return 0;
35 }
36
37 -void repack_promisor_objects(struct repository *repo,
38 - const struct pack_objects_args *args,
39 - struct string_list *names, const char *packtmp)
37 +static void finish_repacking_promisor_objects(struct repository *repo,
38 + struct child_process *cmd,
39 + struct string_list *names,
40 + const char *packtmp)
41 {
41 - struct write_oid_context ctx;
42 - struct child_process cmd = CHILD_PROCESS_INIT;
43 - FILE *out;
42 struct strbuf line = STRBUF_INIT;
43 + FILE *out;
44
46 - prepare_pack_objects(&cmd, args, packtmp);
47 - cmd.in = -1;
48 -
49 - /*
50 - * NEEDSWORK: Giving pack-objects only the OIDs without any ordering
51 - * hints may result in suboptimal deltas in the resulting pack. See if
52 - * the OIDs can be sent with fake paths such that pack-objects can use a
53 - * {type -> existing pack order} ordering when computing deltas instead
54 - * of a {type -> size} ordering, which may produce better deltas.
55 - */
56 - ctx.cmd = &cmd;
57 - ctx.algop = repo->hash_algo;
58 - for_each_packed_object(repo, write_oid, &ctx,
59 - FOR_EACH_OBJECT_PROMISOR_ONLY);
60 -
61 - if (cmd.in == -1) {
62 - /* No packed objects; cmd was never started */
63 - child_process_clear(&cmd);
64 - return;
65 - }
66 -
67 - close(cmd.in);
45 + close(cmd->in);
46
69 - out = xfdopen(cmd.out, "r");
47 + out = xfdopen(cmd->out, "r");
48 while (strbuf_getline_lf(&line, out) != EOF) {
49 struct string_list_item *item;
50 char *promisor_name;
@@ -96,7 +74,38 @@ void repack_promisor_objects(struct repository *repo,
74 }
75
76 fclose(out);
99 - if (finish_command(&cmd))
77 + if (finish_command(cmd))
78 die(_("could not finish pack-objects to repack promisor objects"));
79 strbuf_release(&line);
80 }
81 +
82 +void repack_promisor_objects(struct repository *repo,
83 + const struct pack_objects_args *args,
84 + struct string_list *names, const char *packtmp)
85 +{
86 + struct write_oid_context ctx;
87 + struct child_process cmd = CHILD_PROCESS_INIT;
88 +
89 + prepare_pack_objects(&cmd, args, packtmp);
90 + cmd.in = -1;
91 +
92 + /*
93 + * NEEDSWORK: Giving pack-objects only the OIDs without any ordering
94 + * hints may result in suboptimal deltas in the resulting pack. See if
95 + * the OIDs can be sent with fake paths such that pack-objects can use a
96 + * {type -> existing pack order} ordering when computing deltas instead
97 + * of a {type -> size} ordering, which may produce better deltas.
98 + */
99 + ctx.cmd = &cmd;
100 + ctx.algop = repo->hash_algo;
101 + for_each_packed_object(repo, write_oid, &ctx,
102 + FOR_EACH_OBJECT_PROMISOR_ONLY);
103 +
104 + if (cmd.in == -1) {
105 + /* No packed objects; cmd was never started */
106 + child_process_clear(&cmd);
107 + return;
108 + }
109 +
110 + finish_repacking_promisor_objects(repo, &cmd, names, packtmp);
111 +}