Skip to content

Commit af37a20

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent cc80450 commit af37a20

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

revision.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2795,16 +2795,17 @@ static void read_revisions_from_stdin(struct rev_info *revs,
27952795

27962796
strbuf_init(&sb, 1000);
27972797
while (strbuf_getline(&sb, stdin) != EOF) {
2798-
int len = sb.len;
2799-
if (!len)
2798+
if (!sb.len)
2799+
break;
2800+
2801+
if (!strcmp(sb.buf, "--")) {
2802+
seen_dashdash = 1;
28002803
break;
2801-
if (sb.buf[0] == '-') {
2802-
if (len == 2 && sb.buf[1] == '-') {
2803-
seen_dashdash = 1;
2804-
break;
2805-
}
2806-
die("options not supported in --stdin mode");
28072804
}
2805+
2806+
if (sb.buf[0] == '-')
2807+
die("options not supported in --stdin mode");
2808+
28082809
if (handle_revision_arg(sb.buf, revs, 0,
28092810
REVARG_CANNOT_BE_FILENAME))
28102811
die("bad revision '%s'", sb.buf);

0 commit comments

Comments
 (0)