From patchwork Wed May 6 20:18:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Junio C Hamano X-Patchwork-Id: 11531819 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 635C0913 for ; Wed, 6 May 2020 20:18:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 475D32075E for ; Wed, 6 May 2020 20:18:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=pobox.com header.i=@pobox.com header.b="ZQy047D7" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728738AbgEFUSj (ORCPT ); Wed, 6 May 2020 16:18:39 -0400 Received: from pb-smtp2.pobox.com ([64.147.108.71]:55237 "EHLO pb-smtp2.pobox.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727792AbgEFUSg (ORCPT ); Wed, 6 May 2020 16:18:36 -0400 Received: from pb-smtp2.pobox.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id CFF5160F6B; Wed, 6 May 2020 16:18:32 -0400 (EDT) (envelope-from gitster@pobox.com) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=sasl; bh=cWImBeD1oMT7xXkso5c3rnZkZ hU=; b=ZQy047D7cHjJ4JC63I1wMvf3/gQTVQCD/ItZi6rr3x71p6wMkT7DHgUFe Jt1q3kldADj5MlwhwHd4YlIR3o9yUdURdVCLQmvf18nEJk8Ks+pDbjQuFM08jXAS P3LBuLjCc5DCgN9FVnw5I09k+w0vNiUxhZiOaWpC8nE0mswatc= DomainKey-Signature: a=rsa-sha1; c=nofws; d=pobox.com; h=from:to:subject :date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; q=dns; s=sasl; b=DAuZSRGi6bxQW5M41Xi 0Tb5fOmqgJDcPpJuwxD1iRRDDSneYtwPuSRs2TVjaJomni6jVV7D6LfHqYrmQBYC aO8k9k5eV6wwlRv6C6F5JfsbB9yZDrtXJxBTkdob29qUWTz0R5BRvpeoS1iZhRMC 8mGAB/84akJDwnyH0pq1LDOg= Received: from pb-smtp2.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id C819660F68; Wed, 6 May 2020 16:18:32 -0400 (EDT) (envelope-from gitster@pobox.com) Received: from pobox.com (unknown [34.74.119.39]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp2.pobox.com (Postfix) with ESMTPSA id 4FA7A60F67; Wed, 6 May 2020 16:18:32 -0400 (EDT) (envelope-from gitster@pobox.com) From: Junio C Hamano To: git@vger.kernel.org Subject: [PATCH 1/2] auto-gc: extract a reusable helper from "git fetch" Date: Wed, 6 May 2020 13:18:29 -0700 Message-Id: <20200506201830.92818-2-gitster@pobox.com> X-Mailer: git-send-email 2.26.2-561-g07d8ea56f2 In-Reply-To: <20200506201830.92818-1-gitster@pobox.com> References: <20200506094327.GC31637@rillettes> <20200506201830.92818-1-gitster@pobox.com> MIME-Version: 1.0 X-Pobox-Relay-ID: C1AE5BAA-8FD6-11EA-8533-D1361DBA3BAF-77302942!pb-smtp2.pobox.com Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org 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 --- builtin/fetch.c | 10 ++-------- run-command.c | 13 +++++++++++++ run-command.h | 5 +++++ 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/builtin/fetch.c b/builtin/fetch.c index bf6bab80fa..3e580b9559 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -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; } diff --git a/run-command.c b/run-command.c index f5e1149f9b..2771eb936f 100644 --- a/run-command.c +++ b/run-command.c @@ -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; +} diff --git a/run-command.h b/run-command.h index 0f3cc73ab6..191dfcdafe 100644 --- a/run-command.h +++ b/run-command.h @@ -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 From patchwork Wed May 6 20:18:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Junio C Hamano X-Patchwork-Id: 11531815 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 79B3B913 for ; Wed, 6 May 2020 20:18:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5E8F2207DD for ; Wed, 6 May 2020 20:18:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=pobox.com header.i=@pobox.com header.b="BYDN76jj" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728709AbgEFUSg (ORCPT ); Wed, 6 May 2020 16:18:36 -0400 Received: from pb-smtp1.pobox.com ([64.147.108.70]:60811 "EHLO pb-smtp1.pobox.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727803AbgEFUSf (ORCPT ); Wed, 6 May 2020 16:18:35 -0400 Received: from pb-smtp1.pobox.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id 5AE0348513; Wed, 6 May 2020 16:18:33 -0400 (EDT) (envelope-from gitster@pobox.com) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=sasl; bh=bip3QuKqifkb9ukwgnt54++G+ FY=; b=BYDN76jjHR4GBDUjn3Drfe2BqD5lEHDgNjdzQJ6nAs3EYkOH13lZ5xw0Y jUBRcx8Fs0+tL9FyN9heIJlRaozG6H2A/oMIl9Ginin43tbeqQ5Ji7W4VIze+iWH gaq47gwic00xEy/KP9dxZovIQyzXsIvN5YdziL7EjnU6y2jB5Y= DomainKey-Signature: a=rsa-sha1; c=nofws; d=pobox.com; h=from:to:subject :date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; q=dns; s=sasl; b=B9NAnVkOTIecYZCaAi2 8ln7oE4TfvkXN66OMT1FBh0wOYMVh8AM4QsYBoTiVNvzfDGT0WWRbsjJN6BhCRMK XtRQir/W18ecwBOM8dF16t3eoi2w3N71Cf8Bbwarw2tHbjwRUobXejRe91C5stXG VOoRtji68vr8SB5Bsr3fzjTo= Received: from pb-smtp1.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id 5329E48512; Wed, 6 May 2020 16:18:33 -0400 (EDT) (envelope-from gitster@pobox.com) Received: from pobox.com (unknown [34.74.119.39]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp1.pobox.com (Postfix) with ESMTPSA id CEAD748510; Wed, 6 May 2020 16:18:32 -0400 (EDT) (envelope-from gitster@pobox.com) From: Junio C Hamano To: git@vger.kernel.org Subject: [PATCH 2/2] auto-gc: pass --quiet down from am, commit, merge and rebase Date: Wed, 6 May 2020 13:18:30 -0700 Message-Id: <20200506201830.92818-3-gitster@pobox.com> X-Mailer: git-send-email 2.26.2-561-g07d8ea56f2 In-Reply-To: <20200506201830.92818-1-gitster@pobox.com> References: <20200506094327.GC31637@rillettes> <20200506201830.92818-1-gitster@pobox.com> MIME-Version: 1.0 X-Pobox-Relay-ID: C1FD5430-8FD6-11EA-9007-C28CBED8090B-77302942!pb-smtp1.pobox.com Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org These commands take the --quiet option for their own operation, but they forget to pass the option down when they invoke "git gc --auto" internally. Teach them to do so using the run_auto_gc() helper we added in the previous step. Signed-off-by: Junio C Hamano --- builtin/am.c | 3 +-- builtin/commit.c | 3 +-- builtin/merge.c | 3 +-- builtin/rebase.c | 3 +-- 4 files changed, 4 insertions(+), 8 deletions(-) diff --git a/builtin/am.c b/builtin/am.c index e3dfd93c25..69e50de018 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -1691,7 +1691,6 @@ static int do_interactive(struct am_state *state) */ static void am_run(struct am_state *state, int resume) { - const char *argv_gc_auto[] = {"gc", "--auto", NULL}; struct strbuf sb = STRBUF_INIT; unlink(am_path(state, "dirtyindex")); @@ -1796,7 +1795,7 @@ static void am_run(struct am_state *state, int resume) if (!state->rebasing) { am_destroy(state); close_object_store(the_repository->objects); - run_command_v_opt(argv_gc_auto, RUN_GIT_CMD); + run_auto_gc(state->quiet); } } diff --git a/builtin/commit.c b/builtin/commit.c index 7ba33a3bec..fa8eca623e 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -1488,7 +1488,6 @@ static int git_commit_config(const char *k, const char *v, void *cb) int cmd_commit(int argc, const char **argv, const char *prefix) { - const char *argv_gc_auto[] = {"gc", "--auto", NULL}; static struct wt_status s; static struct option builtin_commit_options[] = { OPT__QUIET(&quiet, N_("suppress summary after successful commit")), @@ -1697,7 +1696,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix) return 1; repo_rerere(the_repository, 0); - run_command_v_opt(argv_gc_auto, RUN_GIT_CMD); + run_auto_gc(quiet); run_commit_hook(use_editor, get_index_file(), "post-commit", NULL); if (amend && !no_post_rewrite) { commit_post_rewrite(the_repository, current_head, &oid); diff --git a/builtin/merge.c b/builtin/merge.c index d127d2225f..c66b9b532c 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -447,7 +447,6 @@ static void finish(struct commit *head_commit, if (verbosity >= 0 && !merge_msg.len) printf(_("No merge message -- not updating HEAD\n")); else { - const char *argv_gc_auto[] = { "gc", "--auto", NULL }; update_ref(reflog_message.buf, "HEAD", new_head, head, 0, UPDATE_REFS_DIE_ON_ERR); /* @@ -455,7 +454,7 @@ static void finish(struct commit *head_commit, * user should see them. */ close_object_store(the_repository->objects); - run_command_v_opt(argv_gc_auto, RUN_GIT_CMD); + run_auto_gc(verbosity < 0); } } if (new_head && show_diffstat) { diff --git a/builtin/rebase.c b/builtin/rebase.c index bff53d5d16..fe1a9aba45 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -763,7 +763,6 @@ static int apply_autostash(struct rebase_options *opts) static int finish_rebase(struct rebase_options *opts) { struct strbuf dir = STRBUF_INIT; - const char *argv_gc_auto[] = { "gc", "--auto", NULL }; int ret = 0; delete_ref(NULL, "REBASE_HEAD", NULL, REF_NO_DEREF); @@ -773,7 +772,7 @@ static int finish_rebase(struct rebase_options *opts) * We ignore errors in 'gc --auto', since the * user should see them. */ - run_command_v_opt(argv_gc_auto, RUN_GIT_CMD); + run_auto_gc(!(opts->flags & (REBASE_NO_QUIET|REBASE_VERBOSE))); if (opts->type == REBASE_MERGE) { struct replay_opts replay = REPLAY_OPTS_INIT;