revision: small readability improvement for reading from stdin
The code that reads lines from standard input manually compares whether the read line matches "--", which is a bit awkward to read. Furthermore, we're about to extend the code to also support reading pseudo-options via standard input, requiring more elaborate handling of lines with a leading dash. Refactor the code by hoisting out the check for "--" outside of the block that checks for a leading dash. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
cc8045018d
commit
af37a209ad
11
revision.c
11
revision.c
@ -2795,16 +2795,17 @@ static void read_revisions_from_stdin(struct rev_info *revs,
|
|||||||
|
|
||||||
strbuf_init(&sb, 1000);
|
strbuf_init(&sb, 1000);
|
||||||
while (strbuf_getline(&sb, stdin) != EOF) {
|
while (strbuf_getline(&sb, stdin) != EOF) {
|
||||||
int len = sb.len;
|
if (!sb.len)
|
||||||
if (!len)
|
|
||||||
break;
|
break;
|
||||||
if (sb.buf[0] == '-') {
|
|
||||||
if (len == 2 && sb.buf[1] == '-') {
|
if (!strcmp(sb.buf, "--")) {
|
||||||
seen_dashdash = 1;
|
seen_dashdash = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (sb.buf[0] == '-')
|
||||||
die("options not supported in --stdin mode");
|
die("options not supported in --stdin mode");
|
||||||
}
|
|
||||||
if (handle_revision_arg(sb.buf, revs, 0,
|
if (handle_revision_arg(sb.buf, revs, 0,
|
||||||
REVARG_CANNOT_BE_FILENAME))
|
REVARG_CANNOT_BE_FILENAME))
|
||||||
die("bad revision '%s'", sb.buf);
|
die("bad revision '%s'", sb.buf);
|
||||||
|
Loading…
Reference in New Issue
Block a user