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

Re: [PATCH] diff: Support diff.color-words config option

From
Boyd Stephen Smith Jr. <bss@iguanasuicide.net>
Date
Jan 20, 2009, 16:52 UTC
Message-ID
<200901201053.03256.bss@iguanasuicide.net>
In-Reply-To
<alpine.DEB.1.00.0901201058520.3586@pacific.mpi-cbg.de>
On Tuesday 2009 January 20 04:02:00 you wrote:
Show 14 quoted lines
>On Mon, 19 Jan 2009, Boyd Stephen Smith Jr. wrote:
>> diff --git a/diff.c b/diff.c
>> index 9fcde96..c53e1d1 100644
>> --- a/diff.c
>> +++ b/diff.c
>> @@ -23,6 +23,7 @@ static int diff_detect_rename_default;
>>  static int diff_rename_limit_default = 200;
>>  static int diff_suppress_blank_empty;
>>  int diff_use_color_default = -1;
>> +static const char *diff_color_words_cfg = NULL;
>>  static const char *external_diff_cmd_cfg;
>
>Guess why external_diff_cmd_cfg is not set to NULL?  All variables
>defined outside a function are set to all-zero anyway.

I suppose I just initialize variables by reflex, having been bitten with too many sometimes-crashes due to variables that were usually-zero. Assuming C does guarantee that it is zeroed, I'll drop the " = NULL" line noise in the next version.

Show 7 quoted lines
>> @@ -92,6 +93,8 @@ int git_diff_ui_config(const char *var, const char
>> *value, void *cb) }
>>  	if (!strcmp(var, "diff.external"))
>>  		return git_config_string(&external_diff_cmd_cfg, var, value);
>> +	if (!strcmp(var, "diff.color-words"))
>
>I'd call it diff.wordregex, because that's what it is.

I don't like runtogetherwords because they are hard to read for me; I tend to choose the wrong word breaks if it is ambiguous. There are other configuration values that use camelCaseWords so I will convert over to using that.

I thought "word regex" made more sense, but I wanted to match the command-line option. Will change.

