builtin/gc: make `too_many_loose_objects()` reusable without GC config
To decide whether or not a repository needs to be repacked we estimate the number of loose objects. If the number exceeds a certain threshold we perform the repack, otherwise we don't. This is done via `too_many_loose_objects()`, which takes as parameter the `struct gc_config`. This configuration is only used to determine the threshold. In a subsequent commit we'll add another caller of this function that wants to pass a different limit than the one stored in that structure. Refactor the function accordingly so that we only take the limit as parameter instead of the whole structure. Signed-off-by: Patrick Steinhardt <ps@pks.im> Acked-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patrick Steinhardt committed
Oct 24, 2025 at 08:57 UTC
60c0af8e20b7c347003c40ca342a074239ea8453
1 file changed
+4
-4
builtin/gc.c
+4
-4
@@ -447,7 +447,7 @@ out:
447
return should_gc;
448
}
449
450
-static int too_many_loose_objects(struct gc_config *cfg)
450
+static int too_many_loose_objects(int limit)
451
{
452
/*
453
* Quickly check if a "gc" is needed, by estimating how
@@ -469,7 +469,7 @@ static int too_many_loose_objects(struct gc_config *cfg)
469
if (!dir)
470
return 0;
471
472
- auto_threshold = DIV_ROUND_UP(cfg->gc_auto_threshold, 256);
472
+ auto_threshold = DIV_ROUND_UP(limit, 256);
473
while ((ent = readdir(dir)) != NULL) {
474
if (strspn(ent->d_name, "0123456789abcdef") != hexsz_loose ||
475
ent->d_name[hexsz_loose] != '\0')
@@ -703,7 +703,7 @@ static int need_to_gc(struct gc_config *cfg, struct strvec *repack_args)
703
704
add_repack_all_option(cfg, &keep_pack, repack_args);
705
string_list_clear(&keep_pack, 0);
706
- } else if (too_many_loose_objects(cfg))
706
+ } else if (too_many_loose_objects(cfg->gc_auto_threshold))
707
add_repack_incremental_option(repack_args);
708
else
709
return 0;
@@ -1057,7 +1057,7 @@ int cmd_gc(int argc,
1057
!opts.quiet && !daemonized ? COMMIT_GRAPH_WRITE_PROGRESS : 0,
1058
NULL);
1059
1060
- if (opts.auto_flag && too_many_loose_objects(&cfg))
1060
+ if (opts.auto_flag && too_many_loose_objects(cfg.gc_auto_threshold))
1061
warning(_("There are too many unreachable loose objects; "
1062
"run 'git prune' to remove them."));
1063