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>

Patrick Steinhardt committed Jun 15, 2023 at 16:39 UTC af37a209ad76ce760becc0d2c2fac63c2022e730
1 file changed +9 -8
revision.c
+9 -8
@@ -2795,16 +2795,17 @@ static void read_revisions_from_stdin(struct rev_info *revs,
2795
2796 strbuf_init(&sb, 1000);
2797 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;
2803 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");
2804 }
2805 +
2806 + if (sb.buf[0] == '-')
2807 + die("options not supported in --stdin mode");
2808 +
2809 if (handle_revision_arg(sb.buf, revs, 0,
2810 REVARG_CANNOT_BE_FILENAME))
2811 die("bad revision '%s'", sb.buf);