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

Re: [PATCH 3/9] ref-filter: add support for %(path) atom

From
Karthik Nayak <karthik.188@gmail.com>
Date
Oct 4, 2015, 19:12 UTC
Message-ID
<CAOLa=ZS2oWfjrx12q8nRxbquwFhtydqAFZ5zc4t2rMAk68RLYw@mail.gmail.com>
In-Reply-To
<vpqfv1q5xop.fsf@grenoble-inp.fr>
On Mon, Oct 5, 2015 at 12:14 AM, Junio C Hamano <gitster@pobox.com> wrote:
Show 8 quoted lines
>
> Is that a derived form of the refname, just like %(refname:short)
> that is 'master' for a ref whose %(refname) is 'refs/heads/master'
> is a derived form of %(refname), and ":short" is what tells the
> formatting machinery what kind of derivation is desired?
>
> If so would %(refname:dir) & %(refname:base) be more in line with
> the overall structure?
This seems way better, I like these names more.

On Sun, Oct 4, 2015 at 11:21 PM, Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> wrote:

Show 23 quoted lines
> Karthik Nayak <karthik.188@gmail.com> writes:
>
>> On Sat, Oct 3, 2015 at 3:32 PM, Matthieu Moy
>> <Matthieu.Moy@grenoble-inp.fr> wrote:
>>> Karthik Nayak <karthik.188@gmail.com> writes:
>>>
>>>> This adds %(path) and %(path:short) atoms. The %(path) atom will print
>>>> the path of the given ref, while %(path:short) will only print the
>>>> subdirectory of the given ref.
>>>
>>> What does "path" mean in this context? How is it different from
>>> %(refname)?
>>>
>>> I found the answer below, but I could not guess from the doc and commit
>>> message. Actually, I'm not sure %(path) is the right name. If you want
>>> the "file/directory" analogy, then %(dirname) would be better.
>>>
>>
>> Noted will change.
>
> Note: I don't completely like %(dirname) either. I'm convinced it's
> better than %(path), but there may be a better option.
>
I like Junio's suggestion, stick with that?
Show 28 quoted lines
>>>> +             } else if (match_atom_name(name, "path", &valp)) {
>>>> +                     const char *sp, *ep;
>>>> +
>>>> +                     if (ref->kind & FILTER_REFS_DETACHED_HEAD)
>>>> +                             continue;
>>>> +
>>>> +                     sp = strchr(ref->refname, '/');
>>>> +                     ep = strchr(++sp, '/');
>>>
>>> This assumes you have two / in the fullrefname. It is normally the case,
>>> but one can also create eg. refs/foo references. AFAIK, in this case sp
>>> will be NULL, and you're then calling strchr(++NULL) which may segfault.
>>
>> Not really,
>
> Oops, indeed, for refs/foo, sp points to / and ep is NULL. It would
> segfault for any ref without a /. Currently, the only such ref is HEAD
> and it is dealt with by the 'if' above, but that still sounds a bit
> fragile to me. Ifever we allow listing refs like FETCH_HEAD, I'm not
> sure we'll remember that and test %(path) on it.
>
> Adding something like
>
> if (!sp)
>         continue;
>
> after the first strchr would make me feel safer.
>
Good point! I'll add that.
Show 13 quoted lines
>> but you made me think of another possible issue.
>>
>> Assume refs/foo "sp = strchr(ref->refname, '/');" would set sp to point at
>> '/' and ++sp will now point at 'f'.
>>
>> The problem now is refs/foo is supposed to print just "refs" whereas it'll
>> print "refs/foo". and %(dirname:short) is supposed to print "" whereas it'll
>> print "foo". Will look into this :)
>
> I think it's worse than that because ep will be NULL, and then you call
>
>         v->s = xstrndup(sp, ep - sp);
>
Ah yes, weirdly though my test didn't yield a problem.

~ git update-ref refs/foo master ~ git for-each-ref --format="%(refname) %(color:red)%(dirname:short)" refs/foo foo ~ git for-each-ref --format="%(refname) %(color:red)%(dirname)" refs/foo refs/foo

-- 
Regards,
Karthik Nayak
Previous: Matthieu MoyNext: Karthik Nayak
Message 19 of 43 in “port branch.c to use ref-filter printing APIs”
  1. 0/9 port branch.c to use ref-filter printing APIsKarthik Nayak, Oct 2, 2015
  2. 1/9 ref-filter: implement %(if), %(then), and %(else) atomsKarthik Nayak, Oct 2, 2015
  3. Junio C HamanoOct 2, 2015
  4. Karthik NayakOct 3, 2015
  5. Matthieu MoyOct 3, 2015
  6. Junio C HamanoOct 3, 2015
  7. Matthieu MoyOct 4, 2015
  8. Junio C HamanoOct 4, 2015
  9. Karthik NayakOct 4, 2015
  10. 2/9 ref-filter: implement %(if:equals=<string>) and %(if:notequals=<string>)Karthik Nayak, Oct 2, 2015
  11. Junio C HamanoOct 2, 2015
  12. Karthik NayakOct 3, 2015
  13. 3/9 ref-filter: add support for %(path) atomKarthik Nayak, Oct 2, 2015
  14. Matthieu MoyOct 3, 2015
  15. Karthik NayakOct 4, 2015
  16. Matthieu MoyOct 4, 2015
  17. Junio C HamanoOct 4, 2015
  18. Matthieu MoyOct 5, 2015
  19. Karthik NayakOct 4, 2015
  20. 4/9 ref-filter: modify "%(objectname:short)" to take lengthKarthik Nayak, Oct 2, 2015
  21. Junio C HamanoOct 2, 2015
  22. Karthik NayakOct 3, 2015
  23. 5/9 ref-filter: adopt get_head_description() from branch.cKarthik Nayak, Oct 2, 2015
  24. 6/9 ref-filter: introduce format_ref_array_item()Karthik Nayak, Oct 2, 2015
  25. Matthieu MoyOct 3, 2015
  26. Karthik NayakOct 5, 2015
  27. Matthieu MoyOct 5, 2015
  28. Karthik NayakOct 6, 2015
  29. Matthieu MoyOct 6, 2015
  30. Karthik NayakOct 6, 2015
  31. 7/9 ref-filter: make %(upstream:track) prints "[gone]" for invalid upstreamsKarthik Nayak, Oct 2, 2015
  32. Matthieu MoyOct 3, 2015
  33. Karthik NayakOct 5, 2015
  34. 8/9 branch: use ref-filter printing APIsKarthik Nayak, Oct 2, 2015
  35. Matthieu MoyOct 3, 2015
  36. Karthik NayakOct 5, 2015
  37. Matthieu MoyOct 5, 2015
  38. Karthik NayakOct 6, 2015
  39. Matthieu MoyOct 6, 2015
  40. Karthik NayakOct 7, 2015
  41. Matthieu MoyOct 7, 2015
  42. Karthik NayakOct 7, 2015
  43. 9/9 branch: implement '--format' optionKarthik Nayak, Oct 2, 2015

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.