@matheusbsbs / matheus-bagliano / commits / bde3054016
Fork 0

git-gc --auto: add pre-auto-gc hook

If such a hook is available and exits with a non-zero status, then git-gc --auto won't run. Signed-off-by: Miklos Vajna <vmiklos@frugalware.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Miklos Vajna committed Apr 2, 2008 at 21:34 UTC bde30540169dd625cbd862ff6f38bc8224ec081c
1 file changed +31
builtin-gc.c
+31
@@ -157,6 +157,34 @@ static int too_many_packs(void)
157 return gc_auto_pack_limit <= cnt;
158 }
159
160 +static int run_hook(void)
161 +{
162 + const char *argv[2];
163 + struct child_process hook;
164 + int ret;
165 +
166 + argv[0] = git_path("hooks/pre-auto-gc");
167 + argv[1] = NULL;
168 +
169 + if (access(argv[0], X_OK) < 0)
170 + return 0;
171 +
172 + memset(&hook, 0, sizeof(hook));
173 + hook.argv = argv;
174 + hook.no_stdin = 1;
175 + hook.stdout_to_stderr = 1;
176 +
177 + ret = start_command(&hook);
178 + if (ret) {
179 + warning("Could not spawn %s", argv[0]);
180 + return ret;
181 + }
182 + ret = finish_command(&hook);
183 + if (ret == -ERR_RUN_COMMAND_WAITPID_SIGNAL)
184 + warning("%s exited due to uncaught signal", argv[0]);
185 + return ret;
186 +}
187 +
188 static int need_to_gc(void)
189 {
190 /*
@@ -176,6 +204,9 @@ static int need_to_gc(void)
204 append_option(argv_repack, "-A", MAX_ADD);
205 else if (!too_many_loose_objects())
206 return 0;
207 +
208 + if (run_hook())
209 + return 0;
210 return 1;
211 }
212