diff: simplify parsing of diff.colormovedws
The code to parse this configuration variable, whose value is a comma-separated list of known tokens like "ignore-space-change" and "ignore-all-space", uses string_list_split() to split the value into pieces, and then places each piece of string in a strbuf to trim, before comparing the result with the list of known tokens. Thanks to the previous steps, now string_list_split() can trim the resulting pieces before it places them in the string list. Use it to simplify the code. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Aug 1, 2025 at 15:04 UTC
f3a303aef017ad6e53fa44643d832a1fa0de0d91
1 file changed
+7
-13
diff.c
+7
-13
@@ -327,29 +327,23 @@ static unsigned parse_color_moved_ws(const char *arg)
327
struct string_list l = STRING_LIST_INIT_DUP;
328
struct string_list_item *i;
329
330
- string_list_split(&l, arg, ",", -1);
330
+ string_list_split_f(&l, arg, ",", -1, STRING_LIST_SPLIT_TRIM);
331
332
for_each_string_list_item(i, &l) {
333
- struct strbuf sb = STRBUF_INIT;
334
- strbuf_addstr(&sb, i->string);
335
- strbuf_trim(&sb);
336
-
337
- if (!strcmp(sb.buf, "no"))
333
+ if (!strcmp(i->string, "no"))
334
ret = 0;
339
- else if (!strcmp(sb.buf, "ignore-space-change"))
335
+ else if (!strcmp(i->string, "ignore-space-change"))
336
ret |= XDF_IGNORE_WHITESPACE_CHANGE;
341
- else if (!strcmp(sb.buf, "ignore-space-at-eol"))
337
+ else if (!strcmp(i->string, "ignore-space-at-eol"))
338
ret |= XDF_IGNORE_WHITESPACE_AT_EOL;
343
- else if (!strcmp(sb.buf, "ignore-all-space"))
339
+ else if (!strcmp(i->string, "ignore-all-space"))
340
ret |= XDF_IGNORE_WHITESPACE;
345
- else if (!strcmp(sb.buf, "allow-indentation-change"))
341
+ else if (!strcmp(i->string, "allow-indentation-change"))
342
ret |= COLOR_MOVED_WS_ALLOW_INDENTATION_CHANGE;
343
else {
344
ret |= COLOR_MOVED_WS_ERROR;
349
- error(_("unknown color-moved-ws mode '%s', possible values are 'ignore-space-change', 'ignore-space-at-eol', 'ignore-all-space', 'allow-indentation-change'"), sb.buf);
345
+ error(_("unknown color-moved-ws mode '%s', possible values are 'ignore-space-change', 'ignore-space-at-eol', 'ignore-all-space', 'allow-indentation-change'"), i->string);
346
}
351
-
352
- strbuf_release(&sb);
347
}
348
349
if ((ret & COLOR_MOVED_WS_ALLOW_INDENTATION_CHANGE) &&