Skip to content

Commit 3af459e

Browse files
committed
Merge branch 'jc/auto-gc-quiet'
Teach "am", "commit", "merge" and "rebase", when they are run with the "--quiet" option, to pass "--quiet" down to "gc --auto". * jc/auto-gc-quiet: auto-gc: pass --quiet down from am, commit, merge and rebase auto-gc: extract a reusable helper from "git fetch"
2 parents aa28171 + 7c3e9e8 commit 3af459e

File tree

7 files changed

+24
-16
lines changed

7 files changed

+24
-16
lines changed

builtin/am.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1691,7 +1691,6 @@ static int do_interactive(struct am_state *state)
16911691
*/
16921692
static void am_run(struct am_state *state, int resume)
16931693
{
1694-
const char *argv_gc_auto[] = {"gc", "--auto", NULL};
16951694
struct strbuf sb = STRBUF_INIT;
16961695

16971696
unlink(am_path(state, "dirtyindex"));
@@ -1796,7 +1795,7 @@ static void am_run(struct am_state *state, int resume)
17961795
if (!state->rebasing) {
17971796
am_destroy(state);
17981797
close_object_store(the_repository->objects);
1799-
run_command_v_opt(argv_gc_auto, RUN_GIT_CMD);
1798+
run_auto_gc(state->quiet);
18001799
}
18011800
}
18021801

builtin/commit.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1494,7 +1494,6 @@ static int git_commit_config(const char *k, const char *v, void *cb)
14941494

14951495
int cmd_commit(int argc, const char **argv, const char *prefix)
14961496
{
1497-
const char *argv_gc_auto[] = {"gc", "--auto", NULL};
14981497
static struct wt_status s;
14991498
static struct option builtin_commit_options[] = {
15001499
OPT__QUIET(&quiet, N_("suppress summary after successful commit")),
@@ -1703,7 +1702,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
17031702
git_test_write_commit_graph_or_die();
17041703

17051704
repo_rerere(the_repository, 0);
1706-
run_command_v_opt(argv_gc_auto, RUN_GIT_CMD);
1705+
run_auto_gc(quiet);
17071706
run_commit_hook(use_editor, get_index_file(), "post-commit", NULL);
17081707
if (amend && !no_post_rewrite) {
17091708
commit_post_rewrite(the_repository, current_head, &oid);

builtin/fetch.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1753,7 +1753,6 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
17531753
struct remote *remote = NULL;
17541754
int result = 0;
17551755
int prune_tags_ok = 1;
1756-
struct argv_array argv_gc_auto = ARGV_ARRAY_INIT;
17571756

17581757
packet_trace_identity("fetch");
17591758

@@ -1880,13 +1879,8 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
18801879

18811880
close_object_store(the_repository->objects);
18821881

1883-
if (enable_auto_gc) {
1884-
argv_array_pushl(&argv_gc_auto, "gc", "--auto", NULL);
1885-
if (verbosity < 0)
1886-
argv_array_push(&argv_gc_auto, "--quiet");
1887-
run_command_v_opt(argv_gc_auto.argv, RUN_GIT_CMD);
1888-
argv_array_clear(&argv_gc_auto);
1889-
}
1882+
if (enable_auto_gc)
1883+
run_auto_gc(verbosity < 0);
18901884

18911885
return result;
18921886
}

builtin/merge.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,15 +450,14 @@ static void finish(struct commit *head_commit,
450450
if (verbosity >= 0 && !merge_msg.len)
451451
printf(_("No merge message -- not updating HEAD\n"));
452452
else {
453-
const char *argv_gc_auto[] = { "gc", "--auto", NULL };
454453
update_ref(reflog_message.buf, "HEAD", new_head, head,
455454
0, UPDATE_REFS_DIE_ON_ERR);
456455
/*
457456
* We ignore errors in 'gc --auto', since the
458457
* user should see them.
459458
*/
460459
close_object_store(the_repository->objects);
461-
run_command_v_opt(argv_gc_auto, RUN_GIT_CMD);
460+
run_auto_gc(verbosity < 0);
462461
}
463462
}
464463
if (new_head && show_diffstat) {

builtin/rebase.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,6 @@ static int rebase_write_basic_state(struct rebase_options *opts)
722722
static int finish_rebase(struct rebase_options *opts)
723723
{
724724
struct strbuf dir = STRBUF_INIT;
725-
const char *argv_gc_auto[] = { "gc", "--auto", NULL };
726725
int ret = 0;
727726

728727
delete_ref(NULL, "REBASE_HEAD", NULL, REF_NO_DEREF);
@@ -732,7 +731,7 @@ static int finish_rebase(struct rebase_options *opts)
732731
* We ignore errors in 'gc --auto', since the
733732
* user should see them.
734733
*/
735-
run_command_v_opt(argv_gc_auto, RUN_GIT_CMD);
734+
run_auto_gc(!(opts->flags & (REBASE_NO_QUIET|REBASE_VERBOSE)));
736735
if (opts->type == REBASE_MERGE) {
737736
struct replay_opts replay = REPLAY_OPTS_INIT;
738737

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)