repack: move `finish_pack_objects_cmd()` out of the builtin

In a similar spirit as the previous commit(s), now that the function `finish_pack_objects_cmd()` has no explicit dependencies within the repack builtin, let's extract it. This prepares us to extract the remaining two functions within the repack builtin that explicitly write packfiles, which are `write_cruft_pack()` and `write_filtered_pack()`, which will be done in the future commits. Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Taylor Blau committed Oct 15, 2025 at 18:29 UTC fa0787a6cc1d8e7ef1e2e8398bdc13b987c61d69
3 files changed +38 -33
builtin/repack.c
-33
@@ -107,39 +107,6 @@ static int repack_config(const char *var, const char *value,
107 return git_default_config(var, value, ctx, cb);
108 }
109
110 -static int finish_pack_objects_cmd(const struct git_hash_algo *algop,
111 - const struct write_pack_opts *opts,
112 - struct child_process *cmd,
113 - struct string_list *names)
114 -{
115 - FILE *out;
116 - bool local = write_pack_opts_is_local(opts);
117 - struct strbuf line = STRBUF_INIT;
118 -
119 - out = xfdopen(cmd->out, "r");
120 - while (strbuf_getline_lf(&line, out) != EOF) {
121 - struct string_list_item *item;
122 -
123 - if (line.len != algop->hexsz)
124 - die(_("repack: Expecting full hex object ID lines only "
125 - "from pack-objects."));
126 - /*
127 - * Avoid putting packs written outside of the repository in the
128 - * list of names.
129 - */
130 - if (local) {
131 - item = string_list_append(names, line.buf);
132 - item->util = generated_pack_populate(line.buf,
133 - opts->packtmp);
134 - }
135 - }
136 - fclose(out);
137 -
138 - strbuf_release(&line);
139 -
140 - return finish_command(cmd);
141 -}
142 -
110 static int write_filtered_pack(const struct write_pack_opts *opts,
111 struct existing_packs *existing,
112 struct string_list *names)
repack.c
+33
@@ -82,6 +82,39 @@ bool write_pack_opts_is_local(const struct write_pack_opts *opts)
82 return starts_with(opts->destination, opts->packdir);
83 }
84
85 +int finish_pack_objects_cmd(const struct git_hash_algo *algop,
86 + const struct write_pack_opts *opts,
87 + struct child_process *cmd,
88 + struct string_list *names)
89 +{
90 + FILE *out;
91 + bool local = write_pack_opts_is_local(opts);
92 + struct strbuf line = STRBUF_INIT;
93 +
94 + out = xfdopen(cmd->out, "r");
95 + while (strbuf_getline_lf(&line, out) != EOF) {
96 + struct string_list_item *item;
97 +
98 + if (line.len != algop->hexsz)
99 + die(_("repack: Expecting full hex object ID lines only "
100 + "from pack-objects."));
101 + /*
102 + * Avoid putting packs written outside of the repository in the
103 + * list of names.
104 + */
105 + if (local) {
106 + item = string_list_append(names, line.buf);
107 + item->util = generated_pack_populate(line.buf,
108 + opts->packtmp);
109 + }
110 + }
111 + fclose(out);
112 +
113 + strbuf_release(&line);
114 +
115 + return finish_command(cmd);
116 +}
117 +
118 #define DELETE_PACK 1
119 #define RETAIN_PACK 2
120
repack.h
+5
@@ -42,6 +42,11 @@ struct write_pack_opts {
42 const char *write_pack_opts_pack_prefix(const struct write_pack_opts *opts);
43 bool write_pack_opts_is_local(const struct write_pack_opts *opts);
44
45 +int finish_pack_objects_cmd(const struct git_hash_algo *algop,
46 + const struct write_pack_opts *opts,
47 + struct child_process *cmd,
48 + struct string_list *names);
49 +
50 struct repository;
51 struct packed_git;
52