tags:

views:

60

answers:

1

Hello,

I would like to use the git pre-auto-gc hook but it doesn't seem to be invoked 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 :-).

A: 

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.

p4bl0
I'm curious, why do you want the hook to be run if it's already been determined that gc is not going to be run? The hook is designed to give you an opportunity to refuse automatic gc if it's due to be run; there doesn't seem to be any point it running the hook if gc is not going to be run in any case.
Charles Bailey
@Charles: I want this hook to be run because I'm using it for something else. I'm writing a blog engine based on git using hooks to generate static html. I want to be able to rebuild every html files with a hook (in case of template change for example) and the only "clean" way I see is to use this pre-auto-gc hook.
p4bl0
If you're using a hook to generate content based on repository changes isn't pre-auto-gc completely inappropriate? Wouldn't post-commit or post-update be more suitable?
Charles Bailey
@Charles yes, these hooks are already used to (re)build added or modified articles. What I want is a hook to be used to force rebuild of the whole site (in case of modification of the templates for instance), but I'll find another way. Thanks for your interrest :-).
p4bl0
Perhaps I'm being slow but why would a forced rebuild of your generated content have anything to do with how well packed your repository is? If the forced rebuild is initiated by a user action why does it need to be achieved via a hook, surely a regular command would be more natural?
Charles Bailey
@Charles: in fact I want to have nothing but git + hooks, no other dependencies (except for sh and the core-utils), and I want the blog to be managed as much as possible in the normal git workflow, so no other commands.But I think I'll simply check when commiting or pushing if a template file has been modified and in this case launch a full rebuild. You can follow the project at gitorious.org/fugitive if you want :-).
p4bl0