From patchwork Sat Mar 12 00:08:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victoria Dye X-Patchwork-Id: 12778665 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 6B0B1C433EF for ; Sat, 12 Mar 2022 00:08:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229711AbiCLAKA (ORCPT ); Fri, 11 Mar 2022 19:10:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35012 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229662AbiCLAJ7 (ORCPT ); Fri, 11 Mar 2022 19:09:59 -0500 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 BD2DD2272C0 for ; Fri, 11 Mar 2022 16:08:53 -0800 (PST) Received: by mail-wr1-x42a.google.com with SMTP id t11so15200299wrm.5 for ; Fri, 11 Mar 2022 16:08:53 -0800 (PST) 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=N1UZ4b4kNCG5MQ7DOblNnbP7KH/VJMAJn8E+sdPKOOmp4Tm9yClXUV3gwk0paW8DM0 3dCUqOCKUamlDGH43Pt9zUrqpIQaYi1AO/LvU8XEa+3hOwLP3i24zG9lSXsHaE3GkIUS mQBgpqUj02thHGI7VKoby+i4z3nQ0TOmwP/vFl3xk6BnCbp4P1msj+tGDAZnHinmN8X8 CUJ8NIPa3aF2xn9v9HqSbZPoQ7IcjEfXyH1GuFIHd8nhqHX/1oXjM5udEnz9RWBCRGB2 s66iG/m9zX+2IgBFS3ht6ndfntmMSimhMiw6NWk/Gasw1jeGe4PhKYlwD72VqYPUy42I Jynw== 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=0oXZEyYSgWvr/l7k2ovSjTJ/vSW9G4cCQafu54YEXBvc8t7ugKV9CqWGyEV45CDKl8 KrvibaW18jQhLG0QfGVq/3qE+3rWD5Vmo/yLTwhf/kqtx42mfzo54krwamZPjsDNlPc8 C8t6XrAFFap3gx51m6VFAeaSUgzP4smg0wci2/Cq3LK78MIxamxC5DpNRA0Ijx8kG3d9 91WO/M3cpPDmU3tJwNhwNKtfmDYPQfu0auVan2ejZhYG/YZR1QhOJ/z/bG8BjAp0f+Mm ih+gA5iT/hUkAn/Y9gsGvHpj1aCF8LxpPtZGlzYM6/C8Ig+OSgppnmtERV4VKa7vBCFJ uRAw== X-Gm-Message-State: AOAM532c6EiDVHwAGYXX0KQDIU4VJwM9sJ1xWLrfkK1bLNGdD+52ZjBS BWS+WoN9pIOI5NYe5X1VcxJ/QZbYlT4= X-Google-Smtp-Source: ABdhPJxWnCF95PY3LP8KsqI6G6N6AxKBW1GWxPaYzAF7EDJNIV807/cdpw4HOVsKrwpH/viaHWV2Vg== X-Received: by 2002:a5d:4441:0:b0:1f0:882d:77e9 with SMTP id x1-20020a5d4441000000b001f0882d77e9mr8791526wrr.718.1647043732035; Fri, 11 Mar 2022 16:08:52 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id c11-20020a05600c0a4b00b0037c91e085ddsm14110488wmq.40.2022.03.11.16.08.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Mar 2022 16:08:51 -0800 (PST) Message-Id: <7206ef8dd8ab088feab841c5574d486b6f19af5e.1647043729.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Sat, 12 Mar 2022 00:08:45 +0000 Subject: [PATCH 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 Sat Mar 12 00:08:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victoria Dye X-Patchwork-Id: 12778666 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 1CAB4C433F5 for ; Sat, 12 Mar 2022 00:09:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229728AbiCLAKB (ORCPT ); Fri, 11 Mar 2022 19:10:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35070 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229681AbiCLAJ7 (ORCPT ); Fri, 11 Mar 2022 19:09:59 -0500 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A17CF2272C4 for ; Fri, 11 Mar 2022 16:08:54 -0800 (PST) Received: by mail-wr1-x42d.google.com with SMTP id p9so15169820wra.12 for ; Fri, 11 Mar 2022 16:08:54 -0800 (PST) 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=DspDRb6NZBmohCcSNRq0bTEHDzymCAfESSKeqqjCETY=; b=gKihNj1bhuaagbM7N9hYZkwBZ6rkW2BnLkxGyQAQL1ku6J1prp2KuQlrHNEpiOXBlz dT5wML6J3Zn94YfEwJRXMSDsOyqWeXZLgm+6WzOYJjkOvPw5oAglVmefh34XuMKPK/0J LKZQwF8DnPorRokrMmSREviohLjm1powKm1vMyu+msqnClklrRkw5Ot3TWCrhpLLFhMH J2f5gp46q6XM41oq/PjZSzCRhUwAMRm+Cvrecw4d7SsT0YQpUMjVKyMfFAbcx3870BLe w3sHe7z5X0eqKoplBiJZ/HXHQE1DqX6nTj8QYCPZoGvOb4D56JVXMpRRmS43fhjmgFQR BuDA== 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=DspDRb6NZBmohCcSNRq0bTEHDzymCAfESSKeqqjCETY=; b=m+5/JRrk8C/Yoz8+p6E9dkHpPbdgHR9OHhE4q5ClUwPbi+xDvs9Xu0t1Ak+fNUqPoS vGzvs4u3MqEVjR/7K+yS993yyIZQYyR+gJP+yPy3HwQ0LC/ckv5cpPH9BMSWmn35WpWa g8o/GT9L2FyCyZ2o0KUCsqNI1q5xsHpjbm7xaQiyMVu6A/lFNFNPHGjOxQZ3aUmDY/p5 kic6gKncABtSnbVEQbxr9EqQlTn1WyQfyV54uQPwxblNzGxQo0LjWQNGjCJZyekgMgg4 Rwhs5NfQamxdHAXG9AlbCsYySjrcehL2I1cUd5JgBkvVrb/JAuatMLjoJeeNLDhNebox lk5A== X-Gm-Message-State: AOAM533GNIn/5GMq92NU0Sq0Ei3XiVsAtf4ChTj8wP4lbee73Eac/831 PMvznN/F6gNHpIaM+kDpJR7tTlWoNZs= X-Google-Smtp-Source: ABdhPJyGQP454JgrGbHSGaRNbADR1+YRA6McIKiJxhmwWgqMwGAEMlQ1OrEAnZh9CEy/5HViZFkJng== X-Received: by 2002:a5d:4b85:0:b0:1f0:9661:9263 with SMTP id b5-20020a5d4b85000000b001f096619263mr8846122wrt.574.1647043732996; Fri, 11 Mar 2022 16:08:52 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id l10-20020a7bc44a000000b003899263bab1sm7971995wmi.20.2022.03.11.16.08.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Mar 2022 16:08:52 -0800 (PST) Message-Id: In-Reply-To: References: Date: Sat, 12 Mar 2022 00:08:46 +0000 Subject: [PATCH 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. A few years ago, [1] introduced behavior to the '--quiet' option to skip 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. [1] 9ac8125d1a (reset: don't compute unstaged changes after reset when --quiet, 2018-10-23) Signed-off-by: Victoria Dye --- Documentation/git-reset.txt | 9 +++++ builtin/reset.c | 13 ++++++- t/t7102-reset.sh | 77 +++++++++++++++++++++++++++++++++---- 3 files changed, 91 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..5e68180f3b2 100755 --- a/t/t7102-reset.sh +++ b/t/t7102-reset.sh @@ -462,14 +462,77 @@ test_expect_success 'resetting an unmodified path is a no-op' ' git diff-index --cached --exit-code HEAD ' +test_index_refreshed () { + + # To test whether the index is refresh, create a scenario where a + # command will fail if the index is *not* refreshed: + # 1. update the worktree to match HEAD & remove file2 in the index + # 2. reset --mixed to unstage the change from step 1 + # 3. read-tree HEAD~1 (which differs from HEAD in file2) + # If the index is refreshed in step 2, then file2 in the index will be + # up-to-date with HEAD and read-tree will succeed (thus failing the + # test). If the index is *not* refreshed, however, the staged deletion + # of file2 from step 1 will conflict with the changes from the tree read + # in step 3, resulting in a failure. + + # Step 0: start with a clean index + git reset --hard HEAD && + + # Step 1 + git rm --cached file2 && + + # Step 2 + git reset $1 --mixed HEAD && + + # Step 3 + git read-tree -m HEAD~1 +} + 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_index_refreshed && +' +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_must_fail test_index_refreshed -c reset.quiet=true && + test_index_refreshed -c reset.quiet=true && + + # Command line option + test_must_fail test_index_refreshed --quiet && + test_index_refreshed --no-quiet && + + # Command line option overrides config setting + test_must_fail test_index_refreshed -c reset.quiet=false --quiet && + test_index_refreshed -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_index_refreshed -c reset.refresh=true && + test_must_fail test_index_refreshed -c reset.refresh=false && + + # Command line option + test_index_refreshed --refresh && + test_must_fail test_index_refreshed --no-refresh && + + # Command line option overrides config setting + test_index_refreshed -c reset.refresh=false --refresh && + test_must_fail test_index_refreshed -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_index_refreshed --refresh --quiet && + test_index_refreshed --refresh -c reset.quiet=true && + test_index_refreshed -c reset.refresh=true --quiet && + test_index_refreshed -c reset.refresh=true -c reset.quiet=true ' test_expect_success '--mixed preserves skip-worktree' ' From patchwork Sat Mar 12 00:08:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victoria Dye X-Patchwork-Id: 12778667 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 EB81BC433EF for ; Sat, 12 Mar 2022 00:09:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229744AbiCLAKE (ORCPT ); Fri, 11 Mar 2022 19:10:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35154 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229448AbiCLAKA (ORCPT ); Fri, 11 Mar 2022 19:10:00 -0500 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A4A4226369 for ; Fri, 11 Mar 2022 16:08:55 -0800 (PST) Received: by mail-wm1-x330.google.com with SMTP id 7-20020a05600c228700b00385fd860f49so6281614wmf.0 for ; Fri, 11 Mar 2022 16:08:55 -0800 (PST) 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=I24vuiQJNGXyMyIstkcuhJXZT6Bih+lJmqobcklSEldyw6GbXMeyyB+EZNMqfHxlLa 5jzSh7Lz3cdGz8TI0B0gmqp3WXm3QCpD6nFbqs7u88pMDPWZ+K6miEnSAdBHKj36gv/v 75Is1mh8WChPjFlMjeNpepr6d57IPpn86E6xvVk+ok0tTw1Ja1xIZtGLm3lCJGbuVsid dsCi4xenHnmVmdJBUUMHCrwMlQn8Gk/LuwR+kEtzlguzsjOVrM1EfpVLQFQRpIukkeKk SKt5/YBvQ/Xw3RWFEu48lEf+ZIg8Dj6xgffU0eBHuFi1DWFzs2Z8NE5TVlI5/WAqGQ1r 6mhg== 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=IU4z6QbrH68Di9wTpQb2gDyBsGYvgq5ldkGy49D6HLStFsynhKQDTTDUmtT2+bl7S0 te87VlOosYU31U1yvw+PfMV1ChcfSErybwoES79NsX4z619254NLT3Zezrl+KKZDCKSH Ujf4Q0WCf/hBRMqJazN4qStnda8dcHmahuZ7nBhtdG9DcGSCN1LgB+ZskaC4wbyFHXFj xVQtUlf7sZt4C9h8+81SQdaYXlaiR0nZGsJAFJ5MSg30192h4Hmwo3WycSAqZXyi4lWn iU8BZe87qNNI/Zs8wft/m5OE4M/j4+WxFIdRMjSsHIXX4UKdexYiQPR6566wVNhZhjS0 kYfQ== X-Gm-Message-State: AOAM5337sdlP9d//q6VCtLG0/HoZ9Q1K8rpvXFJxkkvku457HV2xKIWZ myOXE8fHm/RK4pYBOtYl26EkT4lXgLg= X-Google-Smtp-Source: ABdhPJyDxNfs+tnZz7u4eGtCVQFrA5YtwMfMrt0ToQLpsiAzPwk9b0XiPsufmUpjfQkAdecix9kDQA== X-Received: by 2002:a7b:c08b:0:b0:385:8748:5665 with SMTP id r11-20020a7bc08b000000b0038587485665mr8959217wmh.173.1647043733810; Fri, 11 Mar 2022 16:08:53 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id i186-20020a1c3bc3000000b00382b25f6c9fsm8839759wma.42.2022.03.11.16.08.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Mar 2022 16:08:53 -0800 (PST) Message-Id: <63c5ee36feb38ed192f4c60bb1c1c46a9a7a6b89.1647043729.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Sat, 12 Mar 2022 00:08:47 +0000 Subject: [PATCH 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 Sat Mar 12 00:08:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victoria Dye X-Patchwork-Id: 12778668 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 B59EDC433F5 for ; Sat, 12 Mar 2022 00:09:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229761AbiCLAKH (ORCPT ); Fri, 11 Mar 2022 19:10:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35186 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229716AbiCLAKB (ORCPT ); Fri, 11 Mar 2022 19:10:01 -0500 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 18BBD2272DA for ; Fri, 11 Mar 2022 16:08:56 -0800 (PST) Received: by mail-wr1-x42b.google.com with SMTP id u10so15208332wra.9 for ; Fri, 11 Mar 2022 16:08:56 -0800 (PST) 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=OO18tJjhNZuJRM29oVvg2jOXGCnEKzU0wSuug/VEvtanwyb3hanZm5TVCnHrK6N4DN J7BLTN3rtOTieT1ALewiQtMrF54OmQk0ZRjvLerK1l5EJ+dZRaP9mKHse/NVGSpKPo4Z wpVA4CXmcQEF8xfNCuOPQcc4cHReWTkck9E5Wjd/KgdQJ2J2EOa00IXTmSKqkacKB6h/ 5VzvRJN66zayXvTWL0W72s98OEljtRaa9JKhb4CiaEzJ6JB8RZ780SaVQQFUIxs15SGf 17PR9IYarS9oUpDtSK0Tf2tNFjvrVRiB+5fY/l46ft6Y4Z5t068c9nP8seF6DWH02Nlu bR1A== 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=hLpJ41DLffIsUV6Ivduo0OM/Z7VZWzoXJOYO+kqSsQqY9J4HAlaTlN6tXt7CCjfpUu MXKXg1ltDt/znSZsgCRGs+J3Ox3+eRm+gPR3Yzi8rYeZ5Gr4noIZfEBW6m/YQJBDmCI/ exG8H1mOoGLHtYiwxpYeF2o9JOjkOGB8QnrXYDMcYmlgsV/qB8mM30yW1qeBx2aI5tUx LfhDDf7HXu133KwAjlRsiGe/tQ6NlChky5gpBpK7syeRv6dy2QLLRhmoxL5ffaF5v1Xt n1iUro3ypP5COfljzxeMQJwn305URMCDcZMlmYoTmE8tJDD2BykQ0BVijVuiihcoDoAs ozRg== X-Gm-Message-State: AOAM533u/W5KrGB6ju3Psmon2Y6e6fHBEvSOhpc5N/0hxBgXZl68pnOz 5I/LLRtq3Th0CUHBc2KzcKlgZhgve3I= X-Google-Smtp-Source: ABdhPJzOPWOYkCV+vhvxkH8JMugGSlK0EobhqkbM9ZwI7MqJxHOqclAK/5aF5PSG0Yf9lQN4CV9ORw== X-Received: by 2002:adf:b1da:0:b0:1f0:1205:89c1 with SMTP id r26-20020adfb1da000000b001f0120589c1mr8729778wra.27.1647043734516; Fri, 11 Mar 2022 16:08:54 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id m34-20020a05600c3b2200b00380e3225af9sm8697962wms.0.2022.03.11.16.08.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Mar 2022 16:08:54 -0800 (PST) Message-Id: <3c65a9f19936548883522a4795048a7cf756c6bd.1647043729.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Sat, 12 Mar 2022 00:08:48 +0000 Subject: [PATCH 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 Sat Mar 12 00:08:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victoria Dye X-Patchwork-Id: 12778669 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 715C8C433FE for ; Sat, 12 Mar 2022 00:09:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229735AbiCLAKH (ORCPT ); Fri, 11 Mar 2022 19:10:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35312 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229681AbiCLAKD (ORCPT ); Fri, 11 Mar 2022 19:10:03 -0500 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E77CB2272E9 for ; Fri, 11 Mar 2022 16:08:56 -0800 (PST) Received: by mail-wr1-x431.google.com with SMTP id q14so15240824wrc.4 for ; Fri, 11 Mar 2022 16:08:56 -0800 (PST) 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=G8iZRRwMTxy0bYpRI49zaPbtptzDjIEH6Cj3OnBPU5c=; b=hgcwO7X1uTY18T0ZqTPTeOG4ota23EnAbOiQTLyP9NUfRQBw/7ZunTIXV9LGcdEyNH Ym/hhay2knLB2Kr0zbe6PmjnIG7+mRP1oPWS49CgxTMMJ9m4kZ/Vmyuet+rZJTFAkVWM yxXvCkMqOEHF6CsXh4m4W9clvM+QVM87z2VeVVladsUjJ5mGpIZC7AJ73jcFcb4DfAE+ O+Cnywp0bkhqhNselYZZGoxCuJDIEeOG5Xg1cCmJXGHQeh8y6bAmPFTr0nK7oIiDvQ2D m2cmQl5IDo2d/VWomfB8H1x/XzIjY6uXTqY0upzTdiUvRxwvu76jhZyZEruWE0yCkOAc 1CGg== 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=G8iZRRwMTxy0bYpRI49zaPbtptzDjIEH6Cj3OnBPU5c=; b=bzRheqmNI4d63ZlWKTwFfm56w/bL7BzGNclVkcnM9zrNwbSDFYJUQk3uXNiudthfhF WVWLcIu7Z4HVyFdiQJM3oB/M1Y5M+jFcvnZy7xT+8UjeXQVMTN2rPdL35lhzRJL4i7cn qJBhWHPnIj64OVMTHkuOVFdMQ7u78GgNpHnJc+YMAleEIgUbkbXech9jwweJA/ajnlAU s/p4WWKNghG96qewQYROIz3eVcb1RFZTRcswMLsDg/TRnsnDqx4tbUWQMM28RX6kKuWm Wn5AXwlbmgUZTMx7/6WAmP490KccRIgNsiUcxqQ+TNTyGRWOiEmmdxS8PYQmMTenwUbv +U2Q== X-Gm-Message-State: AOAM531Xf2atROWj8xN7/MDHghXHvcXztmxLtkENxw+mrze0EP0PuRvT NUyr85faSzvR4V1diJuHV+B/bmy22hg= X-Google-Smtp-Source: ABdhPJwvKKMYT8YM0NpAG5eE9cw/iQl3lxg0fmil7yKo9P0dE4tnjBfZlyfPttpFwmiGyd6U1+XtcA== X-Received: by 2002:a5d:588a:0:b0:1f1:e6fb:4e7 with SMTP id n10-20020a5d588a000000b001f1e6fb04e7mr9023531wrf.716.1647043735271; Fri, 11 Mar 2022 16:08:55 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id p18-20020adfba92000000b001e4ae791663sm8121653wrg.62.2022.03.11.16.08.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Mar 2022 16:08:54 -0800 (PST) Message-Id: <052499bbc93cb6a60a3b7f7861de78dd4075fd7f.1647043729.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Sat, 12 Mar 2022 00:08:49 +0000 Subject: [PATCH 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. Signed-off-by: Victoria Dye --- builtin/stash.c | 5 ++-- t/t3903-stash.sh | 12 ++++++++++ t/t7102-reset.sh | 60 +++++++++++++++++++++++++++++++----------------- 3 files changed, 54 insertions(+), 23 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..17f2ad2344c 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 diff --git a/t/t7102-reset.sh b/t/t7102-reset.sh index 5e68180f3b2..f2076545133 100755 --- a/t/t7102-reset.sh +++ b/t/t7102-reset.sh @@ -482,7 +482,7 @@ test_index_refreshed () { git rm --cached file2 && # Step 2 - git reset $1 --mixed HEAD && + git reset $@ --mixed HEAD && # Step 3 git read-tree -m HEAD~1 @@ -491,48 +491,66 @@ test_index_refreshed () { test_expect_success '--mixed refreshes the index' ' # Verify default behavior (with no config settings or command line # options) - test_index_refreshed && + test_index_refreshed ' 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_must_fail test_index_refreshed -c reset.quiet=true && - test_index_refreshed -c reset.quiet=true && - # Command line option - test_must_fail test_index_refreshed --quiet && + ! test_index_refreshed --quiet && test_index_refreshed --no-quiet && - # Command line option overrides config setting - test_must_fail test_index_refreshed -c reset.quiet=false --quiet && - test_index_refreshed -c reset.refresh=true --no-quiet + # Config: reset.quiet=false + test_config reset.quiet false && + ( + test_index_refreshed && + ! test_index_refreshed --quiet + ) && + + # Config: reset.quiet=true + test_config reset.quiet true && + ( + ! test_index_refreshed && + test_index_refreshed --no-quiet + ) ' test_expect_success '--mixed --[no-]refresh sets refresh behavior' ' # Verify that --[no-]refresh and `reset.refresh` control index refresh - # Config setting - test_index_refreshed -c reset.refresh=true && - test_must_fail test_index_refreshed -c reset.refresh=false && - # Command line option test_index_refreshed --refresh && - test_must_fail test_index_refreshed --no-refresh && + ! test_index_refreshed --no-refresh && + + # Config: reset.refresh=false + test_config reset.refresh false && + ( + ! test_index_refreshed && + test_index_refreshed --refresh + ) && - # Command line option overrides config setting - test_index_refreshed -c reset.refresh=false --refresh && - test_must_fail test_index_refreshed -c reset.refresh=true --no-refresh + # Config: reset.refresh=true + test_config reset.refresh true && + ( + test_index_refreshed && + ! test_index_refreshed --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_index_refreshed --refresh --quiet && - test_index_refreshed --refresh -c reset.quiet=true && - test_index_refreshed -c reset.refresh=true --quiet && - test_index_refreshed -c reset.refresh=true -c reset.quiet=true + + # Config: reset.quiet=true + test_config reset.quiet true && + test_index_refreshed --refresh && + + # Config: reset.quiet=true, reset.refresh=true + test_config reset.refresh true && + test_index_refreshed ' test_expect_success '--mixed preserves skip-worktree' '