Re: [PATCH v1 3/3] git: catch an attempt to run "git-foo"
- From
Johannes Schindelin <johannes.schindelin@gmx.de>
- Date
- Dec 20, 2020, 15:25 UTC
- Message-ID
- <nycvar.QRO.7.76.6.2012201623490.56@tvgsbejvaqbjf.bet>
- In-Reply-To
- <nycvar.QRO.7.76.6.2008280412030.56@tvgsbejvaqbjf.bet>
Hi Junio,
On Fri, 28 Aug 2020, Johannes Schindelin wrote:
Show 108 quoted lines
> On Tue, 25 Aug 2020, Junio C Hamano wrote:
>
> > diff --git a/git.c b/git.c
> > index 8bd1d7551d..927018bda7 100644
> > --- a/git.c
> > +++ b/git.c
> > @@ -839,6 +839,8 @@ int cmd_main(int argc, const char **argv)
> > * that one cannot handle it.
> > */
> > if (skip_prefix(cmd, "git-", &cmd)) {
> > + warn_on_dashed_git(argv[0]);
> > +
> > argv[0] = cmd;
> > handle_builtin(argc, argv);
> > die(_("cannot handle %s as a builtin"), cmd);
> > diff --git a/help.c b/help.c
> > index d478afb2af..490d2bc3ae 100644
> > --- a/help.c
> > +++ b/help.c
> > @@ -720,3 +720,37 @@ NORETURN void help_unknown_ref(const char *ref, const char *cmd,
> > string_list_clear(&suggested_refs, 0);
> > exit(1);
> > }
> > +
> > +static struct cmdname_help *find_cmdname_help(const char *name)
> > +{
> > + int i;
> > +
> > + for (i = 0; i < ARRAY_SIZE(command_list); i++) {
> > + if (!strcmp(command_list[i].name, name))
> > + return &command_list[i];
> > + }
> > + return NULL;
> > +}
> > +
> > +void warn_on_dashed_git(const char *cmd)
> > +{
> > + struct cmdname_help *cmdname;
> > + static const char *still_in_use_var = "GIT_I_STILL_USE_DASHED_GIT";
> > + static const char *still_in_use_msg =
> > + N_("Use of '%s' in the dashed-form is nominated for removal.\n"
> > + "If you still use it, export '%s=true'\n"
> > + "and send an e-mail to <git@vger.kernel.org>\n"
> > + "to let us know and stop our removal plan. Thanks.\n");
> > +
> > + if (!cmd)
> > + return; /* git-help is OK */
> > +
> > + cmdname = find_cmdname_help(cmd);
> > + if (cmdname && (cmdname->category & CAT_onpath))
> > + return; /* git-upload-pack and friends are OK */
> > +
> > + if (!git_env_bool(still_in_use_var, 0)) {
> > + fprintf(stderr, _(still_in_use_msg), cmd, still_in_use_var);
> > + exit(1);
> > + }
> > +}
>
> I need this on top, to make it work on Windows:
>
> -- snipsnap --
> From: Johannes Schindelin <johannes.schindelin@gmx.de>
> Subject: [PATCH] fixup??? git: catch an attempt to run "git-foo"
>
> This is needed to handle the case where `argv[0]` contains the full path
> (which is the case on Windows) and the suffix `.exe` (which is also the
> case on Windows).
>
> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
> ---
> git.c | 3 ++-
> help.c | 5 ++++-
> 2 files changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/git.c b/git.c
> index 71ef4835b20e..863fd0c58a66 100644
> --- a/git.c
> +++ b/git.c
> @@ -851,7 +851,8 @@ int cmd_main(int argc, const char **argv)
> * that one cannot handle it.
> */
> if (skip_prefix(cmd, "git-", &cmd)) {
> - warn_on_dashed_git(argv[0]);
> + strip_extension(&cmd);
> + warn_on_dashed_git(cmd);
>
> argv[0] = cmd;
> handle_builtin(argc, argv);
> diff --git a/help.c b/help.c
> index c93a76944b00..27b1b26890be 100644
> --- a/help.c
> +++ b/help.c
> @@ -724,9 +724,12 @@ NORETURN void help_unknown_ref(const char *ref, const char *cmd,
> static struct cmdname_help *find_cmdname_help(const char *name)
> {
> int i;
> + const char *p;
>
> + skip_prefix(name, "git-", &name);
> for (i = 0; i < ARRAY_SIZE(command_list); i++) {
> - if (!strcmp(command_list[i].name, name))
> + if (skip_prefix(command_list[i].name, "git-", &p) &&
> + !strcmp(p, name))
> return &command_list[i];
> }
> return NULL;
> --
> 2.28.0.windows.1How about this instead (to fix that part of the CI failures of `seen`)?
-- snipsnap -- From e8ce19db04657b6ef1c73989695c97a773a9c001 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin <johannes.schindelin@gmx.de> Date: Fri, 28 Aug 2020 14:50:25 +0200 Subject: [PATCH] fixup??? git: catch an attempt to run "git-foo"
This is needed to handle the case where `argv[0]` contains the full path (which is the case on Windows) and the suffix `.exe` (which is also the case on Windows).
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> --- git.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/git.c b/git.c index 7544d2187306..c924c53ea76f 100644 --- a/git.c +++ b/git.c @@ -854,6 +854,7 @@ int cmd_main(int argc, const char **argv) const char *cmd; int done_help = 0; + strip_extension(argv); cmd = argv[0]; if (!cmd) cmd = "git-help"; @@ -875,12 +876,11 @@ int cmd_main(int argc, const char **argv) * So we just directly call the builtin handler, and die if * that one cannot handle it. */ - if (skip_prefix(cmd, "git-", &cmd)) { - warn_on_dashed_git(argv[0]); + if (skip_prefix(cmd, "git-", &argv[0])) { + warn_on_dashed_git(cmd); - argv[0] = cmd; handle_builtin(argc, argv); - die(_("cannot handle %s as a builtin"), cmd); + die(_("cannot handle %s as a builtin"), argv[0]); } /* Look for flags.. */ -- 2.30.0.rc0.windows.1