git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 3/6] revision: support NUL-delimited --stdin mode

From
Justin Tobler <jltobler@gmail.com>
Date
Mar 13, 2025, 00:17 UTC
Message-ID
<20250313001706.3390502-4-jltobler@gmail.com>
In-Reply-To
<20250313001706.3390502-1-jltobler@gmail.com>

When `setup_revisions()` parses the `--stdin` option, revision and pathspec arguments are read from stdin. Each line of input is handled as a separate argument.

Introduce the `nul_delim_stdin` field to `setup_revision_opt` that, when enabled, uses a NUL byte to delimit between stdin arguments instead of newline.

Signed-off-by: Justin Tobler <jltobler@gmail.com>
---
 revision.c | 19 +++++++++++--------
 revision.h |  3 ++-
 2 files changed, 13 insertions(+), 9 deletions(-)
diff --git a/revision.c b/revision.c
index 0eaebe4478..5de6309830 100644
--- a/revision.c
+++ b/revision.c
@@ -2275,10 +2275,10 @@ int handle_revision_arg(const char *arg, struct rev_info *revs, int flags, unsig
 	return ret;
 }
 
-static void read_pathspec_from_stdin(struct strbuf *sb,
-				     struct strvec *prune)
+static void read_pathspec_from_stdin(struct strbuf *sb, struct strvec *prune,
+				     int line_term)
 {
-	while (strbuf_getline(sb, stdin) != EOF)
+	while (strbuf_getdelim_strip_crlf(sb, stdin, line_term) != EOF)
 		strvec_push(prune, sb->buf);
 }
 
@@ -2905,8 +2905,8 @@ static int handle_revision_pseudo_opt(struct rev_info *revs,
 	return 1;
 }
 
