Skip to content

Commit c80a40a

Browse files
committed
Merge branch 'jc/string-list-split' into seen
string_list_split*() family of functions have been extended to simplify common use cases. Comments? * jc/string-list-split: string-list: split-then-remove-empty can be done while splitting string-list: optionally omit empty string pieces in string_list_split*() diff: simplify parsing of diff.colormovedws string-list: optionally trim string pieces split by string_list_split*() string-list: unify string_list_split* functions string-list: align string_list_split() with its _in_place() counterpart string-list: report programming error with BUG
2 parents 7ff6828 + 9eb8d87 commit c80a40a

21 files changed

+222
-90
lines changed

builtin/blame.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ static void parse_color_fields(const char *s)
413413
colorfield_nr = 0;
414414

415415
/* Ideally this would be stripped and split at the same time? */
416-
string_list_split(&l, s, ',', -1);
416+
string_list_split(&l, s, ",", -1);
417417
ALLOC_GROW(colorfield, colorfield_nr + 1, colorfield_alloc);
418418

419419
for_each_string_list_item(item, &l) {

builtin/merge.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -875,7 +875,7 @@ static void add_strategies(const char *string, unsigned attr)
875875
if (string) {
876876
struct string_list list = STRING_LIST_INIT_DUP;
877877
struct string_list_item *item;
878-
string_list_split(&list, string, ' ', -1);
878+
string_list_split(&list, string, " ", -1);
879879
for_each_string_list_item(item, &list)
880880
append_strategy(get_strategy(item->string));
881881
string_list_clear(&list, 0);

builtin/var.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ static void list_vars(void)
182182
if (ptr->multivalued && *val) {
183183
struct string_list list = STRING_LIST_INIT_DUP;
184184

185-
string_list_split(&list, val, '\n', -1);
185+
string_list_split(&list, val, "\n", -1);
186186
for (size_t i = 0; i < list.nr; i++)
187187
printf("%s=%s\n", ptr->name, list.items[i].string);
188188
string_list_clear(&list, 0);

connect.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ static int process_ref_v2(struct packet_reader *reader, struct ref ***list,
407407
* name. Subsequent fields (symref-target and peeled) are optional and
408408
* don't have a particular order.
409409
*/
410-
if (string_list_split(&line_sections, line, ' ', -1) < 2) {
410+
if (string_list_split(&line_sections, line, " ", -1) < 2) {
411411
ret = 0;
412412
goto out;
413413
}

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) &&

fetch-pack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1914,7 +1914,7 @@ static void fetch_pack_config(void)
19141914
char *str;
19151915

19161916
if (!repo_config_get_string(the_repository, "fetch.uriprotocols", &str) && str) {
1917-
string_list_split(&uri_protocols, str, ',', -1);
1917+
string_list_split(&uri_protocols, str, ",", -1);
19181918
free(str);
19191919
}
19201920
}

notes.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -894,7 +894,7 @@ static int string_list_add_note_lines(struct string_list *list,
894894
* later, along with any empty strings that came from empty
895895
* lines within the file.
896896
*/
897-
string_list_split(list, data, '\n', -1);
897+
string_list_split(list, data, "\n", -1);
898898
free(data);
899899
return 0;
900900
}
@@ -973,8 +973,8 @@ void string_list_add_refs_from_colon_sep(struct string_list *list,
973973
char *globs_copy = xstrdup(globs);
974974
int i;
975975

976-
string_list_split_in_place(&split, globs_copy, ":", -1);
977-
string_list_remove_empty_items(&split, 0);
976+
string_list_split_in_place_f(&split, globs_copy, ":", -1,
977+
STRING_LIST_SPLIT_NONEMPTY);
978978

979979
for (i = 0; i < split.nr; i++)
980980
string_list_add_refs_by_glob(list, split.items[i].string);

parse-options.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1338,7 +1338,7 @@ static enum parse_opt_result usage_with_options_internal(struct parse_opt_ctx_t
13381338
if (!saw_empty_line && !*str)
13391339
saw_empty_line = 1;
13401340

1341-
string_list_split(&list, str, '\n', -1);
1341+
string_list_split(&list, str, "\n", -1);
13421342
for (j = 0; j < list.nr; j++) {
13431343
const char *line = list.items[j].string;
13441344

pathspec.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,7 @@ static void parse_pathspec_attr_match(struct pathspec_item *item, const char *va
201201
if (!value || !*value)
202202
die(_("attr spec must not be empty"));
203203

204-
string_list_split(&list, value, ' ', -1);
205-
string_list_remove_empty_items(&list, 0);
204+
string_list_split_f(&list, value, " ", -1, STRING_LIST_SPLIT_NONEMPTY);
206205

207206
item->attr_check = attr_check_alloc();
208207
CALLOC_ARRAY(item->attr_match, list.nr);

protocol.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ enum protocol_version determine_protocol_version_server(void)
6161
if (git_protocol) {
6262
struct string_list list = STRING_LIST_INIT_DUP;
6363
const struct string_list_item *item;
64-
string_list_split(&list, git_protocol, ':', -1);
64+
string_list_split(&list, git_protocol, ":", -1);
6565

6666
for_each_string_list_item(item, &list) {
6767
const char *value;

0 commit comments

Comments
 (0)