rev-list: check reflog_info before showing usage

When git-rev-list sees no pending commits, it shows a usage message. This works even when reflog-walking is requested, because the reflog-walk code currently puts the reflog tips into the pending queue. In preparation for refactoring the reflog-walk code, let's explicitly check whether we have any reflogs to walk. For now this is a noop, but the existing reflog tests will make sure that it kicks in after the refactoring. Likewise, we'll add a test that "rev-list -g" without specifying any reflogs continues to fail (so that we know our check does not kick in too aggressively). Note that the implementation needs to go into its own sub-function, as the walk code does not expose its innards outside of reflog-walk.c. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Jul 7, 2017 at 05:08 UTC 7f97de5ee1e1f9d28f45c8f7890e752f7b12bed1
4 files changed +13 -1
builtin/rev-list.c
+2 -1
@@ -11,6 +11,7 @@
11 #include "graph.h"
12 #include "bisect.h"
13 #include "progress.h"
14 +#include "reflog-walk.h"
15
16 static const char rev_list_usage[] =
17 "git rev-list [OPTION] <commit-id>... [ -- paths... ]\n"
@@ -348,7 +349,7 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
349 /* Only --header was specified */
350 revs.commit_format = CMIT_FMT_RAW;
351
351 - if ((!revs.commits &&
352 + if ((!revs.commits && reflog_walk_empty(revs.reflog_info) &&
353 (!(revs.tag_objects || revs.tree_objects || revs.blob_objects) &&
354 !revs.pending.nr)) ||
355 revs.diff)
reflog-walk.c
+5
@@ -365,3 +365,8 @@ void show_reflog_message(struct reflog_walk_info *reflog_info, int oneline,
365 strbuf_release(&selector);
366 }
367 }
368 +
369 +int reflog_walk_empty(struct reflog_walk_info *info)
370 +{
371 + return !info || !info->reflogs.nr;
372 +}
reflog-walk.h
+2
@@ -20,4 +20,6 @@ extern void get_reflog_selector(struct strbuf *sb,
20 const struct date_mode *dmode, int force_date,
21 int shorten);
22
23 +extern int reflog_walk_empty(struct reflog_walk_info *walk);
24 +
25 #endif
t/t1414-reflog-walk.sh
+4
@@ -102,4 +102,8 @@ test_expect_failure 'walk prefers reflog to ref tip' '
102 test_cmp expect actual
103 '
104
105 +test_expect_success 'rev-list -g complains when there are no reflogs' '
106 + test_must_fail git rev-list -g
107 +'
108 +
109 test_done