git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v1 3/3] git: catch an attempt to run "git-foo"

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Aug 31, 2020, 09:59 UTC
Message-ID
<nycvar.QRO.7.76.6.2008311156020.56@tvgsbejvaqbjf.bet>
In-Reply-To
<xmqq1rjqo2bp.fsf@gitster.c.googlers.com>
Hi Junio,
On Fri, 28 Aug 2020, Junio C Hamano wrote:
Show 25 quoted lines
> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
>
> > 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);
>
> The argv[0] may have been NULL from the beginning of cmd_main(), and
> cmd would be "git-help" in such a case. We used to pass NULL to
> warn_on_dashed_git() in such a case because "git-help" is not what the
> user typed, but what we internally trigger, so we didn't want
> warn_on_dashed_git() to do anything based on that internal string.

True. The test suite passes with this, though, which means we haven't covered that case.

Show 27 quoted lines
> As there is no special casing of "help" in warn_on_dashed_git()
> mechanism, it probably would start triggering a warning/die when
> "git<ENTER>" is typed, no?
>
> +	if (argv[0]) {
> 		strip_extension(&cmd);
> 		warn_on_dashed_git(cmd);
>
> may be the minimum fix, but I would strongly prefer to keep the
> interface into warn_on_dashed_git() (eh, the most important is the
> interface into find_cmdname_help() helper function, which is
> designed to be reused by other parts of help.c) to take the full
> command name, not without "git-" prefix.  This is primarily because
> the entirety of the help.c API is driven by full command names,
> without removing "git-" prefix, and it has to, because the help.c
> API needs to handle "gitk", from which you cannot remove any "git-"
> prefix.
>
> Perhaps
>
> 	if (starts_with(cmd, "git-")) {
>                	strip_extension(&cmd);
> 		if (argv[0])
> 			warn_on_dashed_git(cmd);
> 		argv[0] = cmd + 4;
>                 handle_builtin(argc, argv);
> 		die(...);
Sure.
Show 6 quoted lines
> How does your handle_builtin() work, by the way?
>
> The original code (even before we added warn_on_dashed_git() in this
> codepath) did not do any strip_extension(), so handle_builtin() can
> take commands with ".exe" suffix, but now we are feeding the result
> of strip_extension() to it, so it can deal with both?

Yes, it can deal with both. It calls `strip_extension()`, which on Windows removes the `.exe` suffix, if found.

> Sounds convenient and sloppy (not the handle_builtin's
> implementation, but its callers that sometimes feeds the full
> executable name, and feeds only the basename some other times) at
> the same time.

Right, it does not _require_ the extension. I do not necessarily agree that it is sloppy, but I do agree that it is convenient ;-)

Ciao, Dscho

Show 23 quoted lines
> >  		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.1
>
Previous: Junio C HamanoNext: Junio C Hamano
Message 36 of 78 in “builtin/repack.c: invalidate MIDX only when necessary”
  1. builtin/repack.c: invalidate MIDX only when necessaryTaylor Blau, Aug 25, 2020
  2. Jeff KingAug 25, 2020
  3. Taylor BlauAug 25, 2020
  4. Derrick StoleeAug 25, 2020
  5. Taylor BlauAug 25, 2020
  6. Derrick StoleeAug 25, 2020
  7. Taylor BlauAug 25, 2020
  8. Jeff KingAug 25, 2020
  9. Junio C HamanoAug 25, 2020
  10. Taylor BlauAug 25, 2020
  11. Derrick StoleeAug 25, 2020
  12. Jeff KingAug 25, 2020
  13. Jeff KingAug 25, 2020
  14. Junio C HamanoAug 25, 2020
  15. Jeff KingAug 25, 2020
  16. pack-redundant: gauge the usage before proposing its removalJunio C Hamano, Aug 25, 2020
  17. Taylor BlauAug 25, 2020
  18. Junio C HamanoAug 25, 2020
  19. 0/3 War on dashed-gitJunio C Hamano, Aug 26, 2020
  20. 1/3 transport-helper: do not run git-remote-ext etc. in dashed formJunio C Hamano, Aug 26, 2020
  21. Eric SunshineAug 26, 2020
  22. Johannes SchindelinAug 26, 2020
  23. Junio C HamanoAug 26, 2020
  24. 2/3 cvsexportcommit: do not run git programs in dashed formJunio C Hamano, Aug 26, 2020
  25. Eric SunshineAug 26, 2020
  26. Junio C HamanoAug 26, 2020
  27. Junio C HamanoAug 26, 2020
  28. Junio C HamanoAug 26, 2020
  29. Johannes SchindelinAug 26, 2020
  30. 3/3 git: catch an attempt to run "git-foo"Junio C Hamano, Aug 26, 2020
  31. Junio C HamanoAug 26, 2020
  32. Johannes SchindelinAug 26, 2020
  33. Junio C HamanoAug 26, 2020
  34. Johannes SchindelinAug 28, 2020
  35. Junio C HamanoAug 28, 2020
  36. Johannes SchindelinAug 31, 2020
  37. Junio C HamanoAug 31, 2020
  38. Johannes SchindelinDec 20, 2020
  39. Junio C HamanoDec 21, 2020
  40. Johannes SchindelinDec 30, 2020
  41. Johannes SchindelinAug 26, 2020
  42. Junio C HamanoAug 26, 2020
  43. 0/2 avoid running "git-subcmd" in the dashed formJunio C Hamano, Aug 26, 2020
  44. 1/2 transport-helper: do not run git-remote-ext etc. in dashed formJunio C Hamano, Aug 26, 2020
  45. 2/2 cvsexportcommit: do not run git programs in dashed formJunio C Hamano, Aug 26, 2020
  46. 3/2 credential-cache: use child_process.argsJunio C Hamano, Aug 26, 2020
  47. run_command: teach API users to use embedded 'args' moreJunio C Hamano, Aug 26, 2020
  48. Jeff KingAug 27, 2020
  49. Junio C HamanoAug 27, 2020
  50. Eric SunshineAug 27, 2020
  51. Jeff KingAug 27, 2020
  52. Eric SunshineAug 27, 2020
  53. worktree: fix leak in check_clean_worktree()Jeff King, Aug 27, 2020
  54. Eric SunshineAug 27, 2020
  55. Junio C HamanoAug 27, 2020
  56. Jeff KingAug 27, 2020
  57. Jeff KingAug 27, 2020
  58. Junio C HamanoAug 27, 2020
  59. Jeff KingAug 27, 2020
  60. Junio C HamanoAug 27, 2020
  61. Junio C HamanoAug 31, 2020
  62. Jeff KingSep 1, 2020
  63. Junio C HamanoSep 1, 2020
  64. Derrick StoleeAug 27, 2020
  65. Junio C HamanoAug 27, 2020
  66. Jeff KingAug 28, 2020
  67. Junio C HamanoAug 28, 2020
  68. Son Luong NgocAug 25, 2020
  69. Derrick StoleeAug 25, 2020
  70. Taylor BlauAug 25, 2020
  71. builtin/repack.c: invalidate MIDX only when necessaryTaylor Blau, Aug 25, 2020
  72. Derrick StoleeAug 26, 2020
  73. Junio C HamanoAug 26, 2020
  74. Jeff KingAug 25, 2020
  75. Derrick StoleeAug 25, 2020
  76. Jeff KingAug 25, 2020
  77. Taylor BlauAug 25, 2020
  78. Jeff KingAug 25, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.