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

Re: [PATCH v8 02/11] ref-filter: introduce ref_formatting_state

From
Karthik Nayak <karthik.188@gmail.com>
Date
Aug 3, 2015, 22:03 UTC
Message-ID
<CAOLa=ZStMApJoOfu5Hs_rE+-dKN+FSjcAqKkbAUomt0pnqEdTQ@mail.gmail.com>
In-Reply-To
<xmqqzj286r46.fsf@gitster.dls.corp.google.com>
On Tue, Aug 4, 2015 at 2:12 AM, Junio C Hamano <gitster@pobox.com> wrote:
Show 31 quoted lines
> Karthik Nayak <karthik.188@gmail.com> writes:
>
>> Introduce a ref_formatting_state which will eventually hold the values
>> of modifier atoms. Implement this within ref-filter.
>>
>> Mentored-by: Christian Couder <christian.couder@gmail.com>
>> Mentored-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr>
>> Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
>> ---
>>  ref-filter.c | 49 +++++++++++++++++++++++++++++++++++++------------
>>  ref-filter.h |  4 ++++
>>  2 files changed, 41 insertions(+), 12 deletions(-)
>>
>> diff --git a/ref-filter.c b/ref-filter.c
>> index febdc45..c4c7064 100644
>> --- a/ref-filter.c
>> +++ b/ref-filter.c
>> @@ -1190,9 +1190,10 @@ void ref_array_sort(struct ref_sorting *sorting, struct ref_array *array)
>>       qsort(array->items, array->nr, sizeof(struct ref_array_item *), compare_refs);
>>  }
>>
>> -static void print_value(struct atom_value *v, int quote_style, struct strbuf *output)
>> +static void print_value(struct atom_value *v, struct ref_formatting_state *state,
>> +                     struct strbuf *output)
>>  {
>
> I expect that the state would eventually become a stack of states
> (i.e. the topmost one passed around, each having a pointer to the
> previous level) in order to implement that "divert" mechanism for
> (possibly nested) if ... end construct.
>
Makes sense :)
> With that in mind, I suspect that state->output should be "where the
> current level would output to", i.e. no need to pass state and
> output around separately.
>
Will do!
Show 8 quoted lines
>> +static void apply_formatting_state(struct ref_formatting_state *state, struct strbuf *value,
>> +                                struct strbuf *format)
>> +{
>
> The name "format" feels quite misleading; the readers would expect
> that you would use it in "strbuf_addf(format, value)", but that is
> not what is going on here.
>
will change it to final i guess.
Show 33 quoted lines
>> @@ -1275,12 +1299,13 @@ void show_ref_array_item(struct ref_array_item *info, const char *format, int qu
>>               if (color_parse("reset", color) < 0)
>>                       die("BUG: couldn't parse 'reset' as a color");
>>               resetv.s = color;
>> -             print_value(&resetv, quote_style, &output);
>> +             print_value(&resetv, &state, &value);
>> +             apply_formatting_state(&state, &value, &final_buf);
>>       }
>> -     for (i = 0; i < output.len; i++)
>> -             printf("%c", output.buf[i]);
>> +     for (i = 0; i < final_buf.len; i++)
>> +             printf("%c", final_buf.buf[i]);
>>       putchar('\n');
>> -     strbuf_release(&output);
>> +     strbuf_release(&final_buf);
>>  }
>>
>>  /*  If no sorting option is given, use refname to sort as default */
>> diff --git a/ref-filter.h b/ref-filter.h
>> index 6bf27d8..b64677f 100644
>> --- a/ref-filter.h
>> +++ b/ref-filter.h
>> @@ -16,6 +16,10 @@
>>  #define FILTER_REFS_INCLUDE_BROKEN 0x1
>>  #define FILTER_REFS_ALL 0x2
>>
>> +struct ref_formatting_state {
>> +     int quote_style;
>> +};
>> +
>>  struct atom_value {
>>       const char *s;
>>       unsigned long ul; /* used for sorting when not FIELD_STR */
-- 
Regards,
Karthik Nayak
Previous: Junio C HamanoNext: Karthik Nayak
Message 7 of 20 in “Port tag.c over to use ref-filter APIs”
  1. 0/11 Port tag.c over to use ref-filter APIsKarthik Nayak, Aug 3, 2015
  2. 01/11 ref-filter: print output to strbuf for formattingKarthik Nayak, Aug 3, 2015
  3. Junio C HamanoAug 3, 2015
  4. Karthik NayakAug 3, 2015
  5. 02/11 ref-filter: introduce ref_formatting_stateKarthik Nayak, Aug 3, 2015
  6. Junio C HamanoAug 3, 2015
  7. Karthik NayakAug 3, 2015
  8. 03/11 ref-filter: implement an `align` atomKarthik Nayak, Aug 3, 2015
  9. 04/11 ref-filter: add option to filter only tagsKarthik Nayak, Aug 3, 2015
  10. 05/11 ref-filter: support printing N lines from tag annotationKarthik Nayak, Aug 3, 2015
  11. 06/11 ref-filter: add support to sort by versionKarthik Nayak, Aug 3, 2015
  12. 07/11 ref-filter: add option to match literal patternKarthik Nayak, Aug 3, 2015
  13. 08/11 tag.c: use 'ref-filter' data structuresKarthik Nayak, Aug 3, 2015
  14. 09/11 tag.c: use 'ref-filter' APIsKarthik Nayak, Aug 3, 2015
  15. 10/11 tag.c: implement '--format' optionKarthik Nayak, Aug 3, 2015
  16. 11/11 tag.c: implement '--merged' and '--no-merged' optionsKarthik Nayak, Aug 3, 2015
  17. Junio C HamanoAug 3, 2015
  18. Karthik NayakAug 3, 2015
  19. Junio C HamanoAug 3, 2015
  20. Karthik NayakAug 3, 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.