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 <gitster@pobox.com>
This commit is contained in:
@@ -375,18 +375,19 @@ static int notes_copy_from_stdin(int force, const char *rewrite_cmd)
|
|||||||
|
|
||||||
while (strbuf_getline_lf(&buf, stdin) != EOF) {
|
while (strbuf_getline_lf(&buf, stdin) != EOF) {
|
||||||
struct object_id from_obj, to_obj;
|
struct object_id from_obj, to_obj;
|
||||||
struct strbuf **split;
|
struct string_list split = STRING_LIST_INIT_NODUP;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
split = strbuf_split(&buf, ' ');
|
string_list_split_in_place_f(&split, buf.buf, " ", -1,
|
||||||
if (!split[0] || !split[1])
|
STRING_LIST_SPLIT_TRIM);
|
||||||
|
if (split.nr < 2)
|
||||||
die(_("malformed input line: '%s'."), buf.buf);
|
die(_("malformed input line: '%s'."), buf.buf);
|
||||||
strbuf_rtrim(split[0]);
|
if (repo_get_oid(the_repository, split.items[0].string, &from_obj))
|
||||||
strbuf_rtrim(split[1]);
|
die(_("failed to resolve '%s' as a valid ref."),
|
||||||
if (repo_get_oid(the_repository, split[0]->buf, &from_obj))
|
split.items[0].string);
|
||||||
die(_("failed to resolve '%s' as a valid ref."), split[0]->buf);
|
if (repo_get_oid(the_repository, split.items[1].string, &to_obj))
|
||||||
if (repo_get_oid(the_repository, split[1]->buf, &to_obj))
|
die(_("failed to resolve '%s' as a valid ref."),
|
||||||
die(_("failed to resolve '%s' as a valid ref."), split[1]->buf);
|
split.items[1].string);
|
||||||
|
|
||||||
if (rewrite_cmd)
|
if (rewrite_cmd)
|
||||||
err = copy_note_for_rewrite(c, &from_obj, &to_obj);
|
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)
|
|||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
error(_("failed to copy notes from '%s' to '%s'"),
|
error(_("failed to copy notes from '%s' to '%s'"),
|
||||||
split[0]->buf, split[1]->buf);
|
split.items[0].string, split.items[1].string);
|
||||||
ret = 1;
|
ret = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
strbuf_list_free(split);
|
string_list_clear(&split, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!rewrite_cmd) {
|
if (!rewrite_cmd) {
|
||||||
|
|||||||
Reference in New Issue
Block a user