[PATCH 13/49] repack: move 'delta_base_offset' to 'struct pack_objects_args'

Taylor Blau
2025-09-28T22:08:03Z

The static variable 'delta_base_offset' determines whether or not we
pass the "--delta-base-offset" command-line argument when spawning
pack-objects as a child process. Its introduction dates back to when
repack was rewritten in C, all the way back in a1bbc6c017 (repack:
rewrite the shell script in C, 2013-09-15).

'struct pack_objects_args' was introduced much later on in 4571324b99
(builtin/repack.c: allow configuring cruft pack generation, 2022-05-20),
but did not move the 'delta_base_offset' variable.

Since the 'delta_base_offset' is a property of an individual
pack-objects command, re-introduce that variable as a member of 'struct
pack_objects_args', which will enable further code movement in the
subsequent commits.

Signed-off-by: Taylor Blau <me@ttaylorr.com>
---
builtin/repack.c | 11 ++++++-----
repack.h | 3 +++
2 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/builtin/repack.c b/builtin/repack.c
index af6de8d77a..f4af830353 100644
--- a/builtin/repack.c
+++ b/builtin/repack.c
@@ -34,7 +34,6 @@
#define RETAIN_PACK 2

static int pack_everything;
-static int delta_base_offset = 1;
static int pack_kept_objects = -1;
static int write_bitmaps = -1;
static int use_delta_islands;
@@ -63,9 +62,10 @@ static int repack_config(const char *var, const char *value,
const struct config_context *ctx, void *cb)
{
struct repack_config_ctx *repack_ctx = cb;
+ struct pack_objects_args *po_args = repack_ctx->po_args;
struct pack_objects_args *cruft_po_args = repack_ctx->cruft_po_args;
if (!strcmp(var, "repack.usedeltabaseoffset")) {
- delta_base_offset = git_config_bool(var, value);
+ po_args->delta_base_offset = git_config_bool(var, value);
return 0;
}
if (!strcmp(var, "repack.packkeptobjects")) {
@@ -315,7 +315,7 @@ static void prepare_pack_objects(struct child_process *cmd,
strvec_push(&cmd->args, "--local");
if (args->quiet)
strvec_push(&cmd->args, "--quiet");
- if (delta_base_offset)
+ if (args->delta_base_offset)
strvec_push(&cmd->args, "--delta-base-offset");
strvec_push(&cmd->args, out);
cmd->git_cmd = 1;
@@ -1271,8 +1271,8 @@ int cmd_repack(int argc,
const char *unpack_unreachable = NULL;
int keep_unreachable = 0;
struct string_list keep_pack_list = STRING_LIST_INIT_NODUP;
- struct pack_objects_args po_args = { 0 };
- struct pack_objects_args cruft_po_args = { 0 };
+ struct pack_objects_args po_args = PACK_OBJECTS_ARGS_INIT;
+ struct pack_objects_args cruft_po_args = PACK_OBJECTS_ARGS_INIT;
int write_midx = 0;
const char *cruft_expiration = NULL;
const char *expire_to = NULL;
@@ -1567,6 +1567,7 @@ int cmd_repack(int argc,

cruft_po_args.local = po_args.local;
cruft_po_args.quiet = po_args.quiet;
+ cruft_po_args.delta_base_offset = po_args.delta_base_offset;

ret = write_cruft_pack(&cruft_po_args, packtmp, pack_prefix,
cruft_expiration,
diff --git a/repack.h b/repack.h
index 421d439d5a..12632d7fec 100644
--- a/repack.h
+++ b/repack.h
@@ -15,9 +15,12 @@ struct pack_objects_args {
int local;
int name_hash_version;
int path_walk;
+ int delta_base_offset;
struct list_objects_filter_options filter_options;
};

+#define PACK_OBJECTS_ARGS_INIT { .delta_base_offset = 1 }
+
void pack_objects_args_release(struct pack_objects_args *args);

#endif /* REPACK_H */
--
2.51.0.243.g16eca91f2c0