From: Justin Tobler <jltobler@gmail.com>
To: git@vger.kernel.org
Cc: ps@pks.im, christian.couder@gmail.com, peff@peff.net,
ben.knoble@gmail.com, Justin Tobler <jltobler@gmail.com>
Subject: [PATCH v2 3/6] revision: support NUL-delimited --stdin mode
Date: Wed, 12 Mar 2025 19:17:03 -0500 [thread overview]
Message-ID: <20250313001706.3390502-4-jltobler@gmail.com> (raw)
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
next prev parent reply other threads:[~2025-03-13 0:21 UTC|newest]
Thread overview: 60+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-10 19:28 [PATCH 0/4] rev-list: introduce NUL-delimited output mode Justin Tobler
2025-03-10 19:28 ` [PATCH 1/4] rev-list: inline `show_object_with_name()` in `show_object()` Justin Tobler
2025-03-10 20:51 ` Junio C Hamano
2025-03-10 19:28 ` [PATCH 2/4] rev-list: refactor early option parsing Justin Tobler
2025-03-10 20:54 ` Junio C Hamano
2025-03-12 21:39 ` Justin Tobler
2025-03-10 19:28 ` [PATCH 3/4] rev-list: support delimiting objects with NUL bytes Justin Tobler
2025-03-10 20:59 ` Junio C Hamano
2025-03-12 21:39 ` Justin Tobler
2025-03-12 7:50 ` Patrick Steinhardt
2025-03-12 21:41 ` Justin Tobler
2025-03-10 19:28 ` [PATCH 4/4] rev-list: support NUL-delimited --missing option Justin Tobler
2025-03-10 20:37 ` [PATCH 0/4] rev-list: introduce NUL-delimited output mode Junio C Hamano
2025-03-10 21:08 ` Junio C Hamano
2025-03-11 23:24 ` Justin Tobler
2025-03-11 23:19 ` Justin Tobler
2025-03-11 23:44 ` Junio C Hamano
2025-03-12 7:37 ` Patrick Steinhardt
2025-03-12 21:45 ` Justin Tobler
2025-03-10 22:38 ` D. Ben Knoble
2025-03-11 22:59 ` Justin Tobler
2025-03-11 23:57 ` Jeff King
2025-03-12 7:42 ` Patrick Steinhardt
2025-03-12 15:56 ` Junio C Hamano
2025-03-13 7:46 ` Patrick Steinhardt
2025-03-12 22:09 ` Justin Tobler
2025-03-13 5:33 ` Jeff King
2025-03-13 16:41 ` Justin Tobler
2025-03-14 2:49 ` Jeff King
2025-03-14 17:02 ` Junio C Hamano
2025-03-14 18:59 ` Jeff King
2025-03-14 19:53 ` Justin Tobler
2025-03-14 21:16 ` Junio C Hamano
2025-03-19 15:58 ` Justin Tobler
2025-03-13 0:17 ` [PATCH v2 0/6] " Justin Tobler
2025-03-13 0:17 ` [PATCH v2 1/6] rev-list: inline `show_object_with_name()` in `show_object()` Justin Tobler
2025-03-13 0:17 ` [PATCH v2 2/6] rev-list: refactor early option parsing Justin Tobler
2025-03-13 0:17 ` Justin Tobler [this message]
2025-03-13 0:17 ` [PATCH v2 4/6] rev-list: support delimiting objects with NUL bytes Justin Tobler
2025-03-13 12:55 ` Patrick Steinhardt
2025-03-13 14:44 ` Justin Tobler
2025-03-13 0:17 ` [PATCH v2 5/6] rev-list: support NUL-delimited --boundary option Justin Tobler
2025-03-13 0:17 ` [PATCH v2 6/6] rev-list: support NUL-delimited --missing option Justin Tobler
2025-03-13 12:55 ` Patrick Steinhardt
2025-03-13 14:51 ` Justin Tobler
2025-03-13 23:57 ` [PATCH v3 0/6] rev-list: introduce NUL-delimited output mode Justin Tobler
2025-03-13 23:57 ` [PATCH v3 1/6] rev-list: inline `show_object_with_name()` in `show_object()` Justin Tobler
2025-03-13 23:57 ` [PATCH v3 2/6] rev-list: refactor early option parsing Justin Tobler
2025-03-13 23:57 ` [PATCH v3 3/6] revision: support NUL-delimited --stdin mode Justin Tobler
2025-03-13 23:57 ` [PATCH v3 4/6] rev-list: support delimiting objects with NUL bytes Justin Tobler
2025-03-19 12:35 ` Christian Couder
2025-03-19 16:02 ` Justin Tobler
2025-03-13 23:57 ` [PATCH v3 5/6] rev-list: support NUL-delimited --boundary option Justin Tobler
2025-03-13 23:57 ` [PATCH v3 6/6] rev-list: support NUL-delimited --missing option Justin Tobler
2025-03-19 18:34 ` [PATCH v4 0/5] rev-list: introduce NUL-delimited output mode Justin Tobler
2025-03-19 18:34 ` [PATCH v4 1/5] rev-list: inline `show_object_with_name()` in `show_object()` Justin Tobler
2025-03-19 18:34 ` [PATCH v4 2/5] rev-list: refactor early option parsing Justin Tobler
2025-03-19 18:34 ` [PATCH v4 3/5] rev-list: support delimiting objects with NUL bytes Justin Tobler
2025-03-19 18:34 ` [PATCH v4 4/5] rev-list: support NUL-delimited --boundary option Justin Tobler
2025-03-19 18:34 ` [PATCH v4 5/5] rev-list: support NUL-delimited --missing option Justin Tobler
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250313001706.3390502-4-jltobler@gmail.com \
--to=jltobler@gmail.com \
--cc=ben.knoble@gmail.com \
--cc=christian.couder@gmail.com \
--cc=git@vger.kernel.org \
--cc=peff@peff.net \
--cc=ps@pks.im \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).