Okay I may have an answer.
In the git source of gc.c, I see that the hook is run in the need_to_gc
function which have two ways to squeeze it...
static int need_to_gc(void)
{
/*
* Setting gc.auto to 0 or negative can disable the
* automatic gc.
*/
if (gc_auto_threshold <= 0)
return 0;
/*
* If there are too many loose objects, but not too many
* packs, we run "repack -d -l". If there are too many packs,
* we run "repack -A -d -l". Otherwise we tell the caller
* there is no need.
*/
if (too_many_packs())
append_option(argv_repack,
prune_expire && !strcmp(prune_expire, "now") ?
"-a" : "-A",
MAX_ADD);
else if (!too_many_loose_objects())
return 0;
if (run_hook(NULL, "pre-auto-gc", NULL))
return 0;
return 1;
}
IMO the first short-circuit (if gc.auto
is set to 0) is okay. But the second one should not prevent the hooks to be run, maybe it should pass it a boolean argument saying if yes or no the gc is needed. Because as it is now it's kind of frustrating that the hook isn't run when you would want it to.
And BTW I discovered the git source code, it's really a pleasure to read code that much clean!
EDIT: I tested the hook again on some old and rather big repos and the gc has never been called when the --auto
option was supplied. The default auto_threshold
value (which is apparently 27) might be a bit too high, or maybe the gc is needed only in extreme situation.
Anyway, it annoys me that this hook is not invoked, so much for that.