-static void read_revisions_from_stdin(struct rev_info *revs,
-				      struct strvec *prune)
+static void read_revisions_from_stdin(struct rev_info *revs, struct strvec *prune,
+				      int line_term)
 {
 	struct strbuf sb;
 	int seen_dashdash = 0;
@@ -2918,7 +2918,7 @@ static void read_revisions_from_stdin(struct rev_info *revs,
 	warn_on_object_refname_ambiguity = 0;
 
 	strbuf_init(&sb, 1000);
-	while (strbuf_getline(&sb, stdin) != EOF) {
+	while (strbuf_getdelim_strip_crlf(&sb, stdin, line_term) != EOF) {
 		if (!sb.len)
 			break;
 
@@ -2946,7 +2946,7 @@ static void read_revisions_from_stdin(struct rev_info *revs,
 			die("bad revision '%s'", sb.buf);
 	}
 	if (seen_dashdash)
-		read_pathspec_from_stdin(&sb, prune);
+		read_pathspec_from_stdin(&sb, prune, line_term);
 
 	strbuf_release(&sb);
 	warn_on_object_refname_ambiguity = save_warning;
@@ -3019,13 +3019,16 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
 			}
 
 			if (!strcmp(arg, "--stdin")) {
+				int term = opt && opt->nul_delim_stdin ? '\0' : '\n';
+
 				if (revs->disable_stdin) {
 					argv[left++] = arg;
 					continue;
 				}
 				if (revs->read_from_stdin++)
 					die("--stdin given twice?");
-				read_revisions_from_stdin(revs, &prune_data);
+				read_revisions_from_stdin(revs, &prune_data,
+							  term);
 				continue;
 			}
 
diff --git a/revision.h b/revision.h
index 21c6a69899..0e680c3667 100644
--- a/revision.h
+++ b/revision.h
@@ -439,7 +439,8 @@ struct setup_revision_opt {
 	void (*tweak)(struct rev_info *);
 	unsigned int	assume_dashdash:1,
 			allow_exclude_promisor_objects:1,
-			free_removed_argv_elements:1;
+			free_removed_argv_elements:1,
+			nul_delim_stdin:1;
 	unsigned revarg_opt;
 };
 int setup_revisions(int argc, const char **argv, struct rev_info *revs,
-- 
2.49.0.rc2
Previous: Justin ToblerNext: Justin Tobler
Message 38 of 60 in “rev-list: introduce NUL-delimited output mode”
  1. 0/4 rev-list: introduce NUL-delimited output modeJustin Tobler, Mar 10, 2025
  2. 1/4 rev-list: inline `show_object_with_name()` in `show_object()`Justin Tobler, Mar 10, 2025
  3. Junio C HamanoMar 10, 2025
  4. 2/4 rev-list: refactor early option parsingJustin Tobler, Mar 10, 2025
  5. Junio C HamanoMar 10, 2025
  6. Justin ToblerMar 12, 2025
  7. 3/4 rev-list: support delimiting objects with NUL bytesJustin Tobler, Mar 10, 2025
  8. Junio C HamanoMar 10, 2025
  9. Justin ToblerMar 12, 2025
  10. Patrick SteinhardtMar 12, 2025
  11. Justin ToblerMar 12, 2025
  12. 4/4 rev-list: support NUL-delimited --missing optionJustin Tobler, Mar 10, 2025
  13. Junio C HamanoMar 10, 2025
  14. Junio C HamanoMar 10, 2025
  15. Justin ToblerMar 11, 2025
  16. Justin ToblerMar 11, 2025
  17. Junio C HamanoMar 11, 2025
  18. Patrick SteinhardtMar 12, 2025
  19. Justin ToblerMar 12, 2025
  20. D. Ben KnobleMar 10, 2025
  21. Justin ToblerMar 11, 2025
  22. Jeff KingMar 11, 2025
  23. Patrick SteinhardtMar 12, 2025
  24. Junio C HamanoMar 12, 2025
  25. Patrick SteinhardtMar 13, 2025
  26. Justin ToblerMar 12, 2025
  27. Jeff KingMar 13, 2025
  28. Justin ToblerMar 13, 2025
  29. Jeff KingMar 14, 2025
  30. Junio C HamanoMar 14, 2025
  31. Jeff KingMar 14, 2025
  32. Justin ToblerMar 14, 2025
  33. Junio C HamanoMar 14, 2025
  34. Justin ToblerMar 19, 2025
  35. 0/6 rev-list: introduce NUL-delimited output modeJustin Tobler, Mar 13, 2025
  36. 1/6 rev-list: inline `show_object_with_name()` in `show_object()`Justin Tobler, Mar 13, 2025
  37. 2/6 rev-list: refactor early option parsingJustin Tobler, Mar 13, 2025
  38. 3/6 revision: support NUL-delimited --stdin modeJustin Tobler, Mar 13, 2025
  39. 4/6 rev-list: support delimiting objects with NUL bytesJustin Tobler, Mar 13, 2025
  40. Patrick SteinhardtMar 13, 2025
  41. Justin ToblerMar 13, 2025
  42. 5/6 rev-list: support NUL-delimited --boundary optionJustin Tobler, Mar 13, 2025
  43. 6/6 rev-list: support NUL-delimited --missing optionJustin Tobler, Mar 13, 2025
  44. Patrick SteinhardtMar 13, 2025
  45. Justin ToblerMar 13, 2025
  46. 0/6 rev-list: introduce NUL-delimited output modeJustin Tobler, Mar 13, 2025
  47. 1/6 rev-list: inline `show_object_with_name()` in `show_object()`Justin Tobler, Mar 13, 2025
  48. 2/6 rev-list: refactor early option parsingJustin Tobler, Mar 13, 2025
  49. 3/6 revision: support NUL-delimited --stdin modeJustin Tobler, Mar 13, 2025
  50. 4/6 rev-list: support delimiting objects with NUL bytesJustin Tobler, Mar 13, 2025
  51. Christian CouderMar 19, 2025
  52. Justin ToblerMar 19, 2025
  53. 5/6 rev-list: support NUL-delimited --boundary optionJustin Tobler, Mar 13, 2025
  54. 6/6 rev-list: support NUL-delimited --missing optionJustin Tobler, Mar 13, 2025
  55. 0/5 rev-list: introduce NUL-delimited output modeJustin Tobler, Mar 19, 2025
  56. 1/5 rev-list: inline `show_object_with_name()` in `show_object()`Justin Tobler, Mar 19, 2025
  57. 2/5 rev-list: refactor early option parsingJustin Tobler, Mar 19, 2025
  58. 3/5 rev-list: support delimiting objects with NUL bytesJustin Tobler, Mar 19, 2025
  59. 4/5 rev-list: support NUL-delimited --boundary optionJustin Tobler, Mar 19, 2025
  60. 5/5 rev-list: support NUL-delimited --missing optionJustin Tobler, Mar 19, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.