根本没有调用git pre-auto-gc钩子

时间:2010-08-08 08:43:04

标签: git hook

我想使用git pre-auto-gc hook,但似乎根本没有调用它。

该文件是可执行的,我使用git 1.7.1和1.5.6.5进行了测试,这些文件似乎都没有按预期工作(它们在git gc --auto运行时没有调用脚本)。

你们中有谁对此有所了解吗?也许我需要在配置中设置一些东西让git知道这个钩子?

我试着谷歌但我没找到任何东西......

谢谢: - )。

1 个答案:

答案 0 :(得分:0)

好的,我可能会有答案。

gc.c的git源代码中,我看到钩子在need_to_gc函数中运行,有两种方法可以挤压它...

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第一次短路(如果gc.auto设置为0)是可以的。但是第二个不应该阻止钩子运行,也许它应该传递一个布尔参数,说明是否需要gc。因为现在它是令人沮丧的,当你想要它时,钩子不会运行。

顺便说一句,我发现了git源代码,很高兴看到那些干净的代码!

编辑:我在一些旧的和相当大的回购中再次测试了钩子,并且在提供--auto选项时从未调用过gc。默认的auto_threshold值(显然是27)可能有点太高,或者只有在极端情况下才需要gc。

无论如何,这个钩子没有被调用,这让我很烦恼。