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

Re: BUG: git grep behave oddly with alternatives

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 8, 2023, 01:27 UTC
Message-ID
<xmqqpmbp24td.fsf@gitster.g>
In-Reply-To
<26a0d4ca-3d97-ace4-1a1f-92b1ee6715a6@web.de>
René Scharfe <l.s.r@web.de> writes:
Show 12 quoted lines
> diff --git a/Makefile b/Makefile
> index db447d0738..46e30be673 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -289,6 +289,10 @@ include shared.mak
>  # Define NO_REGEX if your C library lacks regex support with REG_STARTEND
>  # feature.
>  #
> +# Define USE_ENHANCED_BASIC_REGULAR_EXPRESSIONS if your C library provides
> +# the flag REG_ENHANCED and you'd like to use it to enable enhanced basic
> +# regular expressions.
> +#

I wondered if we should mention macOS somewhere in the description to help those users that may be affeced, but it seems that looking for "REG_ENHANCED BSD" with a search engine finds pages that indicate this is available on BSD's in general?

Show 9 quoted lines
> @@ -2037,6 +2041,11 @@ endif
>  ifdef NO_REGEX
>  	COMPAT_CFLAGS += -Icompat/regex
>  	COMPAT_OBJS += compat/regex/regex.o
> +else
> +ifdef USE_ENHANCED_BASIC_REGULAR_EXPRESSIONS
> +	COMPAT_CFLAGS += -DUSE_ENHANCED_BASIC_REGULAR_EXPRESSIONS
> +	COMPAT_OBJS += compat/regcomp_enhanced.o
> +endif
OK.
Show 14 quoted lines
> diff --git a/compat/regcomp_enhanced.c b/compat/regcomp_enhanced.c
> new file mode 100644
> index 0000000000..84193ce53b
> --- /dev/null
> +++ b/compat/regcomp_enhanced.c
> @@ -0,0 +1,9 @@
> +#include "../git-compat-util.h"
> +#undef regcomp
> +int git_regcomp(regex_t *preg, const char *pattern, int cflags)
> +{
> +	if (!(cflags & REG_EXTENDED))
> +		cflags |= REG_ENHANCED;
> +	return regcomp(preg, pattern, cflags);
> +}

OK. I like the "we only want to affect BRE" bit, that is carefully done.

Show 9 quoted lines
> diff --git a/config.mak.uname b/config.mak.uname
> index d63629fe80..7d25995265 100644
> --- a/config.mak.uname
> +++ b/config.mak.uname
> @@ -147,6 +147,7 @@ ifeq ($(uname_S),Darwin)
>  	FREAD_READS_DIRECTORIES = UnfortunatelyYes
>  	HAVE_NS_GET_EXECUTABLE_PATH = YesPlease
>  	CSPRNG_METHOD = arc4random
> +	USE_ENHANCED_BASIC_REGULAR_EXPRESSIONS = YesPlease

OK. This would give macOS folks who have already been using the enhanced mode (without us asking) with their older libraries the behaviour they are more familiar with. Good.

Show 12 quoted lines
> diff --git a/git-compat-util.h b/git-compat-util.h
> index 76e4b11131..1efa834089 100644
> --- a/git-compat-util.h
> +++ b/git-compat-util.h
> @@ -1338,6 +1338,11 @@ static inline int regexec_buf(const regex_t *preg, const char *buf, size_t size,
>  	return regexec(preg, buf, nmatch, pmatch, eflags | REG_STARTEND);
>  }
>
> +#ifdef USE_ENHANCED_BASIC_REGULAR_EXPRESSIONS
> +int git_regcomp(regex_t *preg, const char *pattern, int cflags);
> +#define regcomp git_regcomp
> +#endif
OK.
Previous: René ScharfeNext: Jeff King
Message 10 of 22 in “BUG: git grep behave oddly with alternatives”
  1. Marco NenciariniJan 3, 2023
  2. René ScharfeJan 3, 2023
  3. Marco NenciariniJan 3, 2023
  4. René ScharfeJan 3, 2023
  5. Junio C HamanoJan 4, 2023
  6. Jeff KingJan 4, 2023
  7. René ScharfeJan 4, 2023
  8. Jeff KingJan 6, 2023
  9. René ScharfeJan 8, 2023
  10. Junio C HamanoJan 8, 2023
  11. Jeff KingJan 11, 2023
  12. René ScharfeJan 12, 2023
  13. Ævar Arnfjörð BjarmasonJan 12, 2023
  14. Jeff KingJan 12, 2023
  15. Ævar Arnfjörð BjarmasonJan 13, 2023
  16. Junio C HamanoJan 13, 2023
  17. René ScharfeJan 14, 2023
  18. René ScharfeJan 14, 2023
  19. Diomidis SpinellisJan 14, 2023
  20. Junio C HamanoJan 14, 2023
  21. René ScharfeJan 13, 2023
  22. René ScharfeJan 13, 2023

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.