Skip to content

Commit 927eae1

Browse files
committed
notes: do not use strbuf_split*()
When reading copy instructions from the standard input, the program reads a line, splits it into tokens at whitespace, and trims each of the tokens before using. We no longer need to use strbuf just to be able to trim, as string_list_split*() family now can trim while splitting a string. Retire the use of strbuf_split() from this code path. Note that this loop is a bit sloppy in that it ensures at least there are two tokens on each line, but ignores if there are extra tokens on the line. Tightening it is outside the scope of this series. Signed-off-by: Junio C Hamano <[email protected]>
1 parent a0daa1b commit 927eae1

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

builtin/notes.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -375,18 +375,19 @@ static int notes_copy_from_stdin(int force, const char *rewrite_cmd)
375375

376376
while (strbuf_getline_lf(&buf, stdin) != EOF) {
377377
struct object_id from_obj, to_obj;
378-
struct strbuf **split;
378+
struct string_list split = STRING_LIST_INIT_NODUP;
379379
int err;
380380

381-
split = strbuf_split(&buf, ' ');
382-
if (!split[0] || !split[1])
381+
string_list_split_in_place_f(&split, buf.buf, " ", -1,
382+
STRING_LIST_SPLIT_TRIM);
383+
if (split.nr < 2)
383384
die(_("malformed input line: '%s'."), buf.buf);
384-
strbuf_rtrim(split[0]);
385-
strbuf_rtrim(split[1]);
386-
if (repo_get_oid(the_repository, split[0]->buf, &from_obj))
387-
die(_("failed to resolve '%s' as a valid ref."), split[0]->buf);
388-
if (repo_get_oid(the_repository, split[1]->buf, &to_obj))
389-
die(_("failed to resolve '%s' as a valid ref."), split[1]->buf);
385+
if (repo_get_oid(the_repository, split.items[0].string, &from_obj))
386+
die(_("failed to resolve '%s' as a valid ref."),
387+
split.items[0].string);
388+
if (repo_get_oid(the_repository, split.items[1].string, &to_obj))
389+
die(_("failed to resolve '%s' as a valid ref."),
390+
split.items[1].string);
390391

391392
if (rewrite_cmd)
392393
err = copy_note_for_rewrite(c, &from_obj, &to_obj);
@@ -396,11 +397,11 @@ static int notes_copy_from_stdin(int force, const char *rewrite_cmd)
396397

397398
if (err) {
398399
error(_("failed to copy notes from '%s' to '%s'"),
399-
split[0]->buf, split[1]->buf);
400+
split.items[0].string, split.items[1].string);
400401
ret = 1;
401402
}
402403

403-
strbuf_list_free(split);
404+
string_list_clear(&split, 0);
404405
}
405406

406407
if (!rewrite_cmd) {

0 commit comments

Comments
 (0)