From patchwork Mon Mar 14 16:10:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victoria Dye X-Patchwork-Id: 12780353 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 67F43C433F5 for ; Mon, 14 Mar 2022 16:10:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242911AbiCNQLt (ORCPT ); Mon, 14 Mar 2022 12:11:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234683AbiCNQLp (ORCPT ); Mon, 14 Mar 2022 12:11:45 -0400 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6EF183E0C3 for ; Mon, 14 Mar 2022 09:10:34 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id q14so24816189wrc.4 for ; Mon, 14 Mar 2022 09:10:34 -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=aQkX0YNrVYXzP5v/GUAxfLm+vZWO4sh74cMFLEUsNRZbYPnK7phWKdyS2C6E/MqN+R +J2uv6KHc0PS/Q5hHSJR84tPAyogjvskeosM7apa0tuv9xgSFAlek7xz7kH6Msd+V994 a25LT6CbOIK0umw3KNxPp22HJi8y0NpS8iJYLRl5U7Ed44EU2lmAiBYriBmzr6DX8kxt ziif0aMwjXtDYR306f3QnR1wMb17Bczk0TiP6z9YnbGUDO7h44lNX1NwWIqWS4VdD0dM DKQbzCEfzY/9H0S+u9Vi8Lm0GTXt25/i26M7mmkUhponYh0bPDFGrlitvm8HEddoSuwg Drsg== 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=h/4Z0qeVXH8VgrTX7HWbK9qLEDiHLed++NhRTbK/pFcZl4/deJ/impH5ni7wNzjgeT Je6U2RYnArWOXM92cA6DbJSnyrjT3SxyzzlYmPxiXCQGBHEL7Xk781P5RQw5RPsYkkud dq3NldH2TyLye4AF5PMh4WKp1NaxTCMQrZuwzW1zzScfTt3LgFsoWxCpN/UitXN/haPk 3u1ASgt6SlY5hkVcGhmkq6sLuP/wEXGACWpDwbUh2DVbq1yJJg9ft6OlAJUAj5vqjhiY pP4GAJWgM6iMCzU28gcR2VsPsHHfzerN57Ad4gcedJGlV4m+LB4NUvw3Lor3PzIrSthy mGIQ== X-Gm-Message-State: AOAM532SgP9fRp3ZPXbfWTCK3qGlXNQvczgE6VQ18I02cKtAJ0F6AcKO WjF5Kp0G62/k2UrN7KZGjkeTv5OV1Qs= X-Google-Smtp-Source: ABdhPJwVVw2VuyPqfocdjIIkY3vrSxKtTGkGTQSTSzTATtgU3uryPP1QZ4m6b6d/AtxX+Kr0jF5asg== X-Received: by 2002:adf:e104:0:b0:1f1:d891:5aa6 with SMTP id t4-20020adfe104000000b001f1d8915aa6mr17156065wrz.582.1647274232818; Mon, 14 Mar 2022 09:10:32 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id a8-20020a05600c068800b00389bdc8c8c2sm14306436wmn.12.2022.03.14.09.10.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Mar 2022 09:10:32 -0700 (PDT) Message-Id: <7206ef8dd8ab088feab841c5574d486b6f19af5e.1647274230.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 14 Mar 2022 16:10:26 +0000 Subject: [PATCH v2 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 Mon Mar 14 16:10:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victoria Dye X-Patchwork-Id: 12780352 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 4ABABC433F5 for ; Mon, 14 Mar 2022 16:10:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242898AbiCNQLq (ORCPT ); Mon, 14 Mar 2022 12:11:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47268 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242868AbiCNQLp (ORCPT ); Mon, 14 Mar 2022 12:11:45 -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 68CFC3E0C9 for ; Mon, 14 Mar 2022 09:10:35 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id j26so24826443wrb.1 for ; Mon, 14 Mar 2022 09:10:35 -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=gsKzs7AJFyckwXhNdgglhBMpOVXFbOPZgH1AOJ2vYWo=; b=kbyMw+XkBzD0kG9KcRZDRMm5sjnmLPL1xlkJ1VngX2F1x8qAnjMEvTDz0Fvicd3Q9M wAMyVxTgc5t21L00hasKyCxHwTSHd3WKAjHZx4JdLYOtr298agNFQsf5cYEQhMVUZ4xI xCGW9/um1Y/4uxbU6JqBn2qyyU41ucNFnodKMCjPLOkJzMw4NDPpthLuMKkZu7aVKcD/ uaHAje9maVMR5t2ZsduRqJueysz2Xsz2FvCloWRRvbDysI+Bar4halBY/l+ANaIHFC+I T7MWK/iU7y/Hvc4wTnrvdn7QohMB2g8K7NFm7nj+AbXSsYxWRZZDE4MAl9Yy5nMsALkG 7JOA== 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=gsKzs7AJFyckwXhNdgglhBMpOVXFbOPZgH1AOJ2vYWo=; b=yGoBlWytF8Sibdx8jIawAN6jmwoIHnVHy+kRPK2/fmScn31E+bSF/coFDpvpV5MRsD GPyLrkXKVQW4W9lKM5D/z0jS6WlRrCSkaAwe+6WgqVTYoOWzQ+5VSzERIv6g5kMmhgEu ZTZKRbYgNh3Wv5jWHckJ2RS0+VAV1y3HnteFM1UoT+Fn73+cwJjB9u6fNLIi/TJ9TSW9 l53HPzKnb1rtq8sdpNSfOizMdI6XWpw06T3n3SCF9t5f/Atssp28X2yyCWXYXGBcblF9 FIMMF0axWA3IuWcZKFfhXvA2V6bxyU6DbeK8r4YlKx1J3uqeaWusU+QwWyryVfC6AMlz bT1Q== X-Gm-Message-State: AOAM530KVLN/Q/o6nUDXU9WS8QfZ3fiYFod8VMbrcp9IRjQWZqNcmtyE PPKzO1cojSwTMjYugx/Avb3xtbG3hkg= X-Google-Smtp-Source: ABdhPJzOgsYN+8WBgoAIdQyRnjh6i21bafLxKLnJskd5Uz0lnVFB3UiJz0TfVJ/8rKG99Qfjwohp3A== X-Received: by 2002:a5d:588d:0:b0:203:8c45:8050 with SMTP id n13-20020a5d588d000000b002038c458050mr15786571wrf.502.1647274233611; Mon, 14 Mar 2022 09:10:33 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id i74-20020adf90d0000000b0020373ba7beesm22259749wri.0.2022.03.14.09.10.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Mar 2022 09:10:33 -0700 (PDT) Message-Id: <7f0226bc3e646167808fbd2413dc54e87417230c.1647274230.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 14 Mar 2022 16:10:27 +0000 Subject: [PATCH v2 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 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..005940778b7 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 $1 reset $2 --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_index_refreshed "-c reset.quiet=true" && + test_index_refreshed "-c reset.quiet=false" && + + # Command line option + ! test_index_refreshed "" --quiet && + test_index_refreshed "" --no-quiet && + + # Command line option overrides config setting + ! 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_index_refreshed "-c reset.refresh=false" && + + # Command line option + test_index_refreshed "" --refresh && + ! test_index_refreshed "" --no-refresh && + + # Command line option overrides config setting + test_index_refreshed "-c reset.refresh=false" --refresh && + ! 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 "" "--quiet --refresh" && + test_index_refreshed "-c reset.quiet=true" --refresh && + 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 Mon Mar 14 16:10:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victoria Dye X-Patchwork-Id: 12780355 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 11C5DC433FE for ; Mon, 14 Mar 2022 16:10:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242912AbiCNQL7 (ORCPT ); Mon, 14 Mar 2022 12:11:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47306 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242900AbiCNQLr (ORCPT ); Mon, 14 Mar 2022 12:11:47 -0400 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 138833CFED for ; Mon, 14 Mar 2022 09:10:36 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id p9so24765493wra.12 for ; Mon, 14 Mar 2022 09:10:35 -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=L4M/GcjKded3TIupuazrZk2qZAFFqkAafZIjc7dR97OnWnfm0+oDhwQeJyr+Wlvua7 6TalSoB0d4l71gwA4dn1DesI0nuzwY86oU/pz8PaDVnumeok8zv0aduTT0P2khngiD5G pRmruSmB8AzX+3b1kdJdgmM9ut1rw0YVbZYPvP/X6LBGZqhNRrzev78ags0ArEN+yjEM ZbS8PbkYsBDWPPul1xyS0VCPP9jFzOOX7lZ3d+sK/frh9KirNxs78cHKSr1lzs4zOkQi 3AEYyflq6Um6F1HKpW5ntzX+hSqJGYMwxw3qd2x01fgcJH09g3lmRVMw12W6ncp25785 sBGw== 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=ENUteIHd+OusTOdGoUzLl7qynhR/WmLNrm84ibBCI/z5WsOFrBr1Y7MV4XATgwNDke jQFPggTTiHe/drHXBaslJlJhpXUKY0eU+J/NWVmbIfR94mZnn0yvuV58LepC2ivwTIw6 Z+y0pHg0GsGLoHSqeSXC9T0MexOI0871G4OQsXnmQTNE3X165vqxtBg6oY0pFdKdB+uS AkpskSPfWbfhpZmyID9GoQNd+RL5VzNJdb2Sn3iBuUSTAVk5MfI2BnDk9oE/EChG+VDU eKnrNiKgngwsg9LZCCMhRSxzqgcbiGCe8E2W/nQxOx/E6HHdzRjPAbPhXpP25tPm/MZN nntw== X-Gm-Message-State: AOAM533zwl2Y62yg+vOKPXdznM9LiT+EpI3zclAwite0vj7XqVPfuv55 bAjRmBkuaQ50IsXdgZfzua+VhEu7Sg0= X-Google-Smtp-Source: ABdhPJxtN1K+pH+/B2bBPsEEk+YlqfrKuoyliR0WIP07lfVecyCG0Z3w1yBQx3iQgHvWeM7w+YyZBg== X-Received: by 2002:a5d:4dc5:0:b0:1f0:73e4:2cd9 with SMTP id f5-20020a5d4dc5000000b001f073e42cd9mr17425742wru.212.1647274234437; Mon, 14 Mar 2022 09:10:34 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id m185-20020a1c26c2000000b003899ed333ffsm17934764wmm.47.2022.03.14.09.10.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Mar 2022 09:10:33 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Mon, 14 Mar 2022 16:10:28 +0000 Subject: [PATCH v2 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 Mon Mar 14 16:10:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victoria Dye X-Patchwork-Id: 12780354 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 DF636C433FE for ; Mon, 14 Mar 2022 16:10:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229707AbiCNQL5 (ORCPT ); Mon, 14 Mar 2022 12:11:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47300 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242880AbiCNQLq (ORCPT ); Mon, 14 Mar 2022 12:11:46 -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 D55E23E0C3 for ; Mon, 14 Mar 2022 09:10:36 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id x15so24725036wru.13 for ; Mon, 14 Mar 2022 09:10:36 -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=gb1rOUAN4aWwXNzWfkZER804Fcy5Dhs2ojoPyuPyFP2PX3tQG26dGxX5VzIxqK6FTV FjSnQo0K2NqvViVwSIiV3cvcWKsLiCS8krO6rarwtQHO49YiL5nOpNP4Zq/7BYXxop9Z h602p1YgU9pipRqRAoeQPjyHa65NzSjOj4GCKeyNWAVUVpA3ZhmKjyrbyFGW9F6e/LhJ 62At2bMLSH1/hsph5FaCkkGc2VmNyEaP3vNG71MMBF1rL/b67x7PiVVg4sjqggaqSOzQ csBGH/e8exUPyXa3Wn0BjQ8jd4SE0sBuILH/zuqg9x+UmzwfyyEZ3HcEz+RKoUYA4IIc IAdw== 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=tuZ+jKC48QkxFloW3lrOmwQ/NsJZe23GuMtH9ASNYNVk1QVFgDKCI9VVU97W4yCPRi y79fmWZcth9FWT6Pa0Gq4ueDKY1HJrhlRiPL6kZwRGb4zXzoO7hlgGQ2g1ZorHfG1xlP 1plr8RH81Fwh1K6qRQpq2/k9WFUy1C06mHT9Eqbxl8vPn0LoKmGkHl1amfMc3BmT3iWk CH8/qlPekWaVUj3FrJrqmagdOGUzSX3rNiI+HgwcOGhFAlMS8yOHZZo+uJ43AZDH5gLK XBBuRj+hSvNEVjzYZhkjREwNgsL6Ko3dfWjgDfXvClinpgW8NHMGO1m0HjZAEjw62ilC FZuA== X-Gm-Message-State: AOAM530TfP2M1LAP9p4+ANs9peaTv38hMbsgNd+CSfsd4HfsIwqeTl3w B3tOKcf1R9fHlEhN13Masc90Q9zWi3k= X-Google-Smtp-Source: ABdhPJya2CGD4ftWDA6j7n69y6lf+R+bXdEtAwuNGQRL2Ledwq9Bxziw5s7CzNVcqLdt13XZynSjVA== X-Received: by 2002:adf:fd08:0:b0:1f1:d7a7:f304 with SMTP id e8-20020adffd08000000b001f1d7a7f304mr17705502wrr.36.1647274235346; Mon, 14 Mar 2022 09:10:35 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id m2-20020adff382000000b001f022ef0375sm13617379wro.102.2022.03.14.09.10.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Mar 2022 09:10:34 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Mon, 14 Mar 2022 16:10:29 +0000 Subject: [PATCH v2 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 Mon Mar 14 16:10:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victoria Dye X-Patchwork-Id: 12780356 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 12129C433F5 for ; Mon, 14 Mar 2022 16:10:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242922AbiCNQMB (ORCPT ); Mon, 14 Mar 2022 12:12:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47342 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242908AbiCNQLs (ORCPT ); Mon, 14 Mar 2022 12:11:48 -0400 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 C60BC40E5F for ; Mon, 14 Mar 2022 09:10:37 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id r6so24374883wrr.2 for ; Mon, 14 Mar 2022 09:10:37 -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=1dTmO/MGB8TCNOeHVIRw46EdZM4DrmZ5m+UHTUZgB4c=; b=ZrCj98LzgZdj4ZZq6oTAvACrHbsC73n0YSE9C+MlXA+/yIOYhUcDl8WHWyyEbb3Xyy xI22/oqFACJPfkMhHuG+WO8GgW8qQUwHs9IcaKlqyBCyQ7V2jD9gEpzDIsg7dLw47Bbx HLBUusMn+FXTNdQbayFmVK4RekIaZp+oA7gelcNMXbBM+4jB+MDFw/562zy8hPJ6RcMj dqieQzQkPtbhH02BoM5eB7ikOI2YJ38CzzTW7iO1DJlbyCrHx3f9GGDxkLDZHqTl61Fe Marb1bDNKDZMRTH2+MIho9rEFBztRLs3Gacx2z6VhoZtZDBXfE4PeaqhCMgpINUB1ohP uwGA== 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=1dTmO/MGB8TCNOeHVIRw46EdZM4DrmZ5m+UHTUZgB4c=; b=lwhP+wsprctO9XIpOlbQioCxiI9Sr8jHQutjtgaBwwLwDjs1P4RCXKg3kCq+VPty0C EXoJ7GiK4sw98K6CL+hf/LIgbJlsoblq+HaCDAjT6vgiIn72LYNvyt9XrVBzETrI8agI okzR4qbSgcJDiwpcNlu29sJjLcKfnMYQP1tKke/XaTC13vPEvocn3gZShCC7NP36kZpE u7SVVDeuBGUt78I7mEKaQPPGZbpYcxwRMuICUJG0zauuUZeSuFiIXIlDVtSROF8hqIcK PJGazRaCptEFYPz+mza6qzzHdpSIxMlFOai4un4Z/awP9qbPNp2WgcRCsWHHFfZ2xqd4 cz9Q== X-Gm-Message-State: AOAM530ibN0oNMzjnYOiFnn/i7i0k368cbE2FNfo51N2EzacTmTFQaww iwi8GEuG5I1s3goXehv9+elLYGjCFkw= X-Google-Smtp-Source: ABdhPJwRLyoQrDEzXBE632x9f9fW8PkbAo0hUj3EUrp3YcQBkfkdghSU4Jj0lh9Vj0D/Oo5DsnnNNg== X-Received: by 2002:a05:6000:1446:b0:203:c402:fbfe with SMTP id v6-20020a056000144600b00203c402fbfemr2570635wrx.316.1647274236098; Mon, 14 Mar 2022 09:10:36 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id e4-20020adffc44000000b001f1dba38a65sm13702822wrs.105.2022.03.14.09.10.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Mar 2022 09:10:35 -0700 (PDT) Message-Id: <3334d4cb6f302a35986d94ea8ffcd1ee9c6aae5d.1647274230.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 14 Mar 2022 16:10:30 +0000 Subject: [PATCH v2 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 ++++++++++++ 2 files changed, 15 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..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