]> git.ipfire.org Git - thirdparty/git.git/commitdiff
repack: move `finish_pack_objects_cmd()` out of the builtin
authorTaylor Blau <me@ttaylorr.com>
Wed, 15 Oct 2025 22:29:30 +0000 (18:29 -0400)
committerJunio C Hamano <gitster@pobox.com>
Thu, 16 Oct 2025 17:08:56 +0000 (10:08 -0700)
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>
builtin/repack.c
repack.c
repack.h

index 5f382aaf196c3e77410957094204e1bf2714f76a..71abcfa0b7a78a6ba5a36c0895cec3b521a97847 100644 (file)
@@ -107,39 +107,6 @@ static int repack_config(const char *var, const char *value,
        return git_default_config(var, value, ctx, cb);
 }
 
-static int finish_pack_objects_cmd(const struct git_hash_algo *algop,
-                                  const struct write_pack_opts *opts,
-                                  struct child_process *cmd,
-                                  struct string_list *names)
-{
-       FILE *out;
-       bool local = write_pack_opts_is_local(opts);
-       struct strbuf line = STRBUF_INIT;
-
-       out = xfdopen(cmd->out, "r");
-       while (strbuf_getline_lf(&line, out) != EOF) {
-               struct string_list_item *item;
-
-               if (line.len != algop->hexsz)
-                       die(_("repack: Expecting full hex object ID lines only "
-                             "from pack-objects."));
-               /*
-                * Avoid putting packs written outside of the repository in the
-                * list of names.
-                */
-               if (local) {
-                       item = string_list_append(names, line.buf);
-                       item->util = generated_pack_populate(line.buf,
-                                                            opts->packtmp);
-               }
-       }
-       fclose(out);
-
-       strbuf_release(&line);
-
-       return finish_command(cmd);
-}
-
 static int write_filtered_pack(const struct write_pack_opts *opts,
                               struct existing_packs *existing,
                               struct string_list *names)
index d2ee9f2460f3a3de901a2e88da568cc78cacb8c7..2c478970f3c3decb5b7ecfdd3785004949f8835a 100644 (file)
--- a/repack.c
+++ b/repack.c
@@ -82,6 +82,39 @@ bool write_pack_opts_is_local(const struct write_pack_opts *opts)
        return starts_with(opts->destination, opts->packdir);
 }
 
+int finish_pack_objects_cmd(const struct git_hash_algo *algop,
+                           const struct write_pack_opts *opts,
+                           struct child_process *cmd,
+                           struct string_list *names)
+{
+       FILE *out;
+       bool local = write_pack_opts_is_local(opts);
+       struct strbuf line = STRBUF_INIT;
+
+       out = xfdopen(cmd->out, "r");
+       while (strbuf_getline_lf(&line, out) != EOF) {
+               struct string_list_item *item;
+
+               if (line.len != algop->hexsz)
+                       die(_("repack: Expecting full hex object ID lines only "
+                             "from pack-objects."));
+               /*
+                * Avoid putting packs written outside of the repository in the
+                * list of names.
+                */
+               if (local) {
+                       item = string_list_append(names, line.buf);
+                       item->util = generated_pack_populate(line.buf,
+                                                            opts->packtmp);
+               }
+       }
+       fclose(out);
+
+       strbuf_release(&line);
+
+       return finish_command(cmd);
+}
+
 #define DELETE_PACK 1
 #define RETAIN_PACK 2
 
index 26d1954ae28dddf5036780684db4a689e545504e..3244f601e2d7d0e379f12c91e337949ea6c25628 100644 (file)
--- a/repack.h
+++ b/repack.h
@@ -42,6 +42,11 @@ struct write_pack_opts {
 const char *write_pack_opts_pack_prefix(const struct write_pack_opts *opts);
 bool write_pack_opts_is_local(const struct write_pack_opts *opts);
 
+int finish_pack_objects_cmd(const struct git_hash_algo *algop,
+                           const struct write_pack_opts *opts,
+                           struct child_process *cmd,
+                           struct string_list *names);
+
 struct repository;
 struct packed_git;