diff mbox series

[v2,2/3] revision: small readability improvement for reading from stdin

Message ID 5c1a9a0d08b25ce94ba1498cd88051abd062369c.1686839572.git.ps@pks.im (mailing list archive)
State Accepted
Commit af37a209ad76ce760becc0d2c2fac63c2022e730
Headers show
Series revision: handle pseudo-opts in `--stdin` mode | expand

Commit Message

Patrick Steinhardt June 15, 2023, 2:39 p.m. UTC
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>
---
 revision.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)
diff mbox series

Patch

diff --git a/revision.c b/revision.c
index cc22ccd76e..3a39f41bb8 100644
--- a/revision.c
+++ b/revision.c
@@ -2795,16 +2795,17 @@  static void read_revisions_from_stdin(struct rev_info *revs,
 
 	strbuf_init(&sb, 1000);
 	while (strbuf_getline(&sb, stdin) != EOF) {
-		int len = sb.len;
-		if (!len)
+		if (!sb.len)
+			break;
+
+		if (!strcmp(sb.buf, "--")) {
+			seen_dashdash = 1;
 			break;
-		if (sb.buf[0] == '-') {
-			if (len == 2 && sb.buf[1] == '-') {
-				seen_dashdash = 1;
-				break;
-			}
-			die("options not supported in --stdin mode");
 		}
+
+		if (sb.buf[0] == '-')
+			die("options not supported in --stdin mode");
+
 		if (handle_revision_arg(sb.buf, revs, 0,
 					REVARG_CANNOT_BE_FILENAME))
 			die("bad revision '%s'", sb.buf);