git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] revision: allow pseudo options after --end-of-options
@ 2021-07-08 15:03 Jiang Xin
  2021-07-08 17:01 ` brian m. carlson
  0 siblings, 1 reply; 11+ messages in thread
From: Jiang Xin @ 2021-07-08 15:03 UTC (permalink / raw)
  To: Junio C Hamano, Jeff King, Git List; +Cc: Jiang Xin

From: Jiang Xin <zhiyou.jx@alibaba-inc.com>

Options and revisions can be seperated by the option "--end-of-options"
by introducing commit 19e8789b23 (revision: allow --end-of-options to
end option parsing, 2019-08-06).  The following command will show
revisions which have changes on file "bar" on a branch named "--foo":

    git rev-list --oneline --end-of-options --foo -- bar

If we want to see revisions between two revisions (rev1 and rev2), we
can use the following command:

    git rev-list --oneline --end-of-options rev1..rev2 --

We know that "rev1..rev2" is a shorthand for "rev2 --not rev1", but
we can not use the longer expression with option "--not" after the
"--end-of-options" option.  This is because the parser will not consume
revision pseudo options after seeing "--end-of-option".

Allow parsing revision pseudo options after "--end-of-options", the
following command is valid:

    git rev-list --oneline --end-of-options rev2 --not rev2 --

Signed-off-by: Jiang Xin <zhiyou.jx@alibaba-inc.com>
---
 revision.c               |  7 ++++---
 t/t6000-rev-list-misc.sh | 45 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 49 insertions(+), 3 deletions(-)

diff --git a/revision.c b/revision.c
index 8140561b6c..0d37b5a759 100644
--- a/revision.c
+++ b/revision.c
@@ -2729,9 +2729,9 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
 		revarg_opt |= REVARG_CANNOT_BE_FILENAME;
 	for (left = i = 1; i < argc; i++) {
 		const char *arg = argv[i];
-		if (!seen_end_of_options && *arg == '-') {
-			int opts;
+		int opts;
 
+		if (*arg == '-') {
 			opts = handle_revision_pseudo_opt(submodule,
 						revs, argv + i,
 						&flags);
@@ -2739,7 +2739,9 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
 				i += opts - 1;
 				continue;
 			}
+		}
 
+		if (!seen_end_of_options && *arg == '-') {
 			if (!strcmp(arg, "--stdin")) {
 				if (revs->disable_stdin) {
 					argv[left++] = arg;
@@ -2767,7 +2769,6 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
 			continue;
 		}
 
-
 		if (handle_revision_arg(arg, revs, flags, revarg_opt)) {
 			int j;
 			if (seen_dashdash || *arg == '^')
diff --git a/t/t6000-rev-list-misc.sh b/t/t6000-rev-list-misc.sh
index 12def7bcbf..3b2ca10456 100755
--- a/t/t6000-rev-list-misc.sh
+++ b/t/t6000-rev-list-misc.sh
@@ -169,4 +169,49 @@ test_expect_success 'rev-list --count --objects' '
 	test_line_count = $count actual
 '
 
+test_expect_success 'merge branch "--output=yikes" to main' '
+	git checkout main &&
+	git merge -m "Merge branch" \
+		--allow-unrelated-histories -- \
+		--output=yikes &&
+	echo three >> two/three &&
+	git add two/three &&
+	test_tick &&
+	git commit -m "three" &&
+	cat >expect <<-EOF &&
+	> three
+	> Merge branch
+	> another
+	> that
+	> two
+	> one
+	EOF
+	git log --pretty="%m %s" --end-of-options HEAD >actual &&
+	test_cmp expect actual
+'
+
+test_expect_success 'parse pseudo option "--branches" after "--end-of-options"' '
+	cat >expect <<-EOF &&
+	> three
+	> another
+	> Merge branch
+	> that
+	> two
+	> one
+	EOF
+	git log --pretty="%m %s" --end-of-options \
+		--branches -- >actual &&
+	test_cmp expect actual
+'
+
+test_expect_success 'parse pseudo option "--not" after "--end-of-options"' '
+	cat >expect <<-EOF &&
+	> three
+	EOF
+	git log --pretty="%m %s" --end-of-options \
+		HEAD --not --output=yikes -- \
+		two/three >actual &&
+	test_cmp expect actual
+'
+
 test_done
-- 
2.32.0.rc0.27.g7b1e85181b


^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2021-07-27  6:11 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-08 15:03 [PATCH] revision: allow pseudo options after --end-of-options Jiang Xin
2021-07-08 17:01 ` brian m. carlson
2021-07-09  1:33   ` Jiang Xin
2021-07-10 21:54     ` brian m. carlson
2021-07-12 17:54       ` Jeff King
2021-07-12 18:47         ` Junio C Hamano
2021-07-12 19:47           ` Jeff King
2021-07-12 20:09             ` Junio C Hamano
2021-07-13  8:57         ` Jiang Xin
2021-07-13 21:13           ` Jeff King
2021-07-27  6:10             ` Patrick Steinhardt

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).