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

Re: [PATCH v15 07/13] ref-filter: add support for %(contents:lines=X)

From
Karthik Nayak <karthik.188@gmail.com>
Date
Sep 3, 2015, 13:34 UTC
Message-ID
<CAOLa=ZRiGg1snfsi_mxQYq-wV6Zz4cTkxum47dRowp1XopQejw@mail.gmail.com>
In-Reply-To
<vpq7fo8ol7i.fsf@anie.imag.fr>

On Wed, Sep 2, 2015 at 9:41 PM, Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> wrote:

Show 33 quoted lines
> Karthik Nayak <karthik.188@gmail.com> writes:
>
>> On Wed, Sep 2, 2015 at 2:37 PM, Matthieu Moy
>> <Matthieu.Moy@grenoble-inp.fr> wrote:
>>> Karthik Nayak <karthik.188@gmail.com> writes:
>>>
>>>> --- a/builtin/tag.c
>>>> +++ b/builtin/tag.c
>>>> @@ -185,6 +185,10 @@ static enum contains_result contains(struct commit *candidate,
>>>>       return contains_test(candidate, want);
>>>>  }
>>>>
>>>> +/*
>>>> + * Currently modified and used in ref-filter as append_lines(), will
>>>> + * eventually be removed as we port tag.c to use ref-filter APIs.
>>>> + */
>>>>  static void show_tag_lines(const struct object_id *oid, int lines)
>>>
>>> I would rather have one "cut and paste" patch followed by a "modify and
>>> use" patch for review.
>>>
>>> As-is, reading the patch doesn't tell me what change you did.
>>>
>>> That said, I did get this information in the interdiff, so I won't
>>> insist on that.
>>
>> Its only borrowed slightly, so I don't really see the need for this.
>> But if you insist, we could do that .
>
> As you prefer.
>
> Perhaps just adapt the comment to say "Currently redundant with
> ref-filter'.c's append_line ...", but that's not important.

"Currently modified and used in ref-filter as append_lines()" seems better as only a part of this is used.

