From patchwork Tue Mar 15 01:49:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victoria Dye X-Patchwork-Id: 12780954 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0F951C433F5 for ; Tue, 15 Mar 2022 01:49:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344293AbiCOBvB (ORCPT ); Mon, 14 Mar 2022 21:51:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48998 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244798AbiCOBu4 (ORCPT ); Mon, 14 Mar 2022 21:50:56 -0400 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DF790140CE for ; Mon, 14 Mar 2022 18:49:45 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id h15so26725972wrc.6 for ; Mon, 14 Mar 2022 18:49:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=dHJAh2wSOh3GaTUQruWHP7hWq66tHM98xal7cz9L1WY=; b=dJZnmcN/JyWnwN5p8XQrJjd+j2ZD8Ufv+Fqc3QXUfHFtsK02dEJuK1issi11vuDBao UbfYY/BhGvvVwGfWi+9rgrACbrbeKS6tKabk4c71lhtoUjLfPbqrhsmE8LaRviAaQY9P 7FFXTnLMP0fU+832FhmvIZUsF4fjM3rdMSXK1k+80ZOfwmnbKaBQzb9jjsZXUlrK+lFq +Q7U5gYOMg/K02LtohbLUurQKbgAIS70J9n+yuAkO5YePkCg7oz+9RzbCGQkphVIx8Gz bjrvVd9hBLUQy7mB5OIsQjZmT/Bn94RaNvsG6feKM+EzlZPB+MSitZ9PZbtZxdshm0zk XJlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=dHJAh2wSOh3GaTUQruWHP7hWq66tHM98xal7cz9L1WY=; b=tKnbidQsr1Z0yA9j+fOWJME+NbxdADTPVT3Mq/8uJxDCFK4ZFLiXY0L5D1vChAEdpz cey+0mtiK7n+eNcklBJuN9aeYKiAHKMHGkw3bKHH6zMXiwfz+dGQq/dGjXYqr+1/fIfw A4AC9UW+F+bS9gfaGePRnNtrPoqxUeW2gPw8pSE/Gdiq1uOVWyF+UTRv0fmHEFEPBBIG 9uk/4SZYsrvIS+iArMyrxrIwXz1DlEiK6LGawG7nkCijipSs+OB2wWKm9yoIN92htIMO Le1wapXAq7CJGDFjN2T0EonkvR61kE9KhVf6ysO3thtmRmmeXR+wNBTP62IaRahtmnC5 8m2w== X-Gm-Message-State: AOAM532XYbCxKTunOr2S5GOg3N+Fiq74IaNkVMu3jn83i1zEYf3VZwjC Mk8RMzmc3asfmKcpiIcH4MzCMFSk4yI= X-Google-Smtp-Source: ABdhPJzL9EsGN4JRYNa1XiQqjXn5xZ2yj7NPgW4lehS0h/onOpSXWMszurxD0zuKONNJsTTy86kFCw== X-Received: by 2002:a5d:6782:0:b0:203:d6af:5869 with SMTP id v2-20020a5d6782000000b00203d6af5869mr285869wru.213.1647308984171; Mon, 14 Mar 2022 18:49:44 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id v15-20020a5d590f000000b001f04b96f9a9sm14339000wrd.42.2022.03.14.18.49.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Mar 2022 18:49:43 -0700 (PDT) Message-Id: <7206ef8dd8ab088feab841c5574d486b6f19af5e.1647308982.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 15 Mar 2022 01:49:38 +0000 Subject: [PATCH v3 1/5] reset: revise index refresh advice Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: derrickstolee@github.com, Victoria Dye , Victoria Dye Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Victoria Dye From: Victoria Dye Update the advice describing index refresh from "enumerate unstaged changes" to "refresh the index." Describing 'refresh_index(...)' as "enumerating unstaged changes" is not fully representative of what an index refresh is doing; more generally, it updates the properties of index entries that are affected by outside-of-index state, e.g. CE_UPTODATE, which is affected by the file contents on-disk. This distinction is relevant to operations that read the index but do not refresh first - e.g., 'git read-tree' - where a stale index may cause incorrect behavior. In addition to changing the advice message, use the "advise" function to print advice. Signed-off-by: Victoria Dye --- Documentation/config/advice.txt | 4 ++-- builtin/reset.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Documentation/config/advice.txt b/Documentation/config/advice.txt index c40eb09cb7e..971aad2f237 100644 --- a/Documentation/config/advice.txt +++ b/Documentation/config/advice.txt @@ -69,8 +69,8 @@ advice.*:: merge to avoid overwriting local changes. resetQuiet:: Advice to consider using the `--quiet` option to linkgit:git-reset[1] - when the command takes more than 2 seconds to enumerate unstaged - changes after reset. + when the command takes more than 2 seconds to refresh the index + after reset. resolveConflict:: Advice shown by various commands when conflicts prevent the operation from being performed. diff --git a/builtin/reset.c b/builtin/reset.c index 6e65e90c5db..a420497a14f 100644 --- a/builtin/reset.c +++ b/builtin/reset.c @@ -525,9 +525,9 @@ int cmd_reset(int argc, const char **argv, const char *prefix) _("Unstaged changes after reset:")); t_delta_in_ms = (getnanotime() - t_begin) / 1000000; if (advice_enabled(ADVICE_RESET_QUIET_WARNING) && t_delta_in_ms > REFRESH_INDEX_DELAY_WARNING_IN_MS) { - printf(_("\nIt took %.2f seconds to enumerate unstaged changes after reset. You can\n" + advise(_("It took %.2f seconds to refresh the index after reset. You can\n" "use '--quiet' to avoid this. Set the config setting reset.quiet to true\n" - "to make this the default.\n"), t_delta_in_ms / 1000.0); + "to make this the default."), t_delta_in_ms / 1000.0); } } } else { From patchwork Tue Mar 15 01:49:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victoria Dye X-Patchwork-Id: 12780956 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A0108C433EF for ; Tue, 15 Mar 2022 01:49:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244798AbiCOBvC (ORCPT ); Mon, 14 Mar 2022 21:51:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344223AbiCOBu5 (ORCPT ); Mon, 14 Mar 2022 21:50:57 -0400 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD45E1CFEF for ; Mon, 14 Mar 2022 18:49:46 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id r6so26319271wrr.2 for ; Mon, 14 Mar 2022 18:49:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=fyiFNCooMn8skm8kf56i+jirRha3dnEx0CGS66bx7Qo=; b=MKhzxPRWwu6cwxnmqT92lxSjisGktkvMD+89qYXvp4Bq3WavoKmW6jHpPB9MjGd7Kl +hIlii9sNzap/aB+ryoaBplh7vjQvBfhdxC7iYJNSXY6obUp3wrYkHbC0JB/UDlNAzvO BM/4cqyu0y/EcFeOWyW19TAHW/V6ZoQHzwpzW1kd5zf1xdGtugSc7f5cSU6o+VTdJ7R8 gU98J+YJX6E8wolNHhjVcZV52SECytw1w8EuSGbF2g2iG2qqL8SxSRZBC5kKujYI6AC1 n9k/Dz1kkYI2SXpYQmH+L+CKKtl1BslrhH3pEF4gPzFzKZ4AxBpVxIA2vWNIymiT9sxW SHIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=fyiFNCooMn8skm8kf56i+jirRha3dnEx0CGS66bx7Qo=; b=UyOL9qlD0uxCgQvbxD7/mBBhY/2WxDulrtI6vzUD1qWh7p2/6mn4RA+Du8fV1gCp7v RsUPFMognA5en0zDyhZ54ZyA+dU9Y1YN2MzqAlwTp0qCDcKqBZCi9kok63yf34IO0X1b JHZq7/NGEezHtrfv22CB6aMF5FqKNYOuR4qfu0LhZXL4x4wvvl58wK6YTyhJ9ZV4ZbKJ 0nPfoN0iJpd8BJWQSkJkoHTMpIaEv3/7izuwtfROOa29lqFflm+H1TdiiCqJdLpP7HBZ jWmP0MhACTANvHCAoQbhIDGtrKgmypSfAAGxW/ZTmrR/CuoNljR8ermSkq8qjDUe1f0r ySRg== X-Gm-Message-State: AOAM531tcOrgecWLOvubNyJh5/ldmUdTsfR/Pv0M5Eiq167DhjVRH6RA LRuvwsUIcix0EkgigcHxhEkU4jhD7wg= X-Google-Smtp-Source: ABdhPJz0dLwleanTe3p5FcSba8pIY+VlD83e2f5RXUsS4FWLafaEadgYDTNfAhjeCUqCfCx7zv990A== X-Received: by 2002:adf:ef81:0:b0:1f0:95f:30a7 with SMTP id d1-20020adfef81000000b001f0095f30a7mr18085198wro.636.1647308985053; Mon, 14 Mar 2022 18:49:45 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id a8-20020a05600c068800b00389bdc8c8c2sm842786wmn.12.2022.03.14.18.49.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Mar 2022 18:49:44 -0700 (PDT) Message-Id: <101cee42dd6d5a4e5f12da647eafab9334d69a2d.1647308982.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 15 Mar 2022 01:49:39 +0000 Subject: [PATCH v3 2/5] reset: introduce --[no-]refresh option to --mixed Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: derrickstolee@github.com, Victoria Dye , Victoria Dye Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Victoria Dye From: Victoria Dye Add a new --[no-]refresh option that is intended to explicitly determine whether a mixed reset should end in an index refresh. Starting at 9ac8125d1a (reset: don't compute unstaged changes after reset when --quiet, 2018-10-23), using the '--quiet' option results in skipping the call to 'refresh_index(...)' at the end of a mixed reset with the goal of improving performance. However, by coupling behavior that modifies the index with the option that silences logs, there is no way for users to have one without the other (i.e., silenced logs with a refreshed index) without incurring the overhead of a separate call to 'git update-index --refresh'. Furthermore, there is minimal user-facing documentation indicating that --quiet skips the index refresh, potentially leading to unexpected issues executing commands after 'git reset --quiet' that do not themselves refresh the index (e.g., internals of 'git stash', 'git read-tree'). To mitigate these issues, '--[no-]refresh' and 'reset.refresh' are introduced to provide a dedicated mechanism for refreshing the index. When either is set, '--quiet' and 'reset.quiet' revert to controlling only whether logs are silenced and do not affect index refresh. Helped-by: Derrick Stolee Helped-by: Junio C Hamano Signed-off-by: Victoria Dye --- Documentation/git-reset.txt | 9 +++++ builtin/reset.c | 13 ++++++- t/t7102-reset.sh | 73 +++++++++++++++++++++++++++++++++---- 3 files changed, 87 insertions(+), 8 deletions(-) diff --git a/Documentation/git-reset.txt b/Documentation/git-reset.txt index 6f7685f53d5..89ddc85c2e4 100644 --- a/Documentation/git-reset.txt +++ b/Documentation/git-reset.txt @@ -110,6 +110,15 @@ OPTIONS `reset.quiet` config option. `--quiet` and `--no-quiet` will override the default behavior. +--refresh:: +--no-refresh:: + Proactively refresh the index after a mixed reset. If unspecified, the + behavior falls back on the `reset.refresh` config option. If neither + `--[no-]refresh` nor `reset.refresh` are set, the default behavior is + decided by the `--[no-]quiet` option and/or `reset.quiet` config. + If `--quiet` is specified or `reset.quiet` is set with no command-line + "quiet" setting, refresh is disabled. Otherwise, refresh is enabled. + --pathspec-from-file=:: Pathspec is passed in `` instead of commandline args. If `` is exactly `-` then standard input is used. Pathspec diff --git a/builtin/reset.c b/builtin/reset.c index a420497a14f..7f667e13d71 100644 --- a/builtin/reset.c +++ b/builtin/reset.c @@ -392,6 +392,7 @@ static int git_reset_config(const char *var, const char *value, void *cb) int cmd_reset(int argc, const char **argv, const char *prefix) { int reset_type = NONE, update_ref_status = 0, quiet = 0; + int refresh = -1; int patch_mode = 0, pathspec_file_nul = 0, unborn; const char *rev, *pathspec_from_file = NULL; struct object_id oid; @@ -399,6 +400,8 @@ int cmd_reset(int argc, const char **argv, const char *prefix) int intent_to_add = 0; const struct option options[] = { OPT__QUIET(&quiet, N_("be quiet, only report errors")), + OPT_BOOL(0, "refresh", &refresh, + N_("skip refreshing the index after reset")), OPT_SET_INT(0, "mixed", &reset_type, N_("reset HEAD and index"), MIXED), OPT_SET_INT(0, "soft", &reset_type, N_("reset only HEAD"), SOFT), @@ -421,11 +424,19 @@ int cmd_reset(int argc, const char **argv, const char *prefix) git_config(git_reset_config, NULL); git_config_get_bool("reset.quiet", &quiet); + git_config_get_bool("reset.refresh", &refresh); argc = parse_options(argc, argv, prefix, options, git_reset_usage, PARSE_OPT_KEEP_DASHDASH); parse_args(&pathspec, argv, prefix, patch_mode, &rev); + /* + * If refresh is completely unspecified (either by config or by command + * line option), decide based on 'quiet'. + */ + if (refresh < 0) + refresh = !quiet; + if (pathspec_from_file) { if (patch_mode) die(_("options '%s' and '%s' cannot be used together"), "--pathspec-from-file", "--patch"); @@ -517,7 +528,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix) if (read_from_tree(&pathspec, &oid, intent_to_add)) return 1; the_index.updated_skipworktree = 1; - if (!quiet && get_git_work_tree()) { + if (refresh && get_git_work_tree()) { uint64_t t_begin, t_delta_in_ms; t_begin = getnanotime(); diff --git a/t/t7102-reset.sh b/t/t7102-reset.sh index d05426062ec..1dc3911a060 100755 --- a/t/t7102-reset.sh +++ b/t/t7102-reset.sh @@ -462,14 +462,73 @@ test_expect_success 'resetting an unmodified path is a no-op' ' git diff-index --cached --exit-code HEAD ' +test_reset_refreshes_index () { + + # To test whether the index is refreshed in `git reset --mixed` with + # the given options, create a scenario where we clearly see different + # results depending on whether the refresh occurred or not. + + # Step 0: start with a clean index + git reset --hard HEAD && + + # Step 1: remove file2, but only in the index (no change to worktree) + git rm --cached file2 && + + # Step 2: reset index & leave worktree unchanged from HEAD + git $1 reset $2 --mixed HEAD && + + # Step 3: verify whether the index is refreshed by checking whether + # file2 still has staged changes in the index differing from HEAD (if + # the refresh occurred, there should be no such changes) + git diff-files >output.log && + test_must_be_empty output.log +} + test_expect_success '--mixed refreshes the index' ' - cat >expect <<-\EOF && - Unstaged changes after reset: - M file2 - EOF - echo 123 >>file2 && - git reset --mixed HEAD >output && - test_cmp expect output + # Verify default behavior (with no config settings or command line + # options) + test_reset_refreshes_index +' +test_expect_success '--mixed --[no-]quiet sets default refresh behavior' ' + # Verify that --[no-]quiet and `reset.quiet` (without --[no-]refresh) + # determine refresh behavior + + # Config setting + ! test_reset_refreshes_index "-c reset.quiet=true" && + test_reset_refreshes_index "-c reset.quiet=false" && + + # Command line option + ! test_reset_refreshes_index "" --quiet && + test_reset_refreshes_index "" --no-quiet && + + # Command line option overrides config setting + ! test_reset_refreshes_index "-c reset.quiet=false" --quiet && + test_reset_refreshes_index "-c reset.refresh=true" --no-quiet +' + +test_expect_success '--mixed --[no-]refresh sets refresh behavior' ' + # Verify that --[no-]refresh and `reset.refresh` control index refresh + + # Config setting + test_reset_refreshes_index "-c reset.refresh=true" && + ! test_reset_refreshes_index "-c reset.refresh=false" && + + # Command line option + test_reset_refreshes_index "" --refresh && + ! test_reset_refreshes_index "" --no-refresh && + + # Command line option overrides config setting + test_reset_refreshes_index "-c reset.refresh=false" --refresh && + ! test_reset_refreshes_index "-c reset.refresh=true" --no-refresh +' + +test_expect_success '--mixed --refresh overrides --quiet refresh behavior' ' + # Verify that *both* --refresh and `reset.refresh` override the + # default non-refresh behavior of --quiet + test_reset_refreshes_index "" "--quiet --refresh" && + test_reset_refreshes_index "-c reset.quiet=true" --refresh && + test_reset_refreshes_index "-c reset.refresh=true" --quiet && + test_reset_refreshes_index "-c reset.refresh=true -c reset.quiet=true" ' test_expect_success '--mixed preserves skip-worktree' ' From patchwork Tue Mar 15 01:49:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victoria Dye X-Patchwork-Id: 12780955 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D8A50C433FE for ; Tue, 15 Mar 2022 01:49:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344302AbiCOBvE (ORCPT ); Mon, 14 Mar 2022 21:51:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49018 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344234AbiCOBu6 (ORCPT ); Mon, 14 Mar 2022 21:50:58 -0400 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B1BE1EACF for ; Mon, 14 Mar 2022 18:49:47 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id j26so26777218wrb.1 for ; Mon, 14 Mar 2022 18:49:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=+D8F6NuLashoR0A4E60KGw0SkrTIzukOlk7zDCUYXNc=; b=L2t/53oKck82URgsPzUSgGbUtqo3YOw+jv9vhxcNl/fA73aXf40/2wESSybxlYS9B4 TLW4BF3yBq8tMnfK6IMN4CNS7k74DHHPsAmumYzsGOQ06lZ1SV1qm37H6WNZOqkVvufH JdqDBppeeB/f0pg+swiwXslmdY+86oEnB0tke+vVH7Yhs/TvaXaCL8xiviIQfXXb3ZPM S37UUaj+9z8ZozvVdD019YqC9WKKqNtDcEd86X+vPn/vH4P0FAuIChfLJ4SWCNWit6A3 L4HIqPsySQihltsHgaFzNtccVF39o1gRFjeecP/ydMKRHLsDB16zcZkXeBhWVMCj0wRy 9bTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=+D8F6NuLashoR0A4E60KGw0SkrTIzukOlk7zDCUYXNc=; b=MaM1MVuYHm56fkLFVs47WMwhg3+WJtravEdR4ix7BH8cUoRybJrZhkECNryZW/CtM6 zGzbA2MgX13tyAQ7ToDtzFhwhFHi8adia+iXYJd6WdltFXYd6UwAnaOT/uh+/s1FDL4N thJyUFbtWN76b5ezfKBy4mcQU3D4Iq6C4X8rI9tsYc0IYhjk96tyZh8w4f+Smfpuoe8F uIhDpaLpFzJ/DP7yGEg+4T4zSNdpFincCSep4TuFdaQtBMjdlVGfasBX8K432R+Xc0xf 3OaQsECVFA9IFrQ6M6973THnEHwaFx9OHsV/Mjlu7JIaKo3aecEcCXUbvxpo1OM7lGP0 +nZQ== X-Gm-Message-State: AOAM532QQppCH6FgFtYV4NhQlcjLFKDZvPmIF7Viun5FJOfiXdwzAeT0 tGs4tFkq4vR3fbg1hP+MFm/hqH4Yqdk= X-Google-Smtp-Source: ABdhPJwMs61VvQehbWPFsh6EbIF2gMSsm6EA7QXnHhsm7nwgUgbr/Gxp8As9HAfE5gsCF8AAObOmRg== X-Received: by 2002:a5d:6244:0:b0:1e7:686d:41e7 with SMTP id m4-20020a5d6244000000b001e7686d41e7mr18173595wrv.491.1647308985935; Mon, 14 Mar 2022 18:49:45 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id i11-20020a05600c354b00b00389f440512esm899839wmq.32.2022.03.14.18.49.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Mar 2022 18:49:45 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Tue, 15 Mar 2022 01:49:40 +0000 Subject: [PATCH v3 3/5] reset: replace '--quiet' with '--no-refresh' in performance advice Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: derrickstolee@github.com, Victoria Dye , Victoria Dye Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Victoria Dye From: Victoria Dye Replace references to '--quiet' with '--no-refresh' in the advice on how to skip refreshing the index. When the advice was introduced, '--quiet' was the only way to avoid the expensive 'refresh_index(...)' at the end of a mixed reset. After introducing '--no-refresh', however, '--quiet' became only a fallback option for determining refresh behavior, overridden by '--[no-]refresh' or 'reset.refresh' if either is set. To ensure users are advised to use the most reliable option for avoiding 'refresh_index(...)', replace recommendation of '--quiet' with '--[no-]refresh'. Signed-off-by: Victoria Dye --- Documentation/config/advice.txt | 8 ++++---- advice.c | 2 +- advice.h | 2 +- builtin/reset.c | 8 ++++---- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Documentation/config/advice.txt b/Documentation/config/advice.txt index 971aad2f237..83c2a956611 100644 --- a/Documentation/config/advice.txt +++ b/Documentation/config/advice.txt @@ -67,10 +67,10 @@ advice.*:: commitBeforeMerge:: Advice shown when linkgit:git-merge[1] refuses to merge to avoid overwriting local changes. - resetQuiet:: - Advice to consider using the `--quiet` option to linkgit:git-reset[1] - when the command takes more than 2 seconds to refresh the index - after reset. + resetNoRefresh:: + Advice to consider using the `--no-refresh` option to + linkgit:git-reset[1] when the command takes more than 2 seconds + to refresh the index after reset. resolveConflict:: Advice shown by various commands when conflicts prevent the operation from being performed. diff --git a/advice.c b/advice.c index 2e1fd483040..cb755c551a2 100644 --- a/advice.c +++ b/advice.c @@ -61,7 +61,7 @@ static struct { [ADVICE_PUSH_NON_FF_MATCHING] = { "pushNonFFMatching", 1 }, [ADVICE_PUSH_UNQUALIFIED_REF_NAME] = { "pushUnqualifiedRefName", 1 }, [ADVICE_PUSH_UPDATE_REJECTED] = { "pushUpdateRejected", 1 }, - [ADVICE_RESET_QUIET_WARNING] = { "resetQuiet", 1 }, + [ADVICE_RESET_NO_REFRESH_WARNING] = { "resetNoRefresh", 1 }, [ADVICE_RESOLVE_CONFLICT] = { "resolveConflict", 1 }, [ADVICE_RM_HINTS] = { "rmHints", 1 }, [ADVICE_SEQUENCER_IN_USE] = { "sequencerInUse", 1 }, diff --git a/advice.h b/advice.h index a3957123a16..f95af70ced4 100644 --- a/advice.h +++ b/advice.h @@ -36,7 +36,7 @@ struct string_list; ADVICE_PUSH_UPDATE_REJECTED_ALIAS, ADVICE_PUSH_UPDATE_REJECTED, ADVICE_PUSH_REF_NEEDS_UPDATE, - ADVICE_RESET_QUIET_WARNING, + ADVICE_RESET_NO_REFRESH_WARNING, ADVICE_RESOLVE_CONFLICT, ADVICE_RM_HINTS, ADVICE_SEQUENCER_IN_USE, diff --git a/builtin/reset.c b/builtin/reset.c index 7f667e13d71..feab85e03de 100644 --- a/builtin/reset.c +++ b/builtin/reset.c @@ -535,10 +535,10 @@ int cmd_reset(int argc, const char **argv, const char *prefix) refresh_index(&the_index, flags, NULL, NULL, _("Unstaged changes after reset:")); t_delta_in_ms = (getnanotime() - t_begin) / 1000000; - if (advice_enabled(ADVICE_RESET_QUIET_WARNING) && t_delta_in_ms > REFRESH_INDEX_DELAY_WARNING_IN_MS) { - advise(_("It took %.2f seconds to refresh the index after reset. You can\n" - "use '--quiet' to avoid this. Set the config setting reset.quiet to true\n" - "to make this the default."), t_delta_in_ms / 1000.0); + if (advice_enabled(ADVICE_RESET_NO_REFRESH_WARNING) && t_delta_in_ms > REFRESH_INDEX_DELAY_WARNING_IN_MS) { + advise(_("It took %.2f seconds to refresh the index after reset. You can use\n" + "'--no-refresh' to avoid this. Set the config setting reset.refresh to false\n" + "to make this the default."), t_delta_in_ms / 1000.0); } } } else { From patchwork Tue Mar 15 01:49:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victoria Dye X-Patchwork-Id: 12780957 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4C83FC433EF for ; Tue, 15 Mar 2022 01:49:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241538AbiCOBvG (ORCPT ); Mon, 14 Mar 2022 21:51:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344243AbiCOBu7 (ORCPT ); Mon, 14 Mar 2022 21:50:59 -0400 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 586DF10FFB for ; Mon, 14 Mar 2022 18:49:48 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id bg31-20020a05600c3c9f00b00381590dbb33so595439wmb.3 for ; Mon, 14 Mar 2022 18:49:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=837qGVpXFZzM+0YUSLB3JsjOQ4eE6KaJGG+jcxv7f0o=; b=fuok133nJCseS2SveuR7EkwZl8C3RlQxR5PvkmzR3eVgi3PH3ej+4MyLVUNt8Shu+f SOfuB55zHO3VxbhL6vnYSv9EfK2UTU6tspCwiyfScihS358Ty2y8X1OfMz6C4YB5b8qc h6f1rP7rNA4dnj0ZampTSU2OIE0kxphJCnpXVucz2g+0PEhirVIt8cAS9q4e/O+wFUdA pG8NnwPVaBcXehN10MyTwHwYHe6JhXTZDQhZhNxcnrV/PUsgcnMA3k3ouwz2m5Pg4hjp ZslSaDSWwCMl+VspuZaRlF8z0l6CoKt15c+3oI7QWuYjg5RLkWUe2JX0eycVhtlrfmKE sm2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=837qGVpXFZzM+0YUSLB3JsjOQ4eE6KaJGG+jcxv7f0o=; b=ZlK0g2bOZXtGrwTQNVcc8BVK0N43ZI0jr/IhDkdGDCRrsYab9uvKSTQfhWQaA7iD4E LzluX7UqIpNjUxS1X9lm1byCm41z5yI7H/hZZQvR1+Ee/9oACB509vhRfn26uaqSB1fZ ayXlpCF3Ix1om4P9oc9IVrXkv2EQgS1VE6g3CPX4O/UMmNh0so/rc/5Q3cctU0Lp3wj1 m1xxDPWa20jbi8ckkSuKZzLX8hk0znd0WW8JA35RKrV2dD1Ll7rlPy/5lWfjzU3LTctZ XZsEd4rAhLCj2UvXgB74RCEdoKmQNicIjV/JilVf4V4yi3JlecxkPfZWj+T+UG26C5+1 Gt7Q== X-Gm-Message-State: AOAM531rjaYMFIACAkJqDnL1LenzFr2SGivmPc84N79nCXIJpD2O2EZY fM570dCcjFuWs3nA2A8tmLcOBBKtqGw= X-Google-Smtp-Source: ABdhPJx62+2vg6sZHiHvgoLl+ehqLdFkyE6J++rXIuI8+JIUvtgQ612/tvlmCNbuaV+RGN/duc3cwg== X-Received: by 2002:a05:600c:5108:b0:389:b089:291 with SMTP id o8-20020a05600c510800b00389b0890291mr1348238wms.109.1647308986638; Mon, 14 Mar 2022 18:49:46 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id l1-20020a05600c4f0100b00387369f380bsm924035wmq.41.2022.03.14.18.49.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Mar 2022 18:49:46 -0700 (PDT) Message-Id: <548c9303c448f85b4c1c5db44886b8b9b7b44db5.1647308982.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 15 Mar 2022 01:49:41 +0000 Subject: [PATCH v3 4/5] reset: suppress '--no-refresh' advice if logging is silenced Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: derrickstolee@github.com, Victoria Dye , Victoria Dye Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Victoria Dye From: Victoria Dye If using '--quiet' or 'reset.quiet=true', do not print the 'resetnoRefresh' advice string. For applications that rely on '--quiet' disabling all non-error logs, the advice message should be suppressed accordingly. Signed-off-by: Victoria Dye --- builtin/reset.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin/reset.c b/builtin/reset.c index feab85e03de..c8a356ec5b0 100644 --- a/builtin/reset.c +++ b/builtin/reset.c @@ -535,7 +535,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix) refresh_index(&the_index, flags, NULL, NULL, _("Unstaged changes after reset:")); t_delta_in_ms = (getnanotime() - t_begin) / 1000000; - if (advice_enabled(ADVICE_RESET_NO_REFRESH_WARNING) && t_delta_in_ms > REFRESH_INDEX_DELAY_WARNING_IN_MS) { + if (!quiet && advice_enabled(ADVICE_RESET_NO_REFRESH_WARNING) && t_delta_in_ms > REFRESH_INDEX_DELAY_WARNING_IN_MS) { advise(_("It took %.2f seconds to refresh the index after reset. You can use\n" "'--no-refresh' to avoid this. Set the config setting reset.refresh to false\n" "to make this the default."), t_delta_in_ms / 1000.0); From patchwork Tue Mar 15 01:49:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victoria Dye X-Patchwork-Id: 12780958 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E3233C433FE for ; Tue, 15 Mar 2022 01:49:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344307AbiCOBvH (ORCPT ); Mon, 14 Mar 2022 21:51:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232835AbiCOBu7 (ORCPT ); Mon, 14 Mar 2022 21:50:59 -0400 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10C31140CE for ; Mon, 14 Mar 2022 18:49:49 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id r4-20020a1c4404000000b0038a12987e21so572583wma.4 for ; Mon, 14 Mar 2022 18:49:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=khn7ErIy9kZJToPTZjqCZeka4sIae8cQ3dxGq3E+IF8=; b=YljWvAAWu69eSVmMxltfh+dUHrs12XX1tiv2jPz9EWMNGhVKAqPy/LUKD6X7i207JG xQHjoLtr6lWlq6bdum9O07FyfD2XcHGPsUJEUu92tSLjBSMD2TMmD0yquxITsCfKdWqb +YmcenCCxK1vQbWVo/ciqjruCyY/1FTeNSBqjBbogAMWQiv9ftERP+TSl06Hxx9M+Ow2 7tIH1GlEP9ZFyKkGd1ttjJZj2s5DGXkc3QJAaMtY++OPVAf1v0L6dUZm58Wt4jBgGTAZ oNGO8KA5MkUrrzVJMEy1kMVCw4kam6e2xSqt5jec2LAoC78axjkYsl1hia9n9UmDId+T /p8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=khn7ErIy9kZJToPTZjqCZeka4sIae8cQ3dxGq3E+IF8=; b=fPY9vHM/4SCGW1XfNTSi+1DPyIAiPCb2/whWkn2otiu7fOFs97jLFqlyq5dD4FI/k3 DQi75uMAPoB1rzg8Z57aFMWgSIKEK3owbinbL+vdhogMqFkrDPustGCXcw01dZlLk1HS fRLipcYGj4AzOcZ9QfuSk7VEz1n0w455QWY1jFIH9nxYRAfYT+UCVp5SE3GNxH6t2pQm 3bpgUXy4yWzWi3mpmf+cw8ZCVRGvGwGigskSDx5q5Rwl2yOokyvlmKBpX0SHbcumWP3G bx5JzQqh0BITPjAfFeBNLPjaTB3ZdF/8YiV+btBBtI4MNug1Ceo5lBuHl3W56PMGCToI DJQw== X-Gm-Message-State: AOAM530P/e3vRYDx8xsa6DhQWma4sjh0AKN7rVX1ygNYiPLhyYKb/huO e2KZKU2oukcJpRzSsPvJAgbDQUwxE28= X-Google-Smtp-Source: ABdhPJwwIjq7JBMyaQ3Ul7EW3mkVMcalFTR1OjPTf8hG6eLjxJ9fNygIjHHx+JLoLu9JjGaNO+SODA== X-Received: by 2002:a05:600c:3203:b0:381:b544:7970 with SMTP id r3-20020a05600c320300b00381b5447970mr1366651wmp.144.1647308987503; Mon, 14 Mar 2022 18:49:47 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id m128-20020a1ca386000000b003898b148bf0sm884229wme.20.2022.03.14.18.49.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Mar 2022 18:49:47 -0700 (PDT) Message-Id: <4c45351a0c4b8b955a9101ed9445a763750ca3c3.1647308982.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 15 Mar 2022 01:49:42 +0000 Subject: [PATCH v3 5/5] stash: make internal resets quiet and refresh index Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: derrickstolee@github.com, Victoria Dye , Victoria Dye Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Victoria Dye From: Victoria Dye Add the options '-q' and '--refresh' to the 'git reset' executed in 'reset_head()', and '--refresh' to the 'git reset -q' executed in 'do_push_stash(...)'. 'stash' is implemented such that git commands invoked as part of it (e.g., 'clean', 'read-tree', 'reset', etc.) have their informational output silenced. However, the 'reset' in 'reset_head()' is *not* called with '-q', leading to the potential for a misleading printout from 'git stash apply --index' if the stash included a removed file: Unstaged changes after reset: D Not only is this confusing in its own right (since, after the reset, 'git stash' execution would stage the deletion in the index), it would be printed even when the stash was applied with the '-q' option. As a result, the messaging is removed entirely by calling 'git status' with '-q'. Additionally, because the default behavior of 'git reset -q' is to skip refreshing the index, but later operations in 'git stash' subcommands expect a non-stale index, enable '--refresh' as well. Helped-by: Junio C Hamano Signed-off-by: Victoria Dye --- builtin/stash.c | 5 +++-- t/t3903-stash.sh | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/builtin/stash.c b/builtin/stash.c index 3e8af210fde..91407d9bbe0 100644 --- a/builtin/stash.c +++ b/builtin/stash.c @@ -310,7 +310,7 @@ static int reset_head(void) * API for resetting. */ cp.git_cmd = 1; - strvec_push(&cp.args, "reset"); + strvec_pushl(&cp.args, "reset", "--quiet", "--refresh", NULL); return run_command(&cp); } @@ -1633,7 +1633,8 @@ static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q struct child_process cp = CHILD_PROCESS_INIT; cp.git_cmd = 1; - strvec_pushl(&cp.args, "reset", "-q", "--", NULL); + strvec_pushl(&cp.args, "reset", "-q", "--refresh", "--", + NULL); add_pathspecs(&cp.args, ps); if (run_command(&cp)) { ret = -1; diff --git a/t/t3903-stash.sh b/t/t3903-stash.sh index f36e121210e..1a5c1bd3109 100755 --- a/t/t3903-stash.sh +++ b/t/t3903-stash.sh @@ -261,6 +261,18 @@ test_expect_success 'apply -q is quiet' ' test_must_be_empty output.out ' +test_expect_success 'apply --index -q is quiet' ' + # Added file, deleted file, modified file all staged for commit + echo foo >new-file && + echo test >file && + git add new-file file && + git rm other-file && + + git stash && + git stash apply --index -q >output.out 2>&1 && + test_must_be_empty output.out +' + test_expect_success 'save -q is quiet' ' git stash save --quiet >output.out 2>&1 && test_must_be_empty output.out @@ -291,6 +303,27 @@ test_expect_success 'drop -q is quiet' ' test_must_be_empty output.out ' +test_expect_success 'stash push -q --staged refreshes the index' ' + git reset --hard && + echo test >file && + git add file && + git stash push -q --staged && + git diff-files >output.out && + test_must_be_empty output.out +' + +test_expect_success 'stash apply -q --index refreshes the index' ' + echo test >other-file && + git add other-file && + echo another-change >other-file && + git diff-files >expect && + git stash && + + git stash apply -q --index && + git diff-files >actual && + test_cmp expect actual +' + test_expect_success 'stash -k' ' echo bar3 >file && echo bar4 >file2 &&