Message ID | dbb63c4caa83cc764535a739d20736b706ee44a5.1647894889.git.gitgitgadget@gmail.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | reset: make --no-refresh the only way to skip index refresh | expand |
Hi Victoria On 21/03/2022 20:34, Victoria Dye via GitGitGadget wrote: > From: Victoria Dye <vdye@github.com> > > The explicit '--refresh' option was needed in the past when '--quiet', > 'reset.quiet', and/or 'reset.refresh' disabled the index refresh in 'reset > --mixed'. Those options have since either been deprecated or made to always > refresh the index by default, leaving only '--[no-]refresh' determining > whether the index is refreshed or not. > > Because there is nothing other than '--no-refresh' to disable index refresh, > we do not need a '--refresh' option to counteract some other refresh > disabling. '--refresh' could be used to countermand a previous '--no-refresh' (typically when using an alias that includes '--no-refresh'). Usually we have '--foo' even when it is enabled by default e.g. 'commit --verify'. I think the code below does actually support '--refresh' as parse_options() is smart enough to recognize option names beginning with '--no-' and creates an inverse option by removing the prefix rather than adding '--no-' as it normally does. > To ensure users don't use what is effectively a no-op, remove '--refresh' > from the set of 'reset' options, as well as its usage in 'git stash'. > > Signed-off-by: Victoria Dye <vdye@github.com> > --- > Documentation/git-reset.txt | 3 +-- > builtin/reset.c | 6 +++--- > builtin/stash.c | 4 ++-- > t/t7102-reset.sh | 5 ++--- > 4 files changed, 8 insertions(+), 10 deletions(-) > > diff --git a/Documentation/git-reset.txt b/Documentation/git-reset.txt > index df167eaa766..ba8dece0c03 100644 > --- a/Documentation/git-reset.txt > +++ b/Documentation/git-reset.txt > @@ -107,9 +107,8 @@ OPTIONS > --quiet:: > Be quiet, only report errors. > > ---refresh:: > --no-refresh:: > - Proactively refresh the index after a mixed reset. Enabled by default. > + Disable refreshing the index after a mixed reset. > > --pathspec-from-file=<file>:: > Pathspec is passed in `<file>` instead of commandline args. If > diff --git a/builtin/reset.c b/builtin/reset.c > index 54324217f93..d9427abc483 100644 > --- a/builtin/reset.c > +++ b/builtin/reset.c > @@ -392,7 +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 refresh = 1; > int patch_mode = 0, pathspec_file_nul = 0, unborn; > const char *rev, *pathspec_from_file = NULL; > struct object_id oid; > @@ -400,8 +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, "no-refresh", &refresh, > + N_("skip refreshing the index after reset"), 0), I'm confused why we need to change the option type here - am I missing something? Best Wishes Phillip
Phillip Wood wrote: > Hi Victoria > > On 21/03/2022 20:34, Victoria Dye via GitGitGadget wrote: >> From: Victoria Dye <vdye@github.com> >> >> The explicit '--refresh' option was needed in the past when '--quiet', >> 'reset.quiet', and/or 'reset.refresh' disabled the index refresh in 'reset >> --mixed'. Those options have since either been deprecated or made to always >> refresh the index by default, leaving only '--[no-]refresh' determining >> whether the index is refreshed or not. >> >> Because there is nothing other than '--no-refresh' to disable index refresh, >> we do not need a '--refresh' option to counteract some other refresh >> disabling. > > '--refresh' could be used to countermand a previous '--no-refresh' (typically when using an alias that includes '--no-refresh'). Usually we have '--foo' even when it is enabled by default e.g. 'commit --verify'. I think the code below does actually support '--refresh' as parse_options() is smart enough to recognize option names beginning with '--no-' and creates an inverse option by removing the prefix rather than adding '--no-' as it normally does. > Makes sense, I didn't think of the alias use-case/generally wanting to counteract the negative version of the option. Thanks! >> To ensure users don't use what is effectively a no-op, remove '--refresh' >> from the set of 'reset' options, as well as its usage in 'git stash'. >> >> Signed-off-by: Victoria Dye <vdye@github.com> >> --- >> Documentation/git-reset.txt | 3 +-- >> builtin/reset.c | 6 +++--- >> builtin/stash.c | 4 ++-- >> t/t7102-reset.sh | 5 ++--- >> 4 files changed, 8 insertions(+), 10 deletions(-) >> >> diff --git a/Documentation/git-reset.txt b/Documentation/git-reset.txt >> index df167eaa766..ba8dece0c03 100644 >> --- a/Documentation/git-reset.txt >> +++ b/Documentation/git-reset.txt >> @@ -107,9 +107,8 @@ OPTIONS >> --quiet:: >> Be quiet, only report errors. >> ---refresh:: >> --no-refresh:: >> - Proactively refresh the index after a mixed reset. Enabled by default. >> + Disable refreshing the index after a mixed reset. >> --pathspec-from-file=<file>:: >> Pathspec is passed in `<file>` instead of commandline args. If >> diff --git a/builtin/reset.c b/builtin/reset.c >> index 54324217f93..d9427abc483 100644 >> --- a/builtin/reset.c >> +++ b/builtin/reset.c >> @@ -392,7 +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 refresh = 1; >> int patch_mode = 0, pathspec_file_nul = 0, unborn; >> const char *rev, *pathspec_from_file = NULL; >> struct object_id oid; >> @@ -400,8 +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, "no-refresh", &refresh, >> + N_("skip refreshing the index after reset"), 0), > > I'm confused why we need to change the option type here - am I missing something? > This was to explicitly prevent a user from specifying "--refresh", only allowing "--no-refresh". But, based on your earlier comments, there's still some value in having "--refresh", so I'll drop this patch entirely. > > Best Wishes > > Phillip
diff --git a/Documentation/git-reset.txt b/Documentation/git-reset.txt index df167eaa766..ba8dece0c03 100644 --- a/Documentation/git-reset.txt +++ b/Documentation/git-reset.txt @@ -107,9 +107,8 @@ OPTIONS --quiet:: Be quiet, only report errors. ---refresh:: --no-refresh:: - Proactively refresh the index after a mixed reset. Enabled by default. + Disable refreshing the index after a mixed reset. --pathspec-from-file=<file>:: Pathspec is passed in `<file>` instead of commandline args. If diff --git a/builtin/reset.c b/builtin/reset.c index 54324217f93..d9427abc483 100644 --- a/builtin/reset.c +++ b/builtin/reset.c @@ -392,7 +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 refresh = 1; int patch_mode = 0, pathspec_file_nul = 0, unborn; const char *rev, *pathspec_from_file = NULL; struct object_id oid; @@ -400,8 +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, "no-refresh", &refresh, + N_("skip refreshing the index after reset"), 0), 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), diff --git a/builtin/stash.c b/builtin/stash.c index 91407d9bbe0..73f2ba88823 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_pushl(&cp.args, "reset", "--quiet", "--refresh", NULL); + strvec_pushl(&cp.args, "reset", "--quiet", NULL); return run_command(&cp); } @@ -1633,7 +1633,7 @@ 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", "--refresh", "--", + strvec_pushl(&cp.args, "reset", "-q", "--", NULL); add_pathspecs(&cp.args, ps); if (run_command(&cp)) { diff --git a/t/t7102-reset.sh b/t/t7102-reset.sh index 22477f3a312..7a9b845df8c 100755 --- a/t/t7102-reset.sh +++ b/t/t7102-reset.sh @@ -492,9 +492,8 @@ test_expect_success '--mixed refreshes the index' ' test_reset_refreshes_index "" --quiet ' -test_expect_success '--mixed --[no-]refresh sets refresh behavior' ' - # Verify that --[no-]refresh controls index refresh - test_reset_refreshes_index "" --refresh && +test_expect_success '--mixed --no-refresh sets refresh behavior' ' + # Verify that --no-refresh controls index refresh ! test_reset_refreshes_index "" --no-refresh '