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

Re: [PATCH 3/6] GIT-VERSION-GEN: Use sed instead of expr

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 5, 2019, 22:37 UTC
Message-ID
<xmqqy307kzn3.fsf@gitster-ct.c.googlers.com>
In-Reply-To
<df67a7e1d307d6a7a91ae1bba085959154006ed1.1564876327.git.gitgitgadget@gmail.com>
"lufia via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 19 quoted lines
> From: lufia <lufia@lufia.org>
>
> Plan 9 don't have expr(1).
>
> Signed-off-by: lufia <lufia@lufia.org>
> ---
>  GIT-VERSION-GEN | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/GIT-VERSION-GEN b/GIT-VERSION-GEN
> index a0766f64ed..754d4486f5 100755
> --- a/GIT-VERSION-GEN
> +++ b/GIT-VERSION-GEN
> @@ -26,7 +26,7 @@ else
>  	VN="$DEF_VER"
>  fi
>  
> -VN=$(expr "$VN" : v*'\(.*\)')
> +VN=$(echo "$VN" | sed 's/^v*//')

The expr utility is often a shell built-in, but sed is almost never (as it is a lot more heavy-weight command). It may not be a bad idea to get rid of expr with a simple shell parameter expansion, e.g.

	VN=${VN#v}
instead.

The original explicitly is prepared to see no 'v' at the beginning (in which case it just passes VN intact), or more than one 'v's (in which case all leading 'v's are stripped), while the shell parameter expansion strips zero or one 'v' at the beginning. So there is a slight "regression" there, but I do not think it matters (certainly, it was *NOT* my intention while writing the original to strip two or more 'v's). 181129d2 ("For release tarballs, include the proper version", 2006-01-09) snuck in the "all leading 'v's are stripped" without sufficient explanation, but I do not think it was an attempt to allow two or more 'v's.

Previous: lufia via GitGitGadgetNext: lufia via GitGitGadget
Message 6 of 17 in “Port git to Plan 9”
  1. 0/6 Port git to Plan 9KADOTA, Kyohei via GitGitGadget, Aug 3, 2019
  2. 2/6 Fix C syntactic errors for the Plan 9 C compilerlufia via GitGitGadget, Aug 3, 2019
  3. 4/6 Port generate-cmdline.sh to rclufia via GitGitGadget, Aug 3, 2019
  4. 1/6 Change HOME, PATH, and .gitconfig paths to be customizablelufia via GitGitGadget, Aug 3, 2019
  5. 3/6 GIT-VERSION-GEN: Use sed instead of exprlufia via GitGitGadget, Aug 3, 2019
  6. Junio C HamanoAug 5, 2019
  7. 5/6 Add plan9/wrap.clufia via GitGitGadget, Aug 3, 2019
  8. brian m. carlsonAug 4, 2019
  9. Kyohei KadotaAug 4, 2019
  10. 6/6 Add mkfile to build git and subcommands for Plan 9lufia via GitGitGadget, Aug 3, 2019
  11. brian m. carlsonAug 4, 2019
  12. Kyohei KadotaAug 4, 2019
  13. Jonathan NiederAug 4, 2019
  14. 0/3 Port git to Plan 9KADOTA, Kyohei via GitGitGadget, Aug 27, 2019
  15. 1/3 Change HOME, PATH, and .gitconfig paths to be customizablelufia via GitGitGadget, Aug 27, 2019
  16. 2/3 Fix C syntactic errors for the Plan 9 C compilerlufia via GitGitGadget, Aug 27, 2019
  17. 3/3 Support Plan 9 dialectlufia via GitGitGadget, Aug 27, 2019

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.