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

Re: [PATCHv2 22/25] diff.c: color moved lines differently

From
Junio C Hamano <gitster@pobox.com>
Date
Jun 30, 2017, 21:36 UTC
Message-ID
<xmqqshihp37x.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<CAGZ79kbD13RgcTuiegn4J1piFZrNu6bAxCGEKDYLThnVuYQLrg@mail.gmail.com>
Stefan Beller <sbeller@google.com> writes:
Show 7 quoted lines
> On Fri, Jun 30, 2017 at 2:11 PM, Junio C Hamano <gitster@pobox.com> wrote:
>>> +             return (int)' ';
>>
>> Do we need a cast here?
>
> No, I figured it is good to have it here explicitly, though.
> We can drop that if you have strong preferences one way or another.

I was merely wondering if you were protecting against a funny platform where ' ' is a negative number ;-)

Show 20 quoted lines
>>> +static unsigned get_string_hash(struct emitted_diff_symbol *es, struct diff_options *o)
>>> +{
>>> +     if (o->xdl_opts & XDF_WHITESPACE_FLAGS) {
>>> +             static struct strbuf sb = STRBUF_INIT;
>>> +             const char *ap = es->line, *ae = es->line + es->len;
>>> +             int c;
>>> +
>>> +             strbuf_reset(&sb);
>>> +             while (ae > ap && isspace(*ae))
>>> +                     ae--;
>>
>> Not testing for the AT_EOL option here?
>
> No, because the other options are stronger than the AT_EOL,
> such that as you note it is still correct.
>
> If in the future, we'd have another new option e.g.
> IGNORE_TAB_BLANK_CONVERSION_BUT_WARN_ON_LENGTH_DIFF
> (useful for python programmers ;)
> this would break.

That remark makes it sound as if this is a timebomb ticking, but I do not think that is the case. This is merely stripping whitespaces at the end; mixing tabs and spaces without changing the indentation level matters only when you have something that is !isspace() to indent to begin with ;-)

So, the effect of not checking is only a hashmap that is bit less efficient than necessary, but is there an undue cost of actually checking and doing this skipping only when we are ignoring the whitespaces at the end of lines?

Show 5 quoted lines
>> By the way, this is an unrelated tangent because I think you
> ...
> I agree.  I can make a cleanup throughout the whole code base,
> but I would prefer if that is done in a separate series, as this
> is already slightly lengthy.
Oh, I 100% agree that it is an unrelated tangent.  
Previous: Stefan BellerNext: Stefan Beller
Message 54 of 63 in “Reroll of sb/diff-color-moved.”
  1. 00/25 Reroll of sb/diff-color-moved.Stefan Beller, Jun 30, 2017
  2. 02/25 diff.c: move line ending check into emit_hunk_headerStefan Beller, Jun 30, 2017
  3. 12/25 diff.c: emit_diff_symbol learns DIFF_SYMBOL_HEADERStefan Beller, Jun 30, 2017
  4. 04/25 diff.c: introduce emit_diff_symbolStefan Beller, Jun 30, 2017
  5. 06/25 diff.c: emit_diff_symbol learns DIFF_SYMBOL_CONTEXT_FRAGINFOStefan Beller, Jun 30, 2017
  6. 01/25 diff.c: readability fixStefan Beller, Jun 30, 2017
  7. 05/25 diff.c: emit_diff_symbol learns DIFF_SYMBOL_CONTEXT_MARKERStefan Beller, Jun 30, 2017
  8. 03/25 diff.c: factor out diff_flush_patch_all_file_pairsStefan Beller, Jun 30, 2017
  9. 07/25 diff.c: emit_diff_symbol learns DIFF_SYMBOL_NO_LF_EOFStefan Beller, Jun 30, 2017
  10. 18/25 diff.c: convert word diffing to use emit_diff_symbolStefan Beller, Jun 30, 2017
  11. 13/25 diff.c: emit_diff_symbol learns about DIFF_SYMBOL_BINARY_FILESStefan Beller, Jun 30, 2017
  12. 21/25 diff.c: buffer all output if asked toStefan Beller, Jun 30, 2017
  13. 20/25 diff.c: emit_diff_symbol learns about DIFF_SYMBOL_SUMMARYStefan Beller, Jun 30, 2017
  14. 22/25 diff.c: color moved lines differentlyStefan Beller, Jun 30, 2017
  15. Junio C HamanoJun 30, 2017
  16. Stefan BellerJun 30, 2017
  17. Junio C HamanoJun 30, 2017
  18. 24/25 diff.c: add dimming to moved line detectionStefan Beller, Jun 30, 2017
  19. 25/25 diff: document the new --color-moved settingStefan Beller, Jun 30, 2017
  20. Simon RuderichJun 30, 2017
  21. Stefan BellerJun 30, 2017
  22. Simon RuderichJun 30, 2017
  23. Stefan BellerJun 30, 2017
  24. 19/25 diff.c: emit_diff_symbol learns about DIFF_SYMBOL_STAT_SEPStefan Beller, Jun 30, 2017
  25. 11/25 diff.c: emit_diff_symbol learns DIFF_SYMBOL_FILEPAIR_{PLUS, MINUS}Stefan Beller, Jun 30, 2017
  26. 23/25 diff.c: color moved lines differently, plain modeStefan Beller, Jun 30, 2017
  27. 15/25 submodule.c: migrate diff output to use emit_diff_symbolStefan Beller, Jun 30, 2017
  28. 14/25 diff.c: emit_diff_symbol learns DIFF_SYMBOL_REWRITE_DIFFStefan Beller, Jun 30, 2017
  29. 16/25 diff.c: convert emit_binary_diff_body to use emit_diff_symbolStefan Beller, Jun 30, 2017
  30. 10/25 diff.c: emit_diff_symbol learns DIFF_SYMBOL_CONTEXT_INCOMPLETEStefan Beller, Jun 30, 2017
  31. 17/25 diff.c: convert show_stats to use emit_diff_symbolStefan Beller, Jun 30, 2017
  32. 09/25 diff.c: emit_diff_symbol learns DIFF_SYMBOL_WORDS[_PORCELAIN]Stefan Beller, Jun 30, 2017
  33. 08/25 diff.c: migrate emit_line_checked to use emit_diff_symbolStefan Beller, Jun 30, 2017
  34. 00/25 Reroll of sb/diff-color-moved.Stefan Beller, Jun 30, 2017
  35. 01/25 diff.c: readability fixStefan Beller, Jun 30, 2017
  36. 02/25 diff.c: move line ending check into emit_hunk_headerStefan Beller, Jun 30, 2017
  37. 06/25 diff.c: emit_diff_symbol learns DIFF_SYMBOL_CONTEXT_FRAGINFOStefan Beller, Jun 30, 2017
  38. 07/25 diff.c: emit_diff_symbol learns DIFF_SYMBOL_NO_LF_EOFStefan Beller, Jun 30, 2017
  39. 05/25 diff.c: emit_diff_symbol learns DIFF_SYMBOL_CONTEXT_MARKERStefan Beller, Jun 30, 2017
  40. 12/25 diff.c: emit_diff_symbol learns DIFF_SYMBOL_HEADERStefan Beller, Jun 30, 2017
  41. 13/25 diff.c: emit_diff_symbol learns about DIFF_SYMBOL_BINARY_FILESStefan Beller, Jun 30, 2017
  42. 14/25 diff.c: emit_diff_symbol learns DIFF_SYMBOL_REWRITE_DIFFStefan Beller, Jun 30, 2017
  43. 09/25 diff.c: emit_diff_symbol learns DIFF_SYMBOL_WORDS[_PORCELAIN]Stefan Beller, Jun 30, 2017
  44. 20/25 diff.c: emit_diff_symbol learns about DIFF_SYMBOL_SUMMARYStefan Beller, Jun 30, 2017
  45. 18/25 diff.c: convert word diffing to use emit_diff_symbolStefan Beller, Jun 30, 2017
  46. 17/25 diff.c: convert show_stats to use emit_diff_symbolStefan Beller, Jun 30, 2017
  47. 15/25 submodule.c: migrate diff output to use emit_diff_symbolStefan Beller, Jun 30, 2017
  48. 21/25 diff.c: buffer all output if asked toStefan Beller, Jun 30, 2017
  49. 25/25 diff: document the new --color-moved settingStefan Beller, Jun 30, 2017
  50. 23/25 diff.c: color moved lines differently, plain modeStefan Beller, Jun 30, 2017
  51. 22/25 diff.c: color moved lines differentlyStefan Beller, Jun 30, 2017
  52. Junio C HamanoJun 30, 2017
  53. Stefan BellerJun 30, 2017
  54. Junio C HamanoJun 30, 2017
  55. 24/25 diff.c: add dimming to moved line detectionStefan Beller, Jun 30, 2017
  56. 19/25 diff.c: emit_diff_symbol learns about DIFF_SYMBOL_STAT_SEPStefan Beller, Jun 30, 2017
  57. 16/25 diff.c: convert emit_binary_diff_body to use emit_diff_symbolStefan Beller, Jun 30, 2017
  58. 03/25 diff.c: factor out diff_flush_patch_all_file_pairsStefan Beller, Jun 30, 2017
  59. 11/25 diff.c: emit_diff_symbol learns DIFF_SYMBOL_FILEPAIR_{PLUS, MINUS}Stefan Beller, Jun 30, 2017
  60. 10/25 diff.c: emit_diff_symbol learns DIFF_SYMBOL_CONTEXT_INCOMPLETEStefan Beller, Jun 30, 2017
  61. 08/25 diff.c: migrate emit_line_checked to use emit_diff_symbolStefan Beller, Jun 30, 2017
  62. 04/25 diff.c: introduce emit_diff_symbolStefan Beller, Jun 30, 2017
  63. Junio C HamanoJun 30, 2017

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.