开发者

git pre-auto-gc hook not invoked at all

开发者 https://www.devze.com 2023-01-11 03:16 出处:网络
I would like to use the git pre-auto-gc hook but it doesn\'t seem to be invoke开发者_Python百科d at all.

I would like to use the git pre-auto-gc hook but it doesn't seem to be invoke开发者_Python百科d at all.

The file is executable and I tested it with git 1.7.1 and 1.5.6.5, neither of these seems to work as expected (they're not invoking the script when git gc --auto is run).

Does anyone of you know something about it? Maybe I need to setup someting in the configuration to make git aware of this hook?

I tried to google a bit but I didn't find anything...

Thanks :-).


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消