Merge branch 'jk/rev-list-stdin-noop-is-ok'
authorJunio C Hamano <gitster@pobox.com>
Mon, 17 Sep 2018 20:53:48 +0000 (13:53 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 17 Sep 2018 20:53:48 +0000 (13:53 -0700)
"git rev-list --stdin </dev/null" used to be an error; it now shows
no output without an error. "git rev-list --stdin --default HEAD"
still falls back to the given default when nothing is given on the
standard input.

* jk/rev-list-stdin-noop-is-ok:
rev-list: make empty --stdin not an error

builtin/rev-list.c
revision.c
revision.h
t/t6018-rev-list-glob.sh
index 5b07f3f4a2cf6cd5f73f20a930934ca2277c8391..ed0ea7dc5b5bed0c3cb926725b2f70cbf9b93d35 100644 (file)
@@ -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);
 
index de4dce600d00282655907e9014228791a352f813..46228f82ee50166fb135d457f808b52629f48394 100644 (file)
@@ -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;
index 007278cc119fded9f97832d87ffe5d6b95a5ce41..12259579271d9c51652f671b29598f09de967f0a 100644 (file)
@@ -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;
 
index 0bf10d0686982418682ff03e3a42ef3a16e2cfb4..db8a7834d88e6d01b3cc5106af749ede7b75866a 100755 (executable)
@@ -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
 '