From patchwork Wed May 6 18:56:04 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: 11531721 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 BCC5414B4 for ; Wed, 6 May 2020 18:56:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A551820708 for ; Wed, 6 May 2020 18:56:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=pobox.com header.i=@pobox.com header.b="sicayi/t" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730112AbgEFS4N (ORCPT ); Wed, 6 May 2020 14:56:13 -0400 Received: from pb-smtp20.pobox.com ([173.228.157.52]:65008 "EHLO pb-smtp20.pobox.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729935AbgEFS4M (ORCPT ); Wed, 6 May 2020 14:56:12 -0400 Received: from pb-smtp20.pobox.com (unknown [127.0.0.1]) by pb-smtp20.pobox.com (Postfix) with ESMTP id 31EDAC6634; Wed, 6 May 2020 14:56:09 -0400 (EDT) (envelope-from junio@pobox.com) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to:cc :subject:references:sender:date:in-reply-to:message-id :mime-version:content-type; s=sasl; bh=Fgz8iNOPisSqsBguVE6GeVw8A 6g=; b=sicayi/tKCAzgk+S5f8ga2sSDBWG+GMMjRLBu1+baQFjBK4CdVJb8rL6n LYTuPOMcfJjKS5EZ2QFKw12KY2ydu55Ztsnd4gKhb3qa7UbXbN7Mcant9VjOAjb7 7o1szne48DyjdkmJ008i0IP6zutL47ldsLN9hYVD0Zk6F4g8lk= DomainKey-Signature: a=rsa-sha1; c=nofws; d=pobox.com; h=from:to:cc :subject:references:sender:date:in-reply-to:message-id :mime-version:content-type; q=dns; s=sasl; b=XMzX7kej4yUSft7HHgT /J8lMYh2idDjZcMXtEIP1mDuZw5xxJ1b688bTnhb+3Sdo3ug3bulrai+GYAcLkPS 3fAKnKsdDt/ECE4p0l1QjWNBrhVr7Ki+fiyRLXJbpYSOsJRiSez1iW+Wiahksei7 L2fNU2FgsbQTCI+X6SqEgANk= Received: from pb-smtp20.sea.icgroup.com (unknown [127.0.0.1]) by pb-smtp20.pobox.com (Postfix) with ESMTP id 2A6B6C6631; Wed, 6 May 2020 14:56:09 -0400 (EDT) (envelope-from junio@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-smtp20.pobox.com (Postfix) with ESMTPSA id 6FDD8C6630; Wed, 6 May 2020 14:56:06 -0400 (EDT) (envelope-from junio@pobox.com) From: Junio C Hamano To: Pierrick Gaudry Cc: git@vger.kernel.org, Johannes Schindelin Subject: Re* option -q not passed from "git commit" to "git gc --auto" References: <20200506094327.GC31637@rillettes> Date: Wed, 06 May 2020 11:56:04 -0700 In-Reply-To: (Junio C. Hamano's message of "Wed, 06 May 2020 10:31:31 -0700") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 X-Pobox-Relay-ID: 3DB6A16E-8FCB-11EA-98B4-B0405B776F7B-77302942!pb-smtp20.pobox.com Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Junio C Hamano writes: > An illustration to cover these (not even compile tested) to show > what I mean and help anybody get started. And this would be a good first step in the conversion. -- >8 -- Subject: [PATCH] run_auto_gc(): extract a reusable helper Earlier we taught "git fetch --quiet" to pass the "--quiet" option down to "gc --auto". This, however, is not limited to "fetch": $ git grep -e 'gc.*--auto' \*.c finds hits in "am", "commit", "merge", and "rebase". As a preparatory step, let's introduce a helper function run_auto_gc(), that the caller can pass a boolean "quiet". 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 19:03:14 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: 11531723 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 5B932139F for ; Wed, 6 May 2020 19:03:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1A557207DD for ; Wed, 6 May 2020 19:03:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=pobox.com header.i=@pobox.com header.b="mLI5iYvn" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727805AbgEFTDV (ORCPT ); Wed, 6 May 2020 15:03:21 -0400 Received: from pb-smtp21.pobox.com ([173.228.157.53]:50871 "EHLO pb-smtp21.pobox.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725985AbgEFTDU (ORCPT ); Wed, 6 May 2020 15:03:20 -0400 Received: from pb-smtp21.pobox.com (unknown [127.0.0.1]) by pb-smtp21.pobox.com (Postfix) with ESMTP id E55B8CFDDA; Wed, 6 May 2020 15:03:18 -0400 (EDT) (envelope-from junio@pobox.com) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to :subject:references:date:in-reply-to:message-id:mime-version :content-type; s=sasl; bh=FDj20rdZJbBxBW8nyRy1kDC8lQw=; b=mLI5iY vn5oKCxgkc9OOlyBTMTMnSeUvyX6W2GQRg1JFDQIQfZnoXojgPZ4JtLo7mzA3AZQ RJXFwqfmEidPsweFjxR73yvuolrHS0Q01Q6eLsh+7D7K4OSEg+8EqS8hoh866QtZ fS7D4tjlmz4BQjjl/5Ko9+C42nCN2Iwm0hnlk= DomainKey-Signature: a=rsa-sha1; c=nofws; d=pobox.com; h=from:to:subject :references:date:in-reply-to:message-id:mime-version :content-type; q=dns; s=sasl; b=umw+XEtCAnlt15NctVnYHFRgPCoPZ2To OtUAuNI6hmuWWxEkG+PTbs3N7JHf0nF7VftGGb7GPhm8jupiHJTplHreEKsOSHvb mJt7A9D53rXaVBbKfu/Zz6Jsp1n6l8b8zxezHkybvNdv7ou17NGI3bGobSF4f64G gg66BLzDULE= Received: from pb-smtp21.sea.icgroup.com (unknown [127.0.0.1]) by pb-smtp21.pobox.com (Postfix) with ESMTP id DCBE0CFDD9; Wed, 6 May 2020 15:03:18 -0400 (EDT) (envelope-from junio@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-smtp21.pobox.com (Postfix) with ESMTPSA id 28FDACFDD7; Wed, 6 May 2020 15:03:16 -0400 (EDT) (envelope-from junio@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 References: <20200506094327.GC31637@rillettes> Date: Wed, 06 May 2020 12:03:14 -0700 In-Reply-To: (Junio C. Hamano's message of "Wed, 06 May 2020 11:56:04 -0700") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 X-Pobox-Relay-ID: 3DD773C0-8FCC-11EA-8D96-8D86F504CC47-77302942!pb-smtp21.pobox.com Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org A handful of 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 these commands to do so using the run_gc_auto() helper we added earlier. Signed-off-by: Junio C Hamano --- * And this is the earlier one, wrapped in a proper patch submission format, to conclude the two-patch series. 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..955f91f076 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_gc_auto(state->quiet); } } diff --git a/builtin/commit.c b/builtin/commit.c index 7ba33a3bec..b08c51ae49 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_gc_auto(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..b6e9cebabf 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_gc_auto(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;