git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Jeff King <peff@peff.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: "SZEDER Gábor" <szeder.dev@gmail.com>,
	git@vger.kernel.org, "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Subject: Re: [PATCH] rev-list: make empty --stdin not an error
Date: Wed, 22 Aug 2018 17:37:23 -0400	[thread overview]
Message-ID: <20180822213722.GA25180@sigill.intra.peff.net> (raw)
In-Reply-To: <xmqqa7pem8ul.fsf@gitster-ct.c.googlers.com>

On Wed, Aug 22, 2018 at 01:42:26PM -0700, Junio C Hamano wrote:

> Jeff King <peff@peff.net> writes:
> 
> > Instead, let's keep two flags: one to denote when we got
> > actual input (which triggers both roles) and one for when we
> > read stdin (which triggers only the first).
> >
> > This does mean a caller interested in the first role has to
> > check both flags, but there's only one such caller. And any
> > future callers might want to make the distinction anyway
> > (e.g., if they care less about erroring out, and more about
> > whether revision.c soaked up our stdin).
> >
> > [1] https://public-inbox.org/git/20170802223416.gwiezhbuxbdmbjzx@sigill.intra.peff.net/
> >
> > Helped-by: Junio C Hamano <gitster@pobox.com>
> > Signed-off-by: Jeff King <peff@peff.net>
> > ---
> >  builtin/rev-list.c       | 2 +-
> >  revision.c               | 1 +
> >  revision.h               | 5 +++++
> >  t/t6018-rev-list-glob.sh | 2 +-
> >  4 files changed, 8 insertions(+), 2 deletions(-)
> 
> I think this makes sense, but if we were to give a dedicated field
> in the revs structure, can we lose the local variable at the same
> time, I wonder?

Yes. I was thinking it had more purpose than this, but it really is just
a flag to check "did we do this already?". Which is one of the main
purposes I claimed for the new flag in my commit message. :)

Here it is with that squashed in (this is the whole patch, since I
updated the commit message to mention it).

-- >8 --
Subject: [PATCH] rev-list: make empty --stdin not an error

When we originally did the series that contains 7ba826290a
(revision: add rev_input_given flag, 2017-08-02) the intent
was that "git rev-list --stdin </dev/null" would similarly
become a successful noop. However, an attempt at the time to
do that did not work[1]. The problem is that rev_input_given
serves two roles:

 - it tells rev-list.c that it should not error out

 - it tells revision.c that it should not have the "default"
   ref kick (e.g., "HEAD" in "git log")

We want to trigger the former, but not the latter. This is
technically possible with a single flag, if we set the flag
only after revision.c's revs->def check. But this introduces
a rather subtle ordering dependency.

Instead, let's keep two flags: one to denote when we got
actual input (which triggers both roles) and one for when we
read stdin (which triggers only the first).

This does mean a caller interested in the first role has to
check both flags, but there's only one such caller. And any
future callers might want to make the distinction anyway
(e.g., if they care less about erroring out, and more about
whether revision.c soaked up our stdin).

In fact, we already keep such a flag internally in
revision.c for this purpose, so this is really just exposing
that to the caller (and the old function-local flag can go
away in favor of our new one).

[1] https://public-inbox.org/git/20170802223416.gwiezhbuxbdmbjzx@sigill.intra.peff.net/

Helped-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Jeff King <peff@peff.net>
---
 builtin/rev-list.c       | 2 +-
 revision.c               | 5 ++---
 revision.h               | 5 +++++
 t/t6018-rev-list-glob.sh | 2 +-
 4 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/builtin/rev-list.c b/builtin/rev-list.c
index 5b07f3f4a2..ed0ea7dc5b 100644
--- a/builtin/rev-list.c
+++ b/builtin/rev-list.c
@@ -493,7 +493,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.rev_input_given && !revs.read_from_stdin) ||
 	    revs.diff)
 		usage(rev_list_usage);
 
