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

Re: [PATCH] help.c: strip suffix only if the STRIP_EXTENSION defined

From
Jeff King <peff@peff.net>
Date
Mar 16, 2016, 17:31 UTC
Message-ID
<20160316173127.GD4039@sigill.intra.peff.net>
In-Reply-To
<1458138449-26690-1-git-send-email-kuleshovmail@gmail.com>
On Wed, Mar 16, 2016 at 08:27:29PM +0600, Alexander Kuleshov wrote:
Show 23 quoted lines
> We stripping extension in the list_commands_in_dir() to get
> commands without '.exe' suffix. Let's do it only if STRIP_EXTENSION
> is defined to not spend time for unnecessary strip_suffix() call in
> this case.
> 
> Signed-off-by: Alexander Kuleshov <kuleshovmail@gmail.com>
> ---
>  help.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/help.c b/help.c
> index 19328ea..c865991 100644
> --- a/help.c
> +++ b/help.c
> @@ -153,8 +153,9 @@ static void list_commands_in_dir(struct cmdnames *cmds,
>  			continue;
>  
>  		entlen = strlen(ent);
> -		strip_suffix(ent, ".exe", &entlen);
> -
> +#ifdef STRIP_EXTENSION
> +		strip_suffix(ent, STRIP_EXTENSION, &entlen);
> +#endif

This is billed as an optimization in the commit message, but these two pieces of code are not the same. The original always strips ".exe", whether or not STRIP_EXTENSION is defined, and whether or not it is ".exe".

In practice it works out because people on Unix systems do not have "git-foo.exe", and nobody sets STRIP_EXTENSION to other things. But I tend to think this is an improvement in robustness.

I also wonder if this should be sharing the strip_extension() helper added in your 63ca1c0.

-Peff
Previous: Alexander KuleshovNext: Alexander Kuleshov
Message 4 of 6 in “help.c: strip suffix only if the STRIP_EXTENSION defined”
  1. help.c: strip suffix only if the STRIP_EXTENSION definedAlexander Kuleshov, Mar 16, 2016
  2. Duy NguyenMar 16, 2016
  3. Alexander KuleshovMar 16, 2016
  4. Jeff KingMar 16, 2016
  5. Alexander KuleshovMar 16, 2016
  6. Jeff KingMar 16, 2016

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.