Skip to content

Commit a0daa1b

Browse files
committed
merge-tree: do not use strbuf_split*()
When reading merge instructions from the standard input, the program reads from the standard input, splits the line into tokens at whitespace, and trims each of them before using. We no longer need to use strbuf just for trimming, as string_list_split*() family can trim while splitting a string. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 067fef8 commit a0daa1b

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

builtin/merge-tree.c

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -618,32 +618,34 @@ int cmd_merge_tree(int argc,
618618
"--merge-base", "--stdin");
619619
line_termination = '\0';
620620
while (strbuf_getline_lf(&buf, stdin) != EOF) {
621-
struct strbuf **split;
621+
struct string_list split = STRING_LIST_INIT_NODUP;
622622
const char *input_merge_base = NULL;
623623

624-
split = strbuf_split(&buf, ' ');
625-
if (!split[0] || !split[1])
624+
string_list_split_in_place_f(&split, buf.buf, " ", -1,
625+
STRING_LIST_SPLIT_TRIM);
626+
627+
if (split.nr < 2)
626628
die(_("malformed input line: '%s'."), buf.buf);
627-
strbuf_rtrim(split[0]);
628-
strbuf_rtrim(split[1]);
629629

630630
/* parse the merge-base */
631-
if (!strcmp(split[1]->buf, "--")) {
632-
input_merge_base = split[0]->buf;
631+
if (!strcmp(split.items[1].string, "--")) {
632+
input_merge_base = split.items[0].string;
633633
}
634634

635-
if (input_merge_base && split[2] && split[3] && !split[4]) {
636-
strbuf_rtrim(split[2]);
637-
strbuf_rtrim(split[3]);
638-
real_merge(&o, input_merge_base, split[2]->buf, split[3]->buf, prefix);
639-
} else if (!input_merge_base && !split[2]) {
640-
real_merge(&o, NULL, split[0]->buf, split[1]->buf, prefix);
635+
if (input_merge_base && split.nr == 4) {
636+
real_merge(&o, input_merge_base,
637+
split.items[2].string, split.items[3].string,
638+
prefix);
639+
} else if (!input_merge_base && split.nr == 2) {
640+
real_merge(&o, NULL,
641+
split.items[0].string, split.items[1].string,
642+
prefix);
641643
} else {
642644
die(_("malformed input line: '%s'."), buf.buf);
643645
}
644646
maybe_flush_or_die(stdout, "stdout");
645647

646-
strbuf_list_free(split);
648+
string_list_clear(&split, 0);
647649
}
648650
strbuf_release(&buf);
649651

0 commit comments

Comments
 (0)