Skip to content

Commit ad8b425

Browse files
committed
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 <[email protected]>
1 parent 9d7d22e commit ad8b425

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

diff.c

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -327,29 +327,23 @@ static unsigned parse_color_moved_ws(const char *arg)
327327
struct string_list l = STRING_LIST_INIT_DUP;
328328
struct string_list_item *i;
329329

330-
string_list_split(&l, arg, ",", -1);
330+
string_list_split_f(&l, arg, ",", -1, STRING_LIST_SPLIT_TRIM);
331331

332332
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"))
338334
ret = 0;
339-
else if (!strcmp(sb.buf, "ignore-space-change"))
335+
else if (!strcmp(i->string, "ignore-space-change"))
340336
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"))
342338
ret |= XDF_IGNORE_WHITESPACE_AT_EOL;
343-
else if (!strcmp(sb.buf, "ignore-all-space"))
339+
else if (!strcmp(i->string, "ignore-all-space"))
344340
ret |= XDF_IGNORE_WHITESPACE;
345-
else if (!strcmp(sb.buf, "allow-indentation-change"))
341+
else if (!strcmp(i->string, "allow-indentation-change"))
346342
ret |= COLOR_MOVED_WS_ALLOW_INDENTATION_CHANGE;
347343
else {
348344
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);
350346
}
351-
352-
strbuf_release(&sb);
353347
}
354348

355349
if ((ret & COLOR_MOVED_WS_ALLOW_INDENTATION_CHANGE) &&

0 commit comments

Comments
 (0)