]> git.ipfire.org Git - thirdparty/git.git/commitdiff
repack: move `finish_pack_objects_cmd()` out of the builtin
authorTaylor Blau <me@ttaylorr.com>
Sun, 28 Sep 2025 22:10:19 +0000 (18:10 -0400)
committerJunio C Hamano <gitster@pobox.com>
Mon, 29 Sep 2025 16:31:25 +0000 (09:31 -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 8db95305c8db6d2c9f73a38b271d7d01242d050f..836a00660729c68465f05516fbc720a8b234be68 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,
-                                  struct write_pack_opts *opts,
-                                  struct child_process *cmd,
-                                  struct string_list *names)
-{
-       FILE *out;
-       int 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(struct write_pack_opts *opts,
                               struct existing_packs *existing,
                               struct string_list *names)
index 7af297ae48aa163698e02990ca5dfe805f3a79dd..8a0e4789fadad57eabfc693d7a7c05f86c74ad70 100644 (file)
--- a/repack.c
+++ b/repack.c
@@ -83,6 +83,39 @@ int write_pack_opts_is_local(struct write_pack_opts *opts)
        return skip_prefix(opts->destination, opts->packdir, &scratch);
 }
 
+int finish_pack_objects_cmd(const struct git_hash_algo *algop,
+                           struct write_pack_opts *opts,
+                           struct child_process *cmd,
+                           struct string_list *names)
+{
+       FILE *out;
+       int 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 16f2de2ea9a56cfa8421bdd1ffa3b1e8c789e6d4..9351293233c2bf9f443ef729d93556f1067ada6c 100644 (file)
--- a/repack.h
+++ b/repack.h
@@ -42,6 +42,11 @@ struct write_pack_opts {
 const char *write_pack_opts_pack_prefix(struct write_pack_opts *opts);
 int write_pack_opts_is_local(struct write_pack_opts *opts);
 
+int finish_pack_objects_cmd(const struct git_hash_algo *algop,
+                           struct write_pack_opts *opts,
+                           struct child_process *cmd,
+                           struct string_list *names);
+
 struct repository;
 struct packed_git;