Skip to content

Commit 850b6ed

Browse files
committed
auto-gc: extract a reusable helper from "git fetch"
Back in 1991006 (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 <[email protected]> Reviewed-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent af6b65d commit 850b6ed

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

builtin/fetch.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1759,7 +1759,6 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
17591759
struct remote *remote = NULL;
17601760
int result = 0;
17611761
int prune_tags_ok = 1;
1762-
struct argv_array argv_gc_auto = ARGV_ARRAY_INIT;
17631762

17641763
packet_trace_identity("fetch");
17651764

@@ -1886,13 +1885,8 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
18861885

18871886
close_object_store(the_repository->objects);
18881887

1889-
if (enable_auto_gc) {
1890-
argv_array_pushl(&argv_gc_auto, "gc", "--auto", NULL);
1891-
if (verbosity < 0)
1892-
argv_array_push(&argv_gc_auto, "--quiet");
1893-
run_command_v_opt(argv_gc_auto.argv, RUN_GIT_CMD);
1894-
argv_array_clear(&argv_gc_auto);
1895-
}
1888+
if (enable_auto_gc)
1889+
run_auto_gc(verbosity < 0);
18961890

18971891
return result;
18981892
}

run-command.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1864,3 +1864,16 @@ int run_processes_parallel_tr2(int n, get_next_task_fn get_next_task,
18641864

18651865
return result;
18661866
}
1867+
1868+
int run_auto_gc(int quiet)
1869+
{
1870+
struct argv_array argv_gc_auto = ARGV_ARRAY_INIT;
1871+
int status;
1872+
1873+
argv_array_pushl(&argv_gc_auto, "gc", "--auto", NULL);
1874+
if (quiet)
1875+
argv_array_push(&argv_gc_auto, "--quiet");
1876+
status = run_command_v_opt(argv_gc_auto.argv, RUN_GIT_CMD);
1877+
argv_array_clear(&argv_gc_auto);
1878+
return status;
1879+
}

run-command.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,11 @@ LAST_ARG_MUST_BE_NULL
218218
int run_hook_le(const char *const *env, const char *name, ...);
219219
int run_hook_ve(const char *const *env, const char *name, va_list args);
220220

221+
/*
222+
* Trigger an auto-gc
223+
*/
224+
int run_auto_gc(int quiet);
225+
221226
#define RUN_COMMAND_NO_STDIN 1
222227
#define RUN_GIT_CMD 2 /*If this is to be git sub-command */
223228
#define RUN_COMMAND_STDOUT_TO_STDERR 4

0 commit comments

Comments
 (0)