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

Re: [PATCH] get_sha1: handle special case $commit^{/}

From
Junio C Hamano <gitster@pobox.com>
Date
Dec 15, 2010, 23:44 UTC
Message-ID
<7v8vzqppo3.fsf@alter.siamese.dyndns.org>
In-Reply-To
<1292403774-361-1-git-send-email-pclouds@gmail.com>
Nguyễn Thái Ngọc Duy <pclouds@gmail.com> writes:
> Empty regex pattern should always match. But the exact behavior of
> regexec() may vary. Because it always matches anyway, we can just
> return 'matched' without calling regex machinery.

Hmm, I just noticed that "git grep -e '' Makefile" fails on FBSD8 for the same reason.

I'd prefer a solution that is not about "special case $commit^{/}" but is about "work around regcomp that cannot compile an empty regexp".

Wisdoms?
Show 27 quoted lines
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---
>  On top of nd/oneline-sha1-name-from-specific-ref
>
>  sha1_name.c |    7 +++++++
>  1 files changed, 7 insertions(+), 0 deletions(-)
>
> diff --git a/sha1_name.c b/sha1_name.c
> index 1ba4bc3..c5c59ce 100644
> --- a/sha1_name.c
> +++ b/sha1_name.c
> @@ -599,6 +599,13 @@ static int peel_onion(const char *name, int len, unsigned char *sha1)
>  		int ret;
>  		struct commit_list *list = NULL;
>  
> +		/*
> +		 * $commit^{/}. Some regex implementation may reject.
> +		 * We don't need regex anyway. '' pattern always matches.
> +		 */
> +		if (sp[1] == '}')
> +			return 0;
> +
>  		prefix = xstrndup(sp + 1, name + len - 1 - (sp + 1));
>  		commit_list_insert((struct commit *)o, &list);
>  		ret = get_sha1_oneline(prefix, sha1, list);
> -- 
> 1.7.3.3.476.g10a82
Previous: Nguyễn Thái Ngọc DuyNext: Nguyen Thai Ngoc Duy
Message 11 of 17 in “get_sha1_oneline: do not leak or double free”
  1. 1/3 get_sha1_oneline: do not leak or double freeNguyễn Thái Ngọc Duy, Dec 13, 2010
  2. 2/3 get_sha1_oneline: let callers initialize the commit tips for traverseNguyễn Thái Ngọc Duy, Dec 13, 2010
  3. 3/3 get_sha1: support ref^{/regex} syntaxNguyễn Thái Ngọc Duy, Dec 13, 2010
  4. Nguyen Thai Ngoc DuyDec 13, 2010
  5. Jonathan NiederDec 13, 2010
  6. Junio C HamanoDec 15, 2010
  7. Nguyen Thai Ngoc DuyDec 15, 2010
  8. Junio C HamanoDec 15, 2010
  9. Nguyen Thai Ngoc DuyDec 15, 2010
  10. get_sha1: handle special case $commit^{/}Nguyễn Thái Ngọc Duy, Dec 15, 2010
  11. Junio C HamanoDec 15, 2010
  12. Nguyen Thai Ngoc DuyDec 16, 2010
  13. Junio C HamanoDec 13, 2010
  14. Junio C HamanoDec 13, 2010
  15. Nguyen Thai Ngoc DuyDec 13, 2010
  16. Junio C HamanoDec 13, 2010
  17. Junio C HamanoDec 13, 2010

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.