Show 51 quoted lines
>
>>>> +static void append_lines(struct strbuf *out, const char *buf, unsigned long size, int lines)
>>>> +{
>>>> +     int i;
>>>> +     const char *sp, *eol;
>>>> +     size_t len;
>>>> +
>>>> +     if ((sp = strstr(buf, "\n\n")) && (sp <= buf + size))
>>>> +             size += 2;
>>>
>>> Why is this "size += 2" needed?
>>>
>>
>> We pass size as "sublen + bodylen - siglen" if there exists a "\n\n"
>> between sublen and bodylen this is not accounted for. hence we
>> add 2 here.
>
> That's too much magic for uncommented code. If this is really needed,
> then thes explanations should go in a comment, and I think this logic
> should be moved out of append_lines (if you read the comment above, the
> function, it is actually lying about what the function does).
>
> I think you can simplify this: you know where the buffer ends (bodypos +
> bodylen) and where it starts (subpos), so you know the size: bodypos +
> bodylen - subpos.
>
> IOW, I think you can apply this:
>
> --- a/ref-filter.c
> +++ b/ref-filter.c
> @@ -645,9 +645,6 @@ static void append_lines(struct strbuf *out, const char *buf, unsigned long size
>         const char *sp, *eol;
>         size_t len;
>
> -       if ((sp = strstr(buf, "\n\n")) && (sp <= buf + size))
> -               size += 2;
> -
>         sp = buf;
>
>         for (i = 0; i < lines && sp < buf + size; i++) {
> @@ -707,7 +704,7 @@ static void grab_sub_body_contents(struct atom_value *val, int deref, struct obj
>                         struct strbuf s = STRBUF_INIT;
>                         if (strtoul_ui(valp, 10, &v->u.contents.lines))
>                                 die(_("positive width expected contents:lines=%s"), valp);
> -                       append_lines(&s, subpos, sublen + bodylen - siglen, v->u.contents.lines);
> +                       append_lines(&s, subpos, bodypos + bodylen - subpos, v->u.contents.lines);
>                         v->s = strbuf_detach(&s, NULL);
>                 }
>         }
>
> (half-tested only)
It is important, without it we'll be missing characters at the end.
I'll try what you suggested. Looks good, will test :)
-- 
Regards,
Karthik Nayak
Previous: Matthieu MoyNext: Karthik Nayak
Message 35 of 58 in “port builtin/tag.c to use ref-filter APIs.”
  1. 00/13 port builtin/tag.c to use ref-filter APIs.Karthik Nayak, Sep 1, 2015
  2. 01/13 ref-filter: move `struct atom_value` to ref-filter.cKarthik Nayak, Sep 1, 2015
  3. 02/13 ref-filter: introduce ref_formatting_state and ref_formatting_stackKarthik Nayak, Sep 1, 2015
  4. 03/13 utf8: add function to align a string into given strbufKarthik Nayak, Sep 1, 2015
  5. 04/13 ref-filter: introduce handler function for each atomKarthik Nayak, Sep 1, 2015
  6. 05/13 ref-filter: implement an `align` atomKarthik Nayak, Sep 1, 2015
  7. Junio C HamanoSep 1, 2015
  8. Karthik NayakSep 2, 2015
  9. Junio C HamanoSep 2, 2015
  10. Karthik NayakSep 2, 2015
  11. Junio C HamanoSep 2, 2015
  12. Karthik NayakSep 2, 2015
  13. Matthieu MoySep 2, 2015
  14. Junio C HamanoSep 2, 2015
  15. Karthik NayakSep 3, 2015
  16. Matthieu MoySep 2, 2015
  17. Matthieu MoySep 2, 2015
  18. Karthik NayakSep 2, 2015
  19. Matthieu MoySep 2, 2015
  20. Karthik NayakSep 2, 2015
  21. Matthieu MoySep 2, 2015
  22. Eric SunshineSep 3, 2015
  23. Karthik NayakSep 3, 2015
  24. Junio C HamanoSep 3, 2015
  25. Karthik NayakSep 4, 2015
  26. 06/13 ref-filter: add option to filter out tags, branches and remotesKarthik Nayak, Sep 1, 2015
  27. Junio C HamanoSep 1, 2015
  28. Karthik NayakSep 2, 2015
  29. Junio C HamanoSep 2, 2015
  30. Karthik NayakSep 2, 2015
  31. 07/13 ref-filter: add support for %(contents:lines=X)Karthik Nayak, Sep 1, 2015
  32. Matthieu MoySep 2, 2015
  33. Karthik NayakSep 2, 2015
  34. Matthieu MoySep 2, 2015
  35. Karthik NayakSep 3, 2015
  36. Karthik NayakSep 3, 2015
  37. Matthieu MoySep 3, 2015
  38. Karthik NayakSep 3, 2015
  39. Eric SunshineSep 3, 2015
  40. Eric SunshineSep 3, 2015
  41. Matthieu MoySep 3, 2015
  42. Karthik NayakSep 3, 2015
  43. Junio C HamanoSep 3, 2015
  44. Karthik NayakSep 4, 2015
  45. Matthieu MoySep 3, 2015
  46. Karthik NayakSep 3, 2015
  47. 08/13 ref-filter: add support to sort by versionKarthik Nayak, Sep 1, 2015
  48. 09/13 ref-filter: add option to match literal patternKarthik Nayak, Sep 1, 2015
  49. 10/13 tag.c: use 'ref-filter' data structuresKarthik Nayak, Sep 1, 2015
  50. 11/13 tag.c: use 'ref-filter' APIsKarthik Nayak, Sep 1, 2015
  51. Matthieu MoySep 2, 2015
  52. Junio C HamanoSep 2, 2015
  53. Karthik NayakSep 2, 2015
  54. Matthieu MoySep 2, 2015
  55. Junio C HamanoSep 2, 2015
  56. Karthik NayakSep 3, 2015
  57. 12/13 tag.c: implement '--format' optionKarthik Nayak, Sep 1, 2015
  58. 13/13 tag.c: implement '--merged' and '--no-merged' optionsKarthik Nayak, Sep 1, 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.