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

Re: ds/maintenance-part-3 (was Re: What's cooking in git.git (Nov 2020, #02; Mon, 9))

From
Derrick Stolee <stolee@gmail.com>
Date
Nov 17, 2020, 13:56 UTC
Message-ID
<29212864-ab96-5757-cbfb-f5621a43f8d8@gmail.com>
In-Reply-To
<20201117010709.GB15562@google.com>
On 11/16/2020 8:07 PM, Emily Shaffer wrote:
Show 17 quoted lines
> On Mon, Nov 16, 2020 at 04:40:35PM -0800, Junio C Hamano wrote:
>>
>> Emily Shaffer <emilyshaffer@google.com> writes:
>>
>>> Because 'git maintenance unregister' spins a child process to call 'git
>>> config --unset maintenance.repo <cwd>', it actually fails if "cwd"
>>> contains a POSIX regular expression special character:
>>>
>>>   git config [<file-option>] --unset name [value_regex]
>>
>> Good find.  And it is even worse that value_regex uses ERE, not BRE,
>> which means even an otherwise innocuous letter like '+' cannot be
>> used without quoting.
> 
> I should have mentioned in the first letter than Jonathan Nieder was the
> one who made the jump from "this is breaking in the buildbot but not
> locally" to regular expression metachars. Credit where it's due.
Thank you for finding and reporting this bug.

Can I at least have a short moment of griping about anyone putting regex characters into their directory names? ;)

Show 13 quoted lines
>>> You can demo it for yourself like so:
>>>
>>>   git init repro+for+maintenance
>>>   git maintenance register
>>>   git maintenance unregister
>>>   echo $?	# returns '5'
>>>   git config --list --global
>>>
>>> I see two paths forward:
>>>
>>
>> 0. Quote the value_regex properly, instead of blindly using a value
>>    that comes from the environment.

Pulling the subcommand from my test enfironment using GIT_TRACE2_PERF=1 I see the following quotes being used:

git config --global --unset maintenance.repo "/repos/new+repo*test"

I'm guessing that what we really want is to _escape_ the regex glob characters? This command works:

git config --global --unset maintenance.repo "/repos/new\+repo\*test"

The only place I see where we do that currently is in builtin/sparse-checkout.c:escaped_pattern(). Please let me know if you know of a more suitable way to escape regex characters.

Show 22 quoted lines
>>> 1. Teach 'git config' to learn either which regex parser to use
>>> (including fixed), or at least to learn "value isn't a regex", or
>>>
>>> 2. Don't spin a child process in 'git maintenance [un]register' and
>>> instead just call the config API.
>>
>>> I'd suggest #2. The config API is very nice, and seems to have a simple
>>> way to add or remove configs to your global file in just a couple of
>>> lines. If there's a reason why it's not simpler to do it that way, it's
>>> my fault for missing the review :)
>>
>> My short-to-mid-term preference is to do #1 to allow a value to be
>> spelled literally (i.e. remove entry with _this_ value, and add this
>> one instead), and optionally do #2 as an optimization that is not
>> essential.  I do not offhand know how you can make #2 alone fly
>> without doing some form of #1, as I think the same value_regex that
>> ought to be ERE to specify entries to be replaced needs to be used
>> under the cover even if you use "config API" anyway.
> 
> Ah, right you are - I had figured the regex parsing was done earlier,
> but it indeed looks to happen in
> config.c:git_config_set_multivar_in_file_gently. Thanks.

So the "real fix" is to allow a command-line option to 'git config' that makes the "value_regex" parameter a literal string? Of course, this would either require wiring an option down into git_config_set_multivar_in_file_gently() to treat the string as a literal _or_ to escape the input string in builtin/config.c.

Am I understanding the intended plan here?

Thanks, -Stolee

Previous: Emily ShafferNext: Emily Shaffer
Message 8 of 15 in “What's cooking in git.git (Nov 2020, #02; Mon, 9)”
  1. Junio C HamanoNov 9, 2020
  2. Elijah NewrenNov 10, 2020
  3. Jeff KingNov 10, 2020
  4. ds/maintenance-part-3 (was Re: What's cooking in git.git (Nov 2020, #02; Mon, 9))Derrick Stolee, Nov 10, 2020
  5. Emily ShafferNov 16, 2020
  6. Junio C HamanoNov 17, 2020
  7. Emily ShafferNov 17, 2020
  8. Derrick StoleeNov 17, 2020
  9. Emily ShafferNov 17, 2020
  10. Junio C HamanoNov 17, 2020
  11. Derrick StoleeNov 17, 2020
  12. Junio C HamanoNov 19, 2020
  13. Derrick StoleeNov 19, 2020
  14. Derrick StoleeNov 19, 2020
  15. Junio C HamanoNov 19, 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.