Show 9 quoted lines
>> @@ -1550,6 +1553,8 @@ static void builtin_diff(const char *name_a,
>>  				o->word_regex = userdiff_word_regex(one);
>>  			if (!o->word_regex)
>>  				o->word_regex = userdiff_word_regex(two);
>> +			if (!o->word_regex)
>> +				o->word_regex = diff_color_words_cfg;
>
>IMHO this is the wrong order.  config should not override attributes,
>which are by definition more specific.

You are up too late Dscho. This ordering makes the config not override attributes. If one of the files has a diff driver, o->word_regex will be set to it (and become non-NULL). That will prevent execution of the body of the added "if (!o->word_regex)" -- preventing the configuration option from being used.

Show 12 quoted lines
>> diff --git a/t/t4034-diff-words.sh b/t/t4034-diff-words.sh
>> index 6ebce9d..a207d9e 100755
>> --- a/t/t4034-diff-words.sh
>> +++ b/t/t4034-diff-words.sh
>> @@ -105,7 +105,7 @@ a = b + c<RESET>
>>  EOF
>>  cp expect.non-whitespace-is-word expect
>>
>> -test_expect_failure 'use default supplied by config' '
>> +test_expect_success 'use default supplied by config' '
>
>Let's squash the two, okay?

Will do. I expected the code changes to be larger than the test, and when I finished it was completely the other way. My next patch will be all-in-one.

Thanks for your feedback.
-- 
Boyd Stephen Smith Jr.                     ,= ,-_-. =. 
bss@iguanasuicide.net                     ((_/)o o(\_))
ICQ: 514984 YM/AIM: DaTwinkDaddy           `-'(. .)`-' 
http://iguanasuicide.net/                      \_/     
Previous: Johannes SchindelinNext: Johannes Schindelin
Message 65 of 109 in “refactor the --color-words to make it more hackable”
  1. 0/4 refactor the --color-words to make it more hackableJohannes Schindelin, Jan 11, 2009
  2. 1/4 Add color_fwrite(), a function coloring each line individuallyJohannes Schindelin, Jan 11, 2009
  3. Junio C HamanoJan 11, 2009
  4. Johannes SchindelinJan 11, 2009
  5. 1/4 Add color_fwrite(), a function coloring each line individuallyJohannes Schindelin, Jan 11, 2009
  6. Jakub NarebskiJan 12, 2009
  7. 2/4 color-words: refactor word splitting and use ALLOC_GROW()Johannes Schindelin, Jan 11, 2009
  8. 3/4 color-words: refactor to allow for 0-character word boundariesJohannes Schindelin, Jan 11, 2009
  9. Junio C HamanoJan 11, 2009
  10. Johannes SchindelinJan 11, 2009
  11. Thomas RastJan 12, 2009
  12. Junio C HamanoJan 12, 2009
  13. 0/4 color-words improvementsJohannes Schindelin, Jan 14, 2009
  14. 1/4 Add color_fwrite_lines(), a function coloring each line individuallyJohannes Schindelin, Jan 14, 2009
  15. 2/4 color-words: refactor word splitting and use ALLOC_GROW()Johannes Schindelin, Jan 14, 2009
  16. 3/4 color-words: change algorithm to allow for 0-character word boundariesJohannes Schindelin, Jan 14, 2009
  17. Johannes SchindelinJan 14, 2009
  18. 4/4 color-words: take an optional regular expression describing wordsJohannes Schindelin, Jan 14, 2009
  19. Thomas RastJan 14, 2009
  20. Teemu LikonenJan 14, 2009
  21. Teemu LikonenJan 14, 2009
  22. Johannes SchindelinJan 14, 2009
  23. Johannes SchindelinJan 14, 2009
  24. Thomas RastJan 14, 2009
  25. Johannes SchindelinJan 14, 2009
  26. Thomas RastJan 14, 2009
  27. Boyd Stephen Smith Jr.Jan 14, 2009
  28. Teemu LikonenJan 15, 2009
  29. Johannes SchindelinJan 15, 2009
  30. Teemu LikonenJan 15, 2009
  31. Thomas RastJan 15, 2009
  32. Junio C HamanoJan 15, 2009
  33. Johannes SchindelinJan 15, 2009
  34. Santi BéjarJan 16, 2009
  35. Junio C HamanoJan 16, 2009
  36. Boyd Stephen Smith Jr.Jan 16, 2009
  37. Johannes SchindelinJan 16, 2009
  38. Santi BéjarJan 16, 2009
  39. Johannes SchindelinJan 16, 2009
  40. Santi BéjarJan 16, 2009
  41. Johannes SchindelinJan 16, 2009
  42. Thomas RastJan 16, 2009
  43. Johannes SchindelinJan 16, 2009
  44. 0/7 customizable --color-wordsThomas Rast, Jan 17, 2009
  45. 1/7 Add color_fwrite_lines(), a function coloring each line individuallyThomas Rast, Jan 17, 2009
  46. 2/7 color-words: refactor word splitting and use ALLOC_GROW()Thomas Rast, Jan 17, 2009
  47. 3/7 color-words: change algorithm to allow for 0-character word boundariesThomas Rast, Jan 17, 2009
  48. 4/7 color-words: take an optional regular expression describing wordsThomas Rast, Jan 17, 2009
  49. 5/7 color-words: enable REG_NEWLINE to help userThomas Rast, Jan 17, 2009
  50. 6/7 color-words: expand docs with precise semanticsThomas Rast, Jan 17, 2009
  51. 7/7 color-words: make regex configurable via attributesThomas Rast, Jan 17, 2009
  52. Santi BéjarJan 18, 2009
  53. Santi BéjarJan 18, 2009
  54. Santi BéjarJan 19, 2009
  55. Johannes SchindelinJan 19, 2009
  56. Add tests for diff.color-words configuration option.Boyd Stephen Smith Jr., Jan 20, 2009
  57. diff: Support diff.color-words config optionBoyd Stephen Smith Jr., Jan 20, 2009
  58. Junio C HamanoJan 20, 2009
  59. Markus HeidelbergJan 20, 2009
  60. Boyd Stephen Smith Jr.Jan 20, 2009
  61. Johannes SchindelinJan 20, 2009
  62. Junio C HamanoJan 21, 2009
  63. Markus HeidelbergJan 21, 2009
  64. Johannes SchindelinJan 20, 2009
  65. Boyd Stephen Smith Jr.Jan 20, 2009
  66. Johannes SchindelinJan 20, 2009
  67. Junio C HamanoJan 20, 2009
  68. Johannes SchindelinJan 20, 2009
  69. Junio C HamanoJan 20, 2009
  70. Johannes SchindelinJan 20, 2009
  71. color-words: Support diff.color-words config optionBoyd Stephen Smith Jr., Jan 21, 2009
  72. Change the spelling of "wordregex".Boyd Stephen Smith Jr., Jan 21, 2009
  73. Johannes SchindelinJan 21, 2009
  74. Thomas RastJan 21, 2009
  75. Boyd Stephen Smith Jr.Jan 21, 2009
  76. Johannes SchindelinJan 21, 2009
  77. Boyd Stephen Smith Jr.Jan 21, 2009
  78. Junio C HamanoJan 21, 2009
  79. Jakub NarebskiJan 20, 2009
  80. Johannes SchindelinJan 20, 2009
  81. Boyd Stephen Smith Jr.Jan 20, 2009
  82. Johannes SchindelinJan 20, 2009
  83. Boyd Stephen Smith Jr.Jan 16, 2009
  84. color-words: make regex configurable via attributesThomas Rast, Jan 14, 2009
  85. Johannes SchindelinJan 14, 2009
  86. Thomas RastJan 14, 2009
  87. 3/4 color-words: change algorithm to allow for 0-character word boundariesJohannes Schindelin, Jan 14, 2009
  88. 4/4 color-words: take an optional regular expression describing wordsJohannes Schindelin, Jan 14, 2009
  89. Thomas RastJan 15, 2009
  90. Johannes SchindelinJan 15, 2009
  91. Johannes SchindelinJan 15, 2009
  92. Thomas RastJan 15, 2009
  93. Thomas RastJan 15, 2009
  94. Johannes SchindelinJan 15, 2009
  95. 1/4 color-words: fix quoting in t4034Thomas Rast, Jan 14, 2009
  96. 2/4 color-words: enable REG_NEWLINE to help userThomas Rast, Jan 14, 2009
  97. 3/4 color-words: expand docs with precise semanticsThomas Rast, Jan 14, 2009
  98. 4/4 color-words: make regex configurable via attributesThomas Rast, Jan 14, 2009
  99. Johannes SchindelinJan 15, 2009
  100. Johannes SchindelinJan 15, 2009
  101. Johannes SchindelinJan 14, 2009
  102. Thomas RastJan 14, 2009
  103. Johannes SchindelinJan 14, 2009
  104. Thomas RastJan 14, 2009
  105. 4/4 color-words: take an optional regular expression describing wordsJohannes Schindelin, Jan 11, 2009
  106. Thomas RastJan 11, 2009
  107. Johannes SchindelinJan 11, 2009
  108. Thomas RastJan 12, 2009
  109. Santi BéjarJan 14, 2009

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.