Subject: Re: [PATCH v7 13/17] ref-filter: add `:dir` and `:base` options for ref printing atoms

From: Junio C Hamano <[email-masked]>
Date: Fri, 18 Nov 2016 10:18:39 -0800

Jacob Keller <[email-masked]> writes:

>>>> to get remotes from /refs/foo/abc/xyz we'd need to do
>>>> strip=1,strip=-1, which could be
>>>> done but ...
>>>
>>> ... would be unnecessary if this is the only use case:
>>>
>>>> strbuf_addf(&fmt,
>>>> "%%(if:notequals=remotes)%%(refname:base)%%(then)%s%%(else)%s%%(end)",
>>>> local.buf, remote.buf);
>>>
>>> You can "strip to leave only 2 components" and compare the result
>>> with refs/remotes instead, no?
>>>
>>
>> Of course, my only objective was that someone would find it useful to
>> have these two additional
>> atoms. So if you think it's unnecessary we could drop it entirely :D
>>
>> --
>> Regards,
>> Karthik Nayak
>
> I think having strip and rstrip make sense, (along with support for
> negative numbers) I don't think we need to make them work together
> unless someone is interested, since we can use strip=-2 to get the
> behavior we need today.

I am OK with multiple strips Karthik suggests, e.g.

    %(refname:strip=1,rstrip=-1)

if it is cleanly implemented.

I have a bit of trouble with these names, though.  If we call one
strip and the other rstrip, to only those who know about rstrip it
would be clear that strip is about stripping from the left.  Perhaps
we should call it lstrip for symmetry and ease-of-remembering?

    refs/heads/master:lstrip=-1 => master (strip all but one level
    from the left)

    refs/heads/master:rstrip=-2 => refs/heads (strip all but two
    levels from the right)

    refs/heads/master:lstrip=1,rstrip=-1 => heads (strip one level
    from the left and then strip all but one level from the right)

I dunno.