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

Re: [PATCH v2 02/12] pretty: share code between format_decoration and show_decorations

From
Duy Nguyen <pclouds@gmail.com>
Date
Apr 12, 2013, 23:34 UTC
Message-ID
<CACsJy8BnWg2JPmGUtLdA+XG9=UX65deYv9moefOHL-O7Kd3kww@mail.gmail.com>
In-Reply-To
<7vd2uejfxr.fsf@alter.siamese.dyndns.org>
Sorry for this late reply. I've been quite busy lately..
On Tue, Apr 2, 2013 at 4:53 AM, Junio C Hamano <gitster@pobox.com> wrote:
Show 13 quoted lines
>> -void show_decorations(struct rev_info *opt, struct commit *commit)
>> +void format_decoration(struct strbuf *sb,
>> +                    const struct commit *commit,
>> +                    int use_color)
>>  {
>> -     const char *prefix;
>> -     struct name_decoration *decoration;
>> +     const char *prefix = " (";
>> +     struct name_decoration *d;
>
> This renaming of variable from decoration to d seems to make the
> patched result unnecessarily different from the original in
> show_decorations, making it harder to compare.  Intentional?

I think I just happened to reuse the style of the old format_decoration(). Will reuse the name "decoration" instead.

Show 12 quoted lines
>>       const char *color_commit =
>> -             diff_get_color_opt(&opt->diffopt, DIFF_COMMIT);
>> +             diff_get_color(use_color, DIFF_COMMIT);
>>       const char *color_reset =
>> -             decorate_get_color_opt(&opt->diffopt, DECORATION_NONE);
>> +             decorate_get_color(use_color, DECORATION_NONE);
>> +
>> +     load_ref_decorations(DECORATE_SHORT_REFS);
>
> In cmd_log_init_finish(), we have loaded decorations with specified
> decoration_style already.  Why is this needed (and with a hardcoded
> style that may be different from what the user specified)?

legacy from pretty.c:format_decoration(). Will move it to the caller format_commit_one.

Show 28 quoted lines
>
>> +     d = lookup_decoration(&name_decoration, &commit->object);
>> +     if (!d)
>> +             return;
>> +     while (d) {
>> +             strbuf_addstr(sb, color_commit);
>> +             strbuf_addstr(sb, prefix);
>> +             strbuf_addstr(sb, decorate_get_color(use_color, d->type));
>> +             if (d->type == DECORATION_REF_TAG)
>> +                     strbuf_addstr(sb, "tag: ");
>> +             strbuf_addstr(sb, d->name);
>> +             strbuf_addstr(sb, color_reset);
>> +             prefix = ", ";
>> +             d = d->next;
>> +     }
>> +     if (prefix[0] == ',') {
>> +             strbuf_addstr(sb, color_commit);
>> +             strbuf_addch(sb, ')');
>> +             strbuf_addstr(sb, color_reset);
>> +     }
>
> Was this change to conditionally close ' (' mentioned in the log
> message?  It is in line with the version taken from pretty.c, and I
> think it may be an improvement, but I do not think the check is
> necessary in the context of this function.  You will never see
> prefix[0] != ',' after the loop, because "while (d)" above runs at
> least once; otherwise the "if (!d) return" would have returned from
> the function early, no?
Yes, your eyeballs have really good quality ;)
Show 16 quoted lines
>> @@ -625,8 +639,8 @@ void show_log(struct rev_info *opt)
>>                       printf(" (from %s)",
>>                              find_unique_abbrev(parent->object.sha1,
>>                                                 abbrev_commit));
>> +             fputs(diff_get_color_opt(&opt->diffopt, DIFF_RESET), stdout);
>>               show_decorations(opt, commit);
>> -             printf("%s", diff_get_color_opt(&opt->diffopt, DIFF_RESET));
>
> We used to show and then reset.  I can see the updated
> show_decorations() to format_decoration() callchain always reset at
> the end, so the loss of the final reset here is very sane, but is
> there a need to reset beforehand?  What is the calling convention
> for the updated show_decorations()?  The caller should make sure
> there is no funny colors in effect before calling, and the caller
> can rest assured that there is no funny colors when the function
> returns?

I think it's a sane convention, unless we want a some background color going through show_decorations.

Show 9 quoted lines
>> +void format_decoration(struct strbuf *sb,
>> +                    const struct commit *commit,
>> +                    int use_color);
>
> I think you can fit these on a single line, especially if you drop
> the unused variable names (they help when there are more than one
> parameter of the same type to document the order of the arguments,
> but that does not apply here).  That would help people who run
> "grep" on the header files without using CTAGS/ETAGS.
No problem.
> Wouldn't it be "format_decorations()", or does it handle only one?

