Thread (9 messages) 9 messages, 2 authors, 2023-06-15
STALE1100d

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

From: Patrick Steinhardt <hidden>
Date: 2023-06-14 12:18:58
Subsystem: the rest · Maintainer: Linus Torvalds

The code that reads lines from standard input manually compares whether
the read line matches "--", which is a bit awkward to read. Refactor it
to instead use strcmp(3P) for a small code style improvement.

Signed-off-by: Patrick Steinhardt <redacted>
---
 revision.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/revision.c b/revision.c
index cc22ccd76e..dcb7951b4e 100644
--- a/revision.c
+++ b/revision.c
@@ -2795,16 +2795,18 @@ 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 (sb.buf[0] == '-') {
-			if (len == 2 && sb.buf[1] == '-') {
+			if (!strcmp(sb.buf, "--")) {
 				seen_dashdash = 1;
 				break;
 			}
+
 			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);
-- 
2.41.0

Attachments

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help