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

Re: [PATCH v4 01/10] ref-filter: add option to align atoms to the left

From
Karthik Nayak <karthik.188@gmail.com>
Date
Jul 25, 2015, 04:14 UTC
Message-ID
<CAOLa=ZRBwErMLhcg=STymECrfGG3WQpfFvPXzDCcjBTQb9JmCA@mail.gmail.com>
In-Reply-To
<xmqqpp3hjh3r.fsf@gitster.dls.corp.google.com>
On Sat, Jul 25, 2015 at 4:30 AM, Junio C Hamano <gitster@pobox.com> wrote:
Show 25 quoted lines
> Junio C Hamano <gitster@pobox.com> writes:
>
>> Karthik Nayak <karthik.188@gmail.com> writes:
>>
>>> -    if (!ref->value) {
>>> -            populate_value(ref);
>>> +    /*
>>> +     * If the atom is a pseudo_atom then we re-populate the value
>>> +     * into the ref_formatting_state stucture.
>>> +     */
>>> +    if (!ref->value || ref->value[atom].pseudo_atom) {
>>> +            populate_value(state, ref);
>>>              fill_missing_values(ref->value);
>>
> I am not sure why you need to do this.  populate_value() and
> fill_missing_values() are fairly heavy-weight operations that are
> expected to grab everything necessary from scratch, and that is why
> we ensure that we do not call them more than once for each "ref"
> with by guarding the calls with "if (!ref->value)".
>
> This change is breaking that basic arrangement, and worse yet, it
> forces us re-read everything about that ref, leaking old ref->value.
>
> Why could this be a good idea?
>

This was required as populate_value() would fill the 'state' but the 'state' being a static variable would be lost before printing and hence we would not have the correct values of the 'state' when printing.

> I think populate_value() should not take state; that is the root
> cause of this mistake.
Yes! agreed. atomv should be a better candidate to hold the formatting values.
Show 40 quoted lines
>
> The flow should be:
>
>     - verify_format() looks at the format string and enumerates all
>       atoms that will ever be used in the output by calling
>       parse_atom() and letting it to fill used_atom[];
>
>     - when ref->value is not yet populated, populate_value() is
>       called, just once.  This uses the enumeration in used_atom[]
>       and stores computed value to refs->value[atom];
>
>     - show_ref() repeatedly calls find_next() to find the next
>       reference to %(...), emits everything before it, and then
>       uses the atom value (i.e. ref->value[atom]).
>
> I would expect that the atom value for pseudos like color and align
> to be parsed and stored in ref->value in populate_value() when it is
> called for the first time for each ref _just once_.
>
> "color:blue" may choose to store "blue" as v->s, and "align:4" may
> choose to do "v->ul = 4".
>
> And the code that uses these values should look more like:
>
>         for (cp = format; *cp && (sp = find_next(cp)); cp = ep + 1) {
>                 struct atom_value *atomv;
>
>                 ep = strchr(sp, ')');
>                 if (cp < sp)
>                         emit(cp, sp);
>                 get_ref_atom_value(info, parse_ref_filter_atom(sp + 2, ep), &atomv);
>                 if (atomv->is_pseudo)
>                         apply_pseudo_state(&state, atomv);
>                 else
>                         print_value(&state, atomv);
>         }
>
> where apply_pseudo_state() would switch on what kind of pseudo the
> atom is and update the state accordingly, i.e. the "state" munging
> code you added to populate_value() in this patch.

This makes more sense, and avoids the repetitive call to populate_value(). Will implement this. Thanks

-- 
Regards,
Karthik Nayak
Previous: Junio C HamanoNext: Eric Sunshine
Message 5 of 36 in “port tag.c to use ref-filter APIs”
  1. 0/10 port tag.c to use ref-filter APIsKarthik Nayak, Jul 24, 2015
  2. 01/10 ref-filter: add option to align atoms to the leftKarthik Nayak, Jul 24, 2015
  3. Junio C HamanoJul 24, 2015
  4. Junio C HamanoJul 24, 2015
  5. Karthik NayakJul 25, 2015
  6. Eric SunshineJul 26, 2015
  7. Karthik NayakJul 26, 2015
  8. Eric SunshineJul 26, 2015
  9. Karthik NayakJul 26, 2015
  10. Matthieu MoyJul 27, 2015
  11. Duy NguyenJul 27, 2015
  12. Jacob KellerJul 27, 2015
  13. Duy NguyenJul 27, 2015
  14. Duy NguyenJul 28, 2015
  15. 02/10 ref-filter: make the 'color' use ref_formatting_stateKarthik Nayak, Jul 24, 2015
  16. Junio C HamanoJul 24, 2015
  17. Karthik NayakJul 25, 2015
  18. Eric SunshineJul 26, 2015
  19. Eric SunshineJul 26, 2015
  20. Karthik NayakJul 26, 2015
  21. 03/10 ref-filter: add option to filter only tagsKarthik Nayak, Jul 24, 2015
  22. 04/10 ref-filter: support printing N lines from tag annotationKarthik Nayak, Jul 24, 2015
  23. Eric SunshineJul 26, 2015
  24. Karthik NayakJul 26, 2015
  25. 05/10 ref-filter: add support to sort by versionKarthik Nayak, Jul 24, 2015
  26. Junio C HamanoJul 25, 2015
  27. Karthik NayakJul 26, 2015
  28. Junio C HamanoJul 27, 2015
  29. Karthik NayakJul 27, 2015
  30. 06/10 ref-filter: add option to match literal patternKarthik Nayak, Jul 24, 2015
  31. Eric SunshineJul 26, 2015
  32. Karthik NayakJul 26, 2015
  33. 07/10 tag.c: use 'ref-filter' data structuresKarthik Nayak, Jul 24, 2015
  34. 08/10 tag.c: use 'ref-filter' APIsKarthik Nayak, Jul 24, 2015
  35. 09/10 tag.c: implement '--format' optionKarthik Nayak, Jul 24, 2015
  36. 10/10 tag.c: implement '--merged' and '--no-merged' optionsKarthik Nayak, Jul 24, 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.