All in one, apparently. Will rename. -- Duy

Previous: Duy NguyenNext: Nguyễn Thái Ngọc Duy
Message 26 of 83 in “Layout control placeholders for pretty format”
  1. 00/12 Layout control placeholders for pretty formatNguyễn Thái Ngọc Duy, Mar 16, 2013
  2. 01/12 pretty-formats.txt: wrap long linesNguyễn Thái Ngọc Duy, Mar 16, 2013
  3. 02/12 pretty: share code between format_decoration and show_decorationsNguyễn Thái Ngọc Duy, Mar 16, 2013
  4. 03/12 utf8.c: move display_mode_esc_sequence_len() for use by other functionsNguyễn Thái Ngọc Duy, Mar 16, 2013
  5. 04/12 utf8.c: add utf8_strnwidth() with the ability to skip ansi sequencesNguyễn Thái Ngọc Duy, Mar 16, 2013
  6. 05/12 pretty: save commit encoding from logmsg_reencode if the caller needs itNguyễn Thái Ngọc Duy, Mar 16, 2013
  7. Eric SunshineMar 17, 2013
  8. 06/12 pretty: get the correct encoding for --pretty:format=%eNguyễn Thái Ngọc Duy, Mar 16, 2013
  9. 07/12 utf8: keep NULs in reencode_string()Nguyễn Thái Ngọc Duy, Mar 16, 2013
  10. 08/12 pretty: two phase conversion for non utf-8 commitsNguyễn Thái Ngọc Duy, Mar 16, 2013
  11. 09/12 pretty: add %C(auto) for auto-coloring on the next placeholderNguyễn Thái Ngọc Duy, Mar 16, 2013
  12. Eric SunshineMar 17, 2013
  13. 10/12 pretty: support padding placeholders, %< %> and %><Nguyễn Thái Ngọc Duy, Mar 16, 2013
  14. Eric SunshineMar 17, 2013
  15. 11/12 pretty: support truncating in %>, %< and %><Nguyễn Thái Ngọc Duy, Mar 16, 2013
  16. Paul CampbellMar 16, 2013
  17. 12/12 pretty: support %>> that steal trailing spacesNguyễn Thái Ngọc Duy, Mar 16, 2013
  18. Eric SunshineMar 17, 2013
  19. Duy NguyenMar 30, 2013
  20. 00/12 Layout control placeholders for pretty formatNguyễn Thái Ngọc Duy, Mar 30, 2013
  21. 01/12 pretty-formats.txt: wrap long linesNguyễn Thái Ngọc Duy, Mar 30, 2013
  22. 02/12 pretty: share code between format_decoration and show_decorationsNguyễn Thái Ngọc Duy, Mar 30, 2013
  23. Junio C HamanoApr 1, 2013
  24. Jakub NarębskiApr 5, 2013
  25. Duy NguyenApr 12, 2013
  26. Duy NguyenApr 12, 2013
  27. 03/12 utf8.c: move display_mode_esc_sequence_len() for use by other functionsNguyễn Thái Ngọc Duy, Mar 30, 2013
  28. 04/12 utf8.c: add utf8_strnwidth() with the ability to skip ansi sequencesNguyễn Thái Ngọc Duy, Mar 30, 2013
  29. Junio C HamanoApr 1, 2013
  30. 05/12 pretty: save commit encoding from logmsg_reencode if the caller needs itNguyễn Thái Ngọc Duy, Mar 30, 2013
  31. Junio C HamanoApr 1, 2013
  32. 06/12 pretty: get the correct encoding for --pretty:format=%eNguyễn Thái Ngọc Duy, Mar 30, 2013
  33. 07/12 utf8: keep NULs in reencode_string()Nguyễn Thái Ngọc Duy, Mar 30, 2013
  34. Torsten BögershausenMar 30, 2013
  35. Duy NguyenMar 31, 2013
  36. 08/12 pretty: two phase conversion for non utf-8 commitsNguyễn Thái Ngọc Duy, Mar 30, 2013
  37. 09/12 pretty: add %C(auto) for auto-coloring on the next placeholderNguyễn Thái Ngọc Duy, Mar 30, 2013
  38. Junio C HamanoApr 1, 2013
  39. Duy NguyenApr 5, 2013
  40. Junio C HamanoApr 5, 2013
  41. Duy NguyenApr 15, 2013
  42. 10/12 pretty: support padding placeholders, %< %> and %><Nguyễn Thái Ngọc Duy, Mar 30, 2013
  43. 11/12 pretty: support truncating in %>, %< and %><Nguyễn Thái Ngọc Duy, Mar 30, 2013
  44. 12/12 pretty: support %>> that steal trailing spacesNguyễn Thái Ngọc Duy, Mar 30, 2013
  45. Junio C HamanoApr 1, 2013
  46. 00/13 nd/pretty-formatsNguyễn Thái Ngọc Duy, Apr 16, 2013
  47. 01/13 pretty: save commit encoding from logmsg_reencode if the caller needs itNguyễn Thái Ngọc Duy, Apr 16, 2013
  48. 02/13 pretty: get the correct encoding for --pretty:format=%eNguyễn Thái Ngọc Duy, Apr 16, 2013
  49. 03/13 pretty-formats.txt: wrap long linesNguyễn Thái Ngọc Duy, Apr 16, 2013
  50. 04/13 pretty: share code between format_decoration and show_decorationsNguyễn Thái Ngọc Duy, Apr 16, 2013
  51. 05/13 utf8.c: move display_mode_esc_sequence_len() for use by other functionsNguyễn Thái Ngọc Duy, Apr 16, 2013
  52. 06/13 utf8.c: add utf8_strnwidth() with the ability to skip ansi sequencesNguyễn Thái Ngọc Duy, Apr 16, 2013
  53. 07/13 utf8.c: add reencode_string_len() that can handle NULs in stringNguyễn Thái Ngọc Duy, Apr 16, 2013
  54. Duy NguyenApr 16, 2013
  55. Junio C HamanoApr 18, 2013
  56. 08/13 pretty: two phase conversion for non utf-8 commitsNguyễn Thái Ngọc Duy, Apr 16, 2013
  57. 09/13 pretty: split color parsing into a separate functionNguyễn Thái Ngọc Duy, Apr 16, 2013
  58. 10/13 pretty: add %C(auto) for auto-coloringNguyễn Thái Ngọc Duy, Apr 16, 2013
  59. Junio C HamanoApr 16, 2013
  60. Duy NguyenApr 17, 2013
  61. Junio C HamanoApr 17, 2013
  62. Junio C HamanoApr 16, 2013
  63. 11/13 pretty: support padding placeholders, %< %> and %><Nguyễn Thái Ngọc Duy, Apr 16, 2013
  64. Junio C HamanoApr 16, 2013
  65. Junio C HamanoApr 16, 2013
  66. Duy NguyenApr 17, 2013
  67. 12/13 pretty: support truncating in %>, %< and %><Nguyễn Thái Ngọc Duy, Apr 16, 2013
  68. 13/13 pretty: support %>> that steal trailing spacesNguyễn Thái Ngọc Duy, Apr 16, 2013
  69. 00/13 nd/pretty-formatsNguyễn Thái Ngọc Duy, Apr 18, 2013
  70. 01/13 pretty: save commit encoding from logmsg_reencode if the caller needs itNguyễn Thái Ngọc Duy, Apr 18, 2013
  71. 02/13 pretty: get the correct encoding for --pretty:format=%eNguyễn Thái Ngọc Duy, Apr 18, 2013
  72. 03/13 pretty-formats.txt: wrap long linesNguyễn Thái Ngọc Duy, Apr 18, 2013
  73. 04/13 pretty: share code between format_decoration and show_decorationsNguyễn Thái Ngọc Duy, Apr 18, 2013
  74. 05/13 utf8.c: move display_mode_esc_sequence_len() for use by other functionsNguyễn Thái Ngọc Duy, Apr 18, 2013
  75. 06/13 utf8.c: add utf8_strnwidth() with the ability to skip ansi sequencesNguyễn Thái Ngọc Duy, Apr 18, 2013
  76. 07/13 utf8.c: add reencode_string_len() that can handle NULs in stringNguyễn Thái Ngọc Duy, Apr 18, 2013
  77. 08/13 pretty: two phase conversion for non utf-8 commitsNguyễn Thái Ngọc Duy, Apr 18, 2013
  78. 09/13 pretty: split color parsing into a separate functionNguyễn Thái Ngọc Duy, Apr 18, 2013
  79. 10/13 pretty: add %C(auto) for auto-coloringNguyễn Thái Ngọc Duy, Apr 18, 2013
  80. 11/13 pretty: support padding placeholders, %< %> and %><Nguyễn Thái Ngọc Duy, Apr 18, 2013
  81. 12/13 pretty: support truncating in %>, %< and %><Nguyễn Thái Ngọc Duy, Apr 18, 2013
  82. 13/13 pretty: support %>> that steal trailing spacesNguyễn Thái Ngọc Duy, Apr 18, 2013
  83. Torsten BögershausenApr 16, 2013

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.