Subject: Re: [GSoC][RFC PATCH v4 3/5] builtin/refs: add list subcommand

From: Phillip Wood <[email-masked]>
Date: Mon, 4 Aug 2025 10:27:56 +0100

On 01/08/2025 16:49, Phillip Wood wrote:
> On 01/08/2025 15:43, Junio C Hamano wrote:
>> Phillip Wood <[email-masked]> writes:
>>
>> What does a double-asterisk currently do in these patterns?
> 
> refs/heads/m** seems to behave like refs/heads/m*. I'm a bit surprised 
> by that as for-each-ref seems to set WM_PATHNAME and I thought that our 
> wildmatch code used '**' to match any character in that case.

I'd forgotten the rules for '**' - it must come after a slash and be 
followed by a slash if it is not at the end of a pattern otherwise it is 
silently converted to '*'. I wish our wildmatch code at least warned 
when it did that. So one can query all the branches beginning with "m" 
by passing

     'refs/heads/m*' 'refs/heads/m*/**'

which isn't as convenient as it could be but it is possible.

>> If it
>> is not doing anything useful, perhaps we should make it match any
>> letter, without getting constrained by hierarchy boundaries?  IOW,
>> a "fix" might be to make sure the following happens?
>>
>>   - "refs/heads/m*" matches all local branches whose name starts with
>>     'm' like 'morning', but not the ones inside subhierarchies that
>>     start with 'm' like 'mid/night'.
>>
>>   - "refs/heads/m**" matches all local branches whose name starts
>>     with 'm' and in the ones inside subhierarchies that start with
>>     'm'.
> 
> That sounds like a good idea

Now I'm not so sure. We could add a flag to wildmatch() that allows ** 
to match any character anywhere in a pattern (I think that is how the 
code behaved when it was first imported from rsync and it also rejected 
invalid patterns) but it if we use that flag in for-each-ref we'd be 
changing the behavior.

Thanks

Phillip