]> git.ipfire.org Git - thirdparty/git.git/commitdiff
auto-gc: extract a reusable helper from "git fetch"
authorJunio C Hamano <gitster@pobox.com>
Wed, 6 May 2020 20:18:29 +0000 (13:18 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 7 May 2020 19:24:33 +0000 (12:24 -0700)
Back in 1991006c (fetch: convert argv_gc_auto to struct argv_array,
2014-08-16), we taught "git fetch --quiet" to pass the "--quiet"
option down to "gc --auto".  This issue, however, is not limited to
"fetch":

    $ git grep -e 'gc.*--auto' \*.c

finds hits in "am", "commit", "merge", and "rebase" and these
commands do not pass "--quiet" down to "gc --auto" when they
themselves are told to be quiet.

As a preparatory step, let's introduce a helper function
run_auto_gc(), that the caller can pass a boolean "quiet",
and redo the fix to "git fetch" using the helper.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
Reviewed-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/fetch.c
run-command.c
run-command.h

index bf6bab80fab915242f412de7f0ced4a92d95f930..3e580b9559c6de0a1573b8e6e59126d47add40f1 100644 (file)
@@ -1759,7 +1759,6 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
        struct remote *remote = NULL;
        int result = 0;
        int prune_tags_ok = 1;
-       struct argv_array argv_gc_auto = ARGV_ARRAY_INIT;
 
        packet_trace_identity("fetch");
 
@@ -1886,13 +1885,8 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
 
        close_object_store(the_repository->objects);
 
-       if (enable_auto_gc) {
-               argv_array_pushl(&argv_gc_auto, "gc", "--auto", NULL);
-               if (verbosity < 0)
-                       argv_array_push(&argv_gc_auto, "--quiet");
-               run_command_v_opt(argv_gc_auto.argv, RUN_GIT_CMD);
-               argv_array_clear(&argv_gc_auto);
-       }
+       if (enable_auto_gc)
+               run_auto_gc(verbosity < 0);
 
        return result;
 }
index f5e1149f9b395e77c3d55a147332c1117746d7b1..2771eb936f3c4a6e97e848abbce5bf557eb60ec4 100644 (file)
@@ -1864,3 +1864,16 @@ int run_processes_parallel_tr2(int n, get_next_task_fn get_next_task,
 
        return result;
 }
+
+int run_auto_gc(int quiet)
+{
+       struct argv_array argv_gc_auto = ARGV_ARRAY_INIT;
+       int status;
+
+       argv_array_pushl(&argv_gc_auto, "gc", "--auto", NULL);
+       if (quiet)
+               argv_array_push(&argv_gc_auto, "--quiet");
+       status = run_command_v_opt(argv_gc_auto.argv, RUN_GIT_CMD);
+       argv_array_clear(&argv_gc_auto);
+       return status;
+}
index 0f3cc73ab6727e9b3805d93e5e4ab4dec3c1d5cb..191dfcdafe3dfcf6aff4b1c15e1be0924fbdb2d1 100644 (file)
@@ -218,6 +218,11 @@ LAST_ARG_MUST_BE_NULL
 int run_hook_le(const char *const *env, const char *name, ...);
 int run_hook_ve(const char *const *env, const char *name, va_list args);
 
+/*
+ * Trigger an auto-gc
+ */
+int run_auto_gc(int quiet);
+
 #define RUN_COMMAND_NO_STDIN 1
 #define RUN_GIT_CMD         2  /*If this is to be git sub-command */
 #define RUN_COMMAND_STDOUT_TO_STDERR 4