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

Re: [PATCH v14 06/13] ref-filter: introduce format_ref_array_item()

From
Karthik Nayak <karthik.188@gmail.com>
Date
Aug 30, 2015, 06:39 UTC
Message-ID
<CAOLa=ZTiVS=3M8ckr2Ouz_46h7zaHBcRyxqHMbhGEAt3uWNaCQ@mail.gmail.com>
In-Reply-To
<CAPig+cT2ySwYtTjv7Xe3uv35OH8Bhdyj3m_eqyJjMe_mB6Xj=w@mail.gmail.com>
On Sun, Aug 30, 2015 at 9:12 AM, Eric Sunshine <sunshine@sunshineco.com> wrote:
Show 11 quoted lines
> On Sat, Aug 29, 2015 at 10:12 AM, Karthik Nayak <karthik.188@gmail.com> wrote:
>> Create format_ref_array_item() out of show_ref_array_item(). This will
>> store the output format for the given ref_array_item into the provided
>> strbuf. Make show_ref_array_item() a wrapper around this to print the
>> given ref_array_item with linefeed.
>
> Perhaps you could explain why this change is a good idea, such as that
> a future patch, for <fill-in-the-blank> reason, will need the
> formatting capability of format_ref_array_item() but not the printing
> with newline done by show_ref_array_item().
>
Yeah sure.
Show 35 quoted lines
>> Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
>> ---
>> diff --git a/ref-filter.c b/ref-filter.c
>> index 5d4f93d..1e6754a 100644
>> --- a/ref-filter.c
>> +++ b/ref-filter.c
>> @@ -153,6 +153,27 @@ int parse_ref_filter_atom(const char *atom, const char *ep)
>>         return at;
>>  }
>>
>> +static void quote_formatting(struct strbuf *s, const char *str, int quote_style)
>> +{
>> +       switch (quote_style) {
>> +       case QUOTE_NONE:
>> +               strbuf_addstr(s, str);
>> +               break;
>> +       case QUOTE_SHELL:
>> +               sq_quote_buf(s, str);
>> +               break;
>> +       case QUOTE_PERL:
>> +               perl_quote_buf(s, str);
>> +               break;
>> +       case QUOTE_PYTHON:
>> +               python_quote_buf(s, str);
>> +               break;
>> +       case QUOTE_TCL:
>> +               tcl_quote_buf(s, str);
>> +               break;
>> +       }
>> +}
>
> This code was already relocated once in patch 4/13, and is now being
> relocated again in 6/13. If you instead place the code at the final
> desired location in 4/13, then this patch will become less noisy.
>
Will do.
Show 52 quoted lines
> More below.
>
>>  static void push_stack_element(struct ref_formatting_stack **stack)
>>  {
>>         struct ref_formatting_stack *s = xcalloc(1, sizeof(struct ref_formatting_stack));
>> @@ -665,27 +686,6 @@ static void align_atom_handler(struct atom_value *atomv, struct ref_formatting_s
>>         new->cb_data = atomv->align;
>>  }
>>
>> -static void quote_formatting(struct strbuf *s, const char *str, int quote_style)
>> -{
>> -       switch (quote_style) {
>> -       case QUOTE_NONE:
>> -               strbuf_addstr(s, str);
>> -               break;
>> -       case QUOTE_SHELL:
>> -               sq_quote_buf(s, str);
>> -               break;
>> -       case QUOTE_PERL:
>> -               perl_quote_buf(s, str);
>> -               break;
>> -       case QUOTE_PYTHON:
>> -               python_quote_buf(s, str);
>> -               break;
>> -       case QUOTE_TCL:
>> -               tcl_quote_buf(s, str);
>> -               break;
>> -       }
>> -}
>> -
>>  static void append_atom(struct atom_value *v, struct ref_formatting_state *state)
>>  {
>>         /*
>> @@ -1478,10 +1478,17 @@ void show_ref_array_item(struct ref_array_item *info, const char *format, int qu
>>         }
>>         if (state.stack->prev)
>>                 die(_("format: `end` atom missing"));
>> -       final_buf = &state.stack->output;
>> -       fwrite(final_buf->buf, 1, final_buf->len, stdout);
>> +       strbuf_addbuf(out, &state.stack->output);
>>         pop_stack_element(&state.stack);
>> -       putchar('\n');
>> +}
>> +
>> +void show_ref_array_item(struct ref_array_item *item, const char *format, unsigned int quote_style)
>> +{
>> +       struct strbuf out = STRBUF_INIT;
>> +       format_ref_array_item(&out, item, format, quote_style);
>> +       fwrite(out.buf, out.len, 1, stdout);
>> +       printf("\n");
>
> putchar('\n');
Thanks for the review.
-- 
Regards,
Karthik Nayak
Previous: Eric SunshineNext: Karthik Nayak
Message 33 of 52 in “Port tag.c to use ref-filter.c”
  1. 00/13 Port tag.c to use ref-filter.cKarthik Nayak, Aug 29, 2015
  2. 01/13 ref-filter: move `struct atom_value` to ref-filter.cKarthik Nayak, Aug 29, 2015
  3. 02/13 ref-filter: introduce ref_formatting_state and ref_formatting_stackKarthik Nayak, Aug 29, 2015
  4. 03/13 utf8: add function to align a string into given strbufKarthik Nayak, Aug 29, 2015
  5. Torsten BögershausenAug 29, 2015
  6. Karthik NayakAug 29, 2015
  7. 04/13 ref-filter: implement an `align` atomKarthik Nayak, Aug 29, 2015
  8. Eric SunshineAug 30, 2015
  9. Karthik NayakAug 30, 2015
  10. Eric SunshineAug 30, 2015
  11. Karthik NayakAug 31, 2015
  12. Eric SunshineAug 31, 2015
  13. Matthieu MoyAug 31, 2015
  14. Eric SunshineAug 31, 2015
  15. Karthik NayakSep 1, 2015
  16. Matthieu MoySep 1, 2015
  17. Karthik NayakSep 1, 2015
  18. Karthik NayakAug 30, 2015
  19. Eric SunshineAug 30, 2015
  20. Karthik NayakAug 31, 2015
  21. Junio C HamanoAug 30, 2015
  22. Eric SunshineAug 30, 2015
  23. Karthik NayakAug 31, 2015
  24. Karthik NayakAug 31, 2015
  25. Matthieu MoyAug 31, 2015
  26. Karthik NayakAug 31, 2015
  27. 05/13 ref-filter: add option to filter out tags, branches and remotesKarthik Nayak, Aug 29, 2015
  28. Eric SunshineAug 30, 2015
  29. Karthik NayakAug 30, 2015
  30. Eric SunshineAug 30, 2015
  31. 06/13 ref-filter: introduce format_ref_array_item()Karthik Nayak, Aug 29, 2015
  32. Eric SunshineAug 30, 2015
  33. Karthik NayakAug 30, 2015
  34. Karthik NayakAug 30, 2015
  35. 07/13 ref-filter: add support for %(contents:lines=X)Karthik Nayak, Aug 29, 2015
  36. Eric SunshineAug 30, 2015
  37. Karthik NayakAug 30, 2015
  38. Eric SunshineAug 30, 2015
  39. Karthik NayakAug 30, 2015
  40. Eric SunshineAug 30, 2015
  41. Karthik NayakAug 31, 2015
  42. 08/13 ref-filter: add support to sort by versionKarthik Nayak, Aug 29, 2015
  43. 09/13 ref-filter: add option to match literal patternKarthik Nayak, Aug 29, 2015
  44. 10/13 tag.c: use 'ref-filter' data structuresKarthik Nayak, Aug 29, 2015
  45. 11/13 tag.c: use 'ref-filter' APIsKarthik Nayak, Aug 29, 2015
  46. 12/13 tag.c: implement '--format' optionKarthik Nayak, Aug 29, 2015
  47. 13/13 tag.c: implement '--merged' and '--no-merged' optionsKarthik Nayak, Aug 29, 2015
  48. Matthieu MoyAug 31, 2015
  49. Karthik NayakAug 31, 2015
  50. Matthieu MoyAug 31, 2015
  51. Karthik NayakAug 31, 2015
  52. Karthik NayakSep 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.