Skip to content

Commit 60c0af8

Browse files
pks-tgitster
authored andcommitted
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>
1 parent 0ea94b0 commit 60c0af8

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

builtin/gc.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ static int rerere_gc_condition(struct gc_config *cfg UNUSED)
447447
return should_gc;
448448
}
449449

450-
static int too_many_loose_objects(struct gc_config *cfg)
450+
static int too_many_loose_objects(int limit)
451451
{
452452
/*
453453
* Quickly check if a "gc" is needed, by estimating how
@@ -469,7 +469,7 @@ static int too_many_loose_objects(struct gc_config *cfg)
469469
if (!dir)
470470
return 0;
471471

472-
auto_threshold = DIV_ROUND_UP(cfg->gc_auto_threshold, 256);
472+
auto_threshold = DIV_ROUND_UP(limit, 256);
473473
while ((ent = readdir(dir)) != NULL) {
474474
if (strspn(ent->d_name, "0123456789abcdef") != hexsz_loose ||
475475
ent->d_name[hexsz_loose] != '\0')
@@ -703,7 +703,7 @@ static int need_to_gc(struct gc_config *cfg, struct strvec *repack_args)
703703

704704
add_repack_all_option(cfg, &keep_pack, repack_args);
705705
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))
707707
add_repack_incremental_option(repack_args);
708708
else
709709
return 0;
@@ -1057,7 +1057,7 @@ int cmd_gc(int argc,
10571057
!opts.quiet && !daemonized ? COMMIT_GRAPH_WRITE_PROGRESS : 0,
10581058
NULL);
10591059

1060-
if (opts.auto_flag && too_many_loose_objects(&cfg))
1060+
if (opts.auto_flag && too_many_loose_objects(cfg.gc_auto_threshold))
10611061
warning(_("There are too many unreachable loose objects; "
10621062
"run 'git prune' to remove them."));
10631063

0 commit comments

Comments
 (0)