@@ -1355,7 +1355,7 @@ static void write_commit_patch(const struct am_state *state, struct commit *comm
repo_init_revisions(the_repository, &rev_info, NULL);
rev_info.diff = 1;
rev_info.abbrev = 0;
- rev_info.disable_stdin = 1;
+ rev_info.stdin_handling = REV_INFO_STDIN_IGNORE;
rev_info.show_root_diff = 1;
rev_info.diffopt.output_format = DIFF_FORMAT_PATCH;
rev_info.no_commit_id = 1;
@@ -1390,7 +1390,7 @@ static void write_index_patch(const struct am_state *state)
fp = xfopen(am_path(state, "patch"), "w");
repo_init_revisions(the_repository, &rev_info, NULL);
rev_info.diff = 1;
- rev_info.disable_stdin = 1;
+ rev_info.stdin_handling = REV_INFO_STDIN_IGNORE;
rev_info.no_commit_id = 1;
rev_info.diffopt.output_format = DIFF_FORMAT_PATCH;
rev_info.diffopt.use_color = 0;
@@ -1061,7 +1061,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
argv[argc - 1] = "--";
}
- revs.disable_stdin = 1;
+ revs.stdin_handling = REV_INFO_STDIN_IGNORE;
setup_revisions(argc, argv, &revs, NULL);
if (!revs.pending.nr && is_bare_repository()) {
struct commit *head_commit;
@@ -122,7 +122,7 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix)
die(_("index file corrupt"));
opt->abbrev = 0;
opt->diff = 1;
- opt->disable_stdin = 1;
+ opt->stdin_handling = REV_INFO_STDIN_IGNORE;
memset(&s_r_opt, 0, sizeof(s_r_opt));
s_r_opt.tweak = diff_tree_tweak_rev;
@@ -651,7 +651,7 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
if ((!revs.commits && reflog_walk_empty(revs.reflog_info) &&
(!(revs.tag_objects || revs.tree_objects || revs.blob_objects) &&
!revs.pending.nr) &&
- !revs.rev_input_given && !revs.read_from_stdin) ||
+ !revs.rev_input_given && !revs.consumed_stdin) ||
revs.diff)
usage(rev_list_usage);
@@ -2742,14 +2742,17 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
}
if (!strcmp(arg, "--stdin")) {
- if (revs->disable_stdin) {
+ switch (revs->stdin_handling) {
+ case REV_INFO_STDIN_IGNORE:
argv[left++] = arg;
continue;
+ case REV_INFO_STDIN_CONSUME_ON_OPTION:
+ if (revs->consumed_stdin)
+ die("--stdin given twice?");
+ read_revisions_from_stdin(revs, &prune_data);
+ revs->consumed_stdin = 1;
+ continue;
}
- if (revs->read_from_stdin++)
- die("--stdin given twice?");
- read_revisions_from_stdin(revs, &prune_data);
- continue;
}
if (!strcmp(arg, "--end-of-options")) {
@@ -86,6 +86,11 @@ struct rev_cmdline_info {
struct oidset;
struct topo_walk_info;
+enum rev_info_stdin {
+ REV_INFO_STDIN_CONSUME_ON_OPTION,
+ REV_INFO_STDIN_IGNORE,
+};
+
struct rev_info {
/* Starting list */
struct commit_list *commits;
@@ -114,9 +119,22 @@ struct rev_info {
int rev_input_given;
/*
- * Whether we read from stdin due to the --stdin option.
+ * How should we handle seeing --stdin?
+ *
+ * Defaults to REV_INFO_STDIN_CONSUME_ON_OPTION where we'll
+ * attempt to read it if we see the --stdin option.
+ *
+ * Can be set to REV_INFO_STDIN_IGNORE to ignore the --stdin
+ * option.
+ */
+ enum rev_info_stdin stdin_handling;
+
+ /*
+ * Did we read from stdin due to stdin_handling ==
+ * REV_INFO_STDIN_CONSUME_ON_OPTION and seeing the --stdin
+ * option?
*/
- int read_from_stdin;
+ int consumed_stdin:1;
/* topo-sort */
enum rev_sort_order sort_order;
@@ -216,7 +234,6 @@ struct rev_info {
date_mode_explicit:1,
preserve_subject:1,
encode_email_headers:1;
- unsigned int disable_stdin:1;
/* --show-linear-break */
unsigned int track_linear:1,
track_first_time:1,
@@ -3377,7 +3377,7 @@ static int make_patch(struct repository *r,
log_tree_opt.abbrev = 0;
log_tree_opt.diff = 1;
log_tree_opt.diffopt.output_format = DIFF_FORMAT_PATCH;
- log_tree_opt.disable_stdin = 1;
+ log_tree_opt.stdin_handling = REV_INFO_STDIN_IGNORE;
log_tree_opt.no_commit_id = 1;
log_tree_opt.diffopt.file = fopen(buf.buf, "w");
log_tree_opt.diffopt.use_color = GIT_COLOR_NEVER;
@@ -4513,7 +4513,7 @@ static int pick_commits(struct repository *r,
log_tree_opt.diff = 1;
log_tree_opt.diffopt.output_format =
DIFF_FORMAT_DIFFSTAT;
- log_tree_opt.disable_stdin = 1;
+ log_tree_opt.stdin_handling = REV_INFO_STDIN_IGNORE;
if (read_oneliner(&buf, rebase_path_orig_head(), 0) &&
!get_oid(buf.buf, &orig) &&
Change the two "disable_stdin" and "read_from_stdin" flags to an enum, in preparation for a subsequent commit adding more flags. The interaction between these is more subtle than they might appear at first sight, as noted in a12cbe23ef7. "read_stdin" is not the inverse of "disable_stdin", rather we read stdin if we see the "--stdin" option. The "read" is intended to understood as "I've read it already", not "you should read it". Let's avoid this confusion by using "consume" and "consumed" instead, i.e. a word whose present and past tense isn't the same. See 8b3dce56508 (Teach --stdin option to "log" family, 2009-11-03) where we added the "disable_stdin" flag, and a12cbe23ef7 (rev-list: make empty --stdin not an error, 2018-08-22) for the addition of the "read_from_stdin" flag. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> --- builtin/am.c | 4 ++-- builtin/blame.c | 2 +- builtin/diff-tree.c | 2 +- builtin/rev-list.c | 2 +- revision.c | 13 ++++++++----- revision.h | 23 ++++++++++++++++++++--- sequencer.c | 4 ++-- 7 files changed, 35 insertions(+), 15 deletions(-)