diff --git a/revision.c b/revision.c
index de4dce600d..46228f82ee 100644
--- a/revision.c
+++ b/revision.c
@@ -2318,7 +2318,7 @@ static void NORETURN diagnose_missing_default(const char *def)
  */
 int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct setup_revision_opt *opt)
 {
-	int i, flags, left, seen_dashdash, read_from_stdin, got_rev_arg = 0, revarg_opt;
+	int i, flags, left, seen_dashdash, got_rev_arg = 0, revarg_opt;
 	struct argv_array prune_data = ARGV_ARRAY_INIT;
 	const char *submodule = NULL;
 
@@ -2348,7 +2348,6 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
 	revarg_opt = opt ? opt->revarg_opt : 0;
 	if (seen_dashdash)
 		revarg_opt |= REVARG_CANNOT_BE_FILENAME;
-	read_from_stdin = 0;
 	for (left = i = 1; i < argc; i++) {
 		const char *arg = argv[i];
 		if (*arg == '-') {
@@ -2367,7 +2366,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
 					argv[left++] = arg;
 					continue;
 				}
-				if (read_from_stdin++)
+				if (revs->read_from_stdin++)
 					die("--stdin given twice?");
 				read_revisions_from_stdin(revs, &prune_data);
 				continue;
diff --git a/revision.h b/revision.h
index 007278cc11..1225957927 100644
--- a/revision.h
+++ b/revision.h
@@ -82,6 +82,11 @@ struct rev_info {
 	 */
 	int rev_input_given;
 
+	/*
+	 * Whether we read from stdin due to the --stdin option.
+	 */
+	int read_from_stdin;
+
 	/* topo-sort */
 	enum rev_sort_order sort_order;
 
diff --git a/t/t6018-rev-list-glob.sh b/t/t6018-rev-list-glob.sh
index 0bf10d0686..db8a7834d8 100755
--- a/t/t6018-rev-list-glob.sh
+++ b/t/t6018-rev-list-glob.sh
@@ -255,7 +255,7 @@ test_expect_success 'rev-list accumulates multiple --exclude' '
 	compare rev-list "--exclude=refs/remotes/* --exclude=refs/tags/* --all" --branches
 '
 
-test_expect_failure 'rev-list should succeed with empty output on empty stdin' '
+test_expect_success 'rev-list should succeed with empty output on empty stdin' '
 	git rev-list --stdin </dev/null >actual &&
 	test_must_be_empty actual
 '
-- 
2.19.0.rc0.412.g7005db4e88


  reply	other threads:[~2018-08-22 21:37 UTC|newest]

Thread overview: 95+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-02 10:54 [PATCH] checkout & worktree: introduce a core.DWIMRemote setting Ævar Arnfjörð Bjarmason
2018-05-02 15:21 ` Duy Nguyen
2018-05-02 18:00   ` Eric Sunshine
2018-05-02 18:09     ` Duy Nguyen
2018-05-02 18:25     ` Ævar Arnfjörð Bjarmason
2018-05-03 13:18       ` [PATCH v2] checkout & worktree: introduce checkout.implicitRemote Ævar Arnfjörð Bjarmason
2018-05-03 15:14         ` Duy Nguyen
2018-05-04  7:54           ` Ævar Arnfjörð Bjarmason
2018-05-04 14:58             ` Duy Nguyen
2018-05-04 18:02               ` Ævar Arnfjörð Bjarmason
2018-05-04  9:58         ` Eric Sunshine
2018-05-24 19:47           ` [PATCH v3] " Ævar Arnfjörð Bjarmason
2018-05-25  8:12             ` Junio C Hamano
2018-05-25 14:42               ` Duy Nguyen
2018-05-25 18:38                 ` Ævar Arnfjörð Bjarmason
2018-05-26 12:49                   ` Duy Nguyen
2018-05-31  7:45             ` Ævar Arnfjörð Bjarmason
2018-05-31 19:52               ` [PATCH v4 0/9] ambiguous checkout UI & checkout.defaultRemote Ævar Arnfjörð Bjarmason
2018-06-01 21:10                 ` [PATCH v5 0/8] " Ævar Arnfjörð Bjarmason
2018-06-02 11:50                   ` [PATCH v6 " Ævar Arnfjörð Bjarmason
2018-06-05 14:40                     ` [PATCH v7 " Ævar Arnfjörð Bjarmason
2018-06-05 14:40                     ` [PATCH v7 1/8] checkout tests: index should be clean after dwim checkout Ævar Arnfjörð Bjarmason
2018-06-05 15:45                       ` SZEDER Gábor
2018-07-27 17:48                         ` [PATCH] tests: make use of the test_must_be_empty function Ævar Arnfjörð Bjarmason
2018-07-27 21:50                           ` Junio C Hamano
2018-07-31  0:17                           ` SZEDER Gábor
2018-08-22 17:48                           ` [PATCH] t6018-rev-list-glob: fix 'empty stdin' test SZEDER Gábor
2018-08-22 17:53                             ` Eric Sunshine
2018-08-22 18:59                               ` SZEDER Gábor
2018-08-22 20:30                                 ` Eric Sunshine
2018-08-22 18:01                             ` Junio C Hamano
2018-08-22 18:50                             ` Junio C Hamano
2018-08-22 19:23                               ` Jeff King
2018-08-22 19:50                                 ` [PATCH] rev-list: make empty --stdin not an error Jeff King
2018-08-22 20:42                                   ` Junio C Hamano
2018-08-22 21:37                                     ` Jeff King [this message]
2018-08-22 21:50                                       ` Junio C Hamano
2018-08-22 21:55                                         ` Jeff King
2018-08-22 21:41                                     ` Junio C Hamano
2018-06-05 14:40                     ` [PATCH v7 2/8] checkout.h: wrap the arguments to unique_tracking_name() Ævar Arnfjörð Bjarmason
2018-06-05 14:40                     ` [PATCH v7 3/8] checkout.c: introduce an *_INIT macro Ævar Arnfjörð Bjarmason
2018-06-05 14:40                     ` [PATCH v7 4/8] checkout.c: change "unique" member to "num_matches" Ævar Arnfjörð Bjarmason
2018-06-05 14:40                     ` [PATCH v7 5/8] checkout: pass the "num_matches" up to callers Ævar Arnfjörð Bjarmason
2018-06-05 14:40                     ` [PATCH v7 6/8] builtin/checkout.c: use "ret" variable for return Ævar Arnfjörð Bjarmason
2018-06-05 14:40                     ` [PATCH v7 7/8] checkout: add advice for ambiguous "checkout <branch>" Ævar Arnfjörð Bjarmason
2018-06-05 14:40                     ` [PATCH v7 8/8] checkout & worktree: introduce checkout.defaultRemote Ævar Arnfjörð Bjarmason
2018-06-02 11:50                   ` [PATCH v6 1/8] checkout tests: index should be clean after dwim checkout Ævar Arnfjörð Bjarmason
2018-06-02 11:50                   ` [PATCH v6 2/8] checkout.h: wrap the arguments to unique_tracking_name() Ævar Arnfjörð Bjarmason
2018-06-02 11:50                   ` [PATCH v6 3/8] checkout.c: introduce an *_INIT macro Ævar Arnfjörð Bjarmason
2018-06-02 11:50                   ` [PATCH v6 4/8] checkout.c]: change "unique" member to "num_matches" Ævar Arnfjörð Bjarmason
2018-06-02 11:50                   ` [PATCH v6 5/8] checkout: pass the "num_matches" up to callers Ævar Arnfjörð Bjarmason
2018-06-02 11:50                   ` [PATCH v6 6/8] builtin/checkout.c: use "ret" variable for return Ævar Arnfjörð Bjarmason
2018-06-02 11:50                   ` [PATCH v6 7/8] checkout: add advice for ambiguous "checkout <branch>" Ævar Arnfjörð Bjarmason
2018-06-02 11:50                   ` [PATCH v6 8/8] checkout & worktree: introduce checkout.defaultRemote Ævar Arnfjörð Bjarmason
2018-06-03  7:58                     ` Eric Sunshine
2018-06-01 21:10                 ` [PATCH v5 1/8] checkout tests: index should be clean after dwim checkout Ævar Arnfjörð Bjarmason
2018-06-01 21:10                 ` [PATCH v5 2/8] checkout.h: wrap the arguments to unique_tracking_name() Ævar Arnfjörð Bjarmason
2018-06-01 21:10                 ` [PATCH v5 3/8] checkout.[ch]: introduce an *_INIT macro Ævar Arnfjörð Bjarmason
2018-06-01 22:40                   ` Eric Sunshine
2018-06-01 21:10                 ` [PATCH v5 4/8] checkout.[ch]: change "unique" member to "num_matches" Ævar Arnfjörð Bjarmason
2018-06-01 22:41                   ` Eric Sunshine
2018-06-01 21:10                 ` [PATCH v5 5/8] checkout: pass the "num_matches" up to callers Ævar Arnfjörð Bjarmason
2018-06-01 21:10                 ` [PATCH v5 6/8] builtin/checkout.c: use "ret" variable for return Ævar Arnfjörð Bjarmason
2018-06-01 21:10                 ` [PATCH v5 7/8] checkout: add advice for ambiguous "checkout <branch>" Ævar Arnfjörð Bjarmason
2018-06-01 22:52                   ` Eric Sunshine
2018-06-01 21:10                 ` [PATCH v5 8/8] checkout & worktree: introduce checkout.defaultRemote Ævar Arnfjörð Bjarmason
2018-05-31 19:52               ` [PATCH v4 1/9] checkout tests: index should be clean after dwim checkout Ævar Arnfjörð Bjarmason
2018-06-01  4:06                 ` Junio C Hamano
2018-06-01 19:43                   ` Ævar Arnfjörð Bjarmason
2018-05-31 19:52               ` [PATCH v4 2/9] checkout.h: wrap the arguments to unique_tracking_name() Ævar Arnfjörð Bjarmason
2018-05-31 19:52               ` [PATCH v4 3/9] checkout.[ch]: move struct declaration into *.h Ævar Arnfjörð Bjarmason
2018-05-31 21:45                 ` Thomas Gummerer
2018-06-01  2:14                   ` Junio C Hamano
2018-06-01  9:56                     ` Ævar Arnfjörð Bjarmason
2018-05-31 19:52               ` [PATCH v4 4/9] checkout.[ch]: introduce an *_INIT macro Ævar Arnfjörð Bjarmason
2018-06-01  4:16                 ` Junio C Hamano
2018-05-31 19:52               ` [PATCH v4 5/9] checkout.[ch]: change "unique" member to "num_matches" Ævar Arnfjörð Bjarmason
2018-05-31 19:52               ` [PATCH v4 6/9] checkout: pass the "num_matches" up to callers Ævar Arnfjörð Bjarmason
2018-05-31 19:52               ` [PATCH v4 7/9] builtin/checkout.c: use "ret" variable for return Ævar Arnfjörð Bjarmason
2018-05-31 19:52               ` [PATCH v4 8/9] checkout: add advice for ambiguous "checkout <branch>" Ævar Arnfjörð Bjarmason
2018-06-01  4:32                 ` Junio C Hamano
2018-06-01  5:11                   ` Junio C Hamano
2018-06-01  9:54                     ` Ævar Arnfjörð Bjarmason
2018-06-04  1:58                       ` Junio C Hamano
2018-06-01  9:50                   ` Ævar Arnfjörð Bjarmason
2018-06-01  7:53                 ` Eric Sunshine
2018-06-01 19:59                   ` Ævar Arnfjörð Bjarmason
2018-05-31 19:52               ` [PATCH v4 9/9] checkout & worktree: introduce checkout.defaultRemote Ævar Arnfjörð Bjarmason
2018-05-31 21:49                 ` Stefan Beller
2018-06-01  8:04                   ` Eric Sunshine
2018-06-01  9:47                   ` Ævar Arnfjörð Bjarmason
2018-05-31 22:22                 ` Thomas Gummerer
2018-06-01  2:17                   ` Junio C Hamano
2018-05-04  7:14       ` [PATCH] checkout & worktree: introduce a core.DWIMRemote setting Eric Sunshine
2018-05-04  7:23         ` Eric Sunshine

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

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180822213722.GA25180@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=szeder.dev@gmail.com \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).