From 0c5dc7431a01d325e815ce722d80ad549a41e632 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Wed, 2 Aug 2017 18:24:51 -0400 Subject: [PATCH 1/4] t6018: flesh out empty input/output rev-list tests In 751a2ac6e (rev-list --exclude: tests, 2013-11-01), we added a few tests for handling "empty" inputs with rev-list (i.e., where the user gave us some pattern but it turned out not to queue any objects for traversal), all of which were marked as failing. In preparation for working on this area of the code, let's give each test a more descriptive name. Let's also include one more case which we should cover: feeding a --glob pattern that doesn't match anything. We can also drop the explanatory comment; we'll be converting these to expect_success in the next few patches, so the discussion isn't necessary. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- t/t6018-rev-list-glob.sh | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/t/t6018-rev-list-glob.sh b/t/t6018-rev-list-glob.sh index 381f35ed16d152..f8367b829cf91c 100755 --- a/t/t6018-rev-list-glob.sh +++ b/t/t6018-rev-list-glob.sh @@ -255,27 +255,19 @@ test_expect_success 'rev-list accumulates multiple --exclude' ' compare rev-list "--exclude=refs/remotes/* --exclude=refs/tags/* --all" --branches ' - -# "git rev-list" is likely to be a bug in the calling script and may -# deserve an error message, but do cases where set of refs programmatically -# given using globbing and/or --stdin need to fail with the same error, or -# are we better off reporting a success with no output? The following few -# tests document the current behaviour to remind us that we might want to -# think about this issue. - -test_expect_failure 'rev-list may want to succeed with empty output on no input (1)' ' +test_expect_failure 'rev-list should succeed with empty output on empty stdin' ' >expect && git rev-list --stdin actual && test_cmp expect actual ' -test_expect_failure 'rev-list may want to succeed with empty output on no input (2)' ' +test_expect_failure 'rev-list should succeed with empty output with all refs excluded' ' >expect && git rev-list --exclude=* --all >actual && test_cmp expect actual ' -test_expect_failure 'rev-list may want to succeed with empty output on no input (3)' ' +test_expect_failure 'rev-list should succeed with empty output with empty --all' ' ( test_create_repo empty && cd empty && @@ -285,6 +277,12 @@ test_expect_failure 'rev-list may want to succeed with empty output on no input ) ' +test_expect_failure 'rev-list should succeed with empty output with empty glob' ' + >expect && + git rev-list --glob=does-not-match-anything >actual && + test_cmp expect actual +' + test_expect_success 'shortlog accepts --glob/--tags/--remotes' ' compare shortlog "subspace/one subspace/two" --branches=subspace && From 7ba826290aa448bb9d0d45c3bb4b34905b741013 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Wed, 2 Aug 2017 18:25:27 -0400 Subject: [PATCH 2/4] revision: add rev_input_given flag Normally a caller that invokes setup_revisions() has to check rev.pending to see if anything was actually queued for the traversal. But they can't tell the difference between two cases: 1. The user gave us no tip from which to start a traversal. 2. The user tried to give us tips via --glob, --all, etc, but their patterns ended up being empty. Let's set a flag in the rev_info struct that callers can use to tell the difference. We can set this from the init_all_refs_cb() function. That's a little funny because it's not exactly about initializing the "cb" struct itself. But that function is the common setup place for doing pattern traversals that is used by --glob, --all, etc. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- revision.c | 1 + revision.h | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/revision.c b/revision.c index 6603af944486db..08d5806b8a0d01 100644 --- a/revision.c +++ b/revision.c @@ -1168,6 +1168,7 @@ static void init_all_refs_cb(struct all_refs_cb *cb, struct rev_info *revs, { cb->all_revs = revs; cb->all_flags = flags; + revs->rev_input_given = 1; } void clear_ref_exclusion(struct string_list **ref_excludes_p) diff --git a/revision.h b/revision.h index f96e7f7f49debc..bc18487d6fff5e 100644 --- a/revision.h +++ b/revision.h @@ -71,6 +71,13 @@ struct rev_info { const char *def; struct pathspec prune_data; + /* + * Whether the arguments parsed by setup_revisions() included any + * "input" revisions that might still have yielded an empty pending + * list (e.g., patterns like "--all" or "--glob"). + */ + int rev_input_given; + /* topo-sort */ enum rev_sort_order sort_order; From 0159ba3226f75fbd6d3dc0e92c325cb11f2f0699 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Wed, 2 Aug 2017 18:26:06 -0400 Subject: [PATCH 3/4] rev-list: don't show usage when we see empty ref patterns If the user gives us no starting point for a traversal, we want to complain with our normal usage message. But if they tried to do so with "--all" or "--glob", but that happened not to match any refs, the usage message isn't helpful. We should just give them the empty output they asked for instead. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- builtin/rev-list.c | 3 ++- t/t6018-rev-list-glob.sh | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/builtin/rev-list.c b/builtin/rev-list.c index 95d84d5cda1bdb..1e9cc594881f8f 100644 --- a/builtin/rev-list.c +++ b/builtin/rev-list.c @@ -350,7 +350,8 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix) if ((!revs.commits && (!(revs.tag_objects || revs.tree_objects || revs.blob_objects) && - !revs.pending.nr)) || + !revs.pending.nr) && + !revs.rev_input_given) || revs.diff) usage(rev_list_usage); diff --git a/t/t6018-rev-list-glob.sh b/t/t6018-rev-list-glob.sh index f8367b829cf91c..d3453c583c1921 100755 --- a/t/t6018-rev-list-glob.sh +++ b/t/t6018-rev-list-glob.sh @@ -261,13 +261,13 @@ test_expect_failure 'rev-list should succeed with empty output on empty stdin' ' test_cmp expect actual ' -test_expect_failure 'rev-list should succeed with empty output with all refs excluded' ' +test_expect_success 'rev-list should succeed with empty output with all refs excluded' ' >expect && git rev-list --exclude=* --all >actual && test_cmp expect actual ' -test_expect_failure 'rev-list should succeed with empty output with empty --all' ' +test_expect_success 'rev-list should succeed with empty output with empty --all' ' ( test_create_repo empty && cd empty && @@ -277,7 +277,7 @@ test_expect_failure 'rev-list should succeed with empty output with empty --all' ) ' -test_expect_failure 'rev-list should succeed with empty output with empty glob' ' +test_expect_success 'rev-list should succeed with empty output with empty glob' ' >expect && git rev-list --glob=does-not-match-anything >actual && test_cmp expect actual From 5d34d1ac06fe70fc0a7a8f35ddf9e7690114dda7 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Wed, 2 Aug 2017 18:30:19 -0400 Subject: [PATCH 4/4] revision: do not fallback to default when rev_input_given is set If revs->def is set (as it is in "git log") and there are no pending objects after parsing the user's input, then we show whatever is in "def". But if the user _did_ ask for some input that just happened to be empty (e.g., "--glob" that does not match anything), showing the default revision is confusing. We should just show nothing, as that is what the user's request yielded. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- revision.c | 2 +- t/t4202-log.sh | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/revision.c b/revision.c index 08d5806b8a0d01..ba2b166cd67fab 100644 --- a/revision.c +++ b/revision.c @@ -2316,7 +2316,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s opt->tweak(revs, opt); if (revs->show_merge) prepare_show_merge(revs); - if (revs->def && !revs->pending.nr && !got_rev_arg) { + if (revs->def && !revs->pending.nr && !revs->rev_input_given && !got_rev_arg) { struct object_id oid; struct object *object; struct object_context oc; diff --git a/t/t4202-log.sh b/t/t4202-log.sh index 3f3531f0a49be3..36d120c969f6c1 100755 --- a/t/t4202-log.sh +++ b/t/t4202-log.sh @@ -1523,6 +1523,12 @@ test_expect_success 'log diagnoses bogus HEAD' ' test_i18ngrep broken stderr ' +test_expect_success 'log does not default to HEAD when rev input is given' ' + >expect && + git log --branches=does-not-exist >actual && + test_cmp expect actual +' + test_expect_success 'set up --source tests' ' git checkout --orphan source-a && test_commit one &&