rev-list: check reflog_info before showing usage
authorJeff King <peff@peff.net>
Fri, 7 Jul 2017 09:08:30 +0000 (05:08 -0400)
committerJunio C Hamano <gitster@pobox.com>
Sun, 9 Jul 2017 17:00:48 +0000 (10:00 -0700)
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>
builtin/rev-list.c
reflog-walk.c
reflog-walk.h
t/t1414-reflog-walk.sh
index 95d84d5cda1bdb6a699bc74ad57f7f1910946440..53a746dd891419f01d7c26b4b783a3b0142c26d2 100644 (file)
@@ -11,6 +11,7 @@
 #include "graph.h"
 #include "bisect.h"
 #include "progress.h"
+#include "reflog-walk.h"
 
 static const char rev_list_usage[] =
 "git rev-list [OPTION] <commit-id>... [ -- paths... ]\n"
@@ -348,7 +349,7 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
                /* Only --header was specified */
                revs.commit_format = CMIT_FMT_RAW;
 
-       if ((!revs.commits &&
+       if ((!revs.commits && reflog_walk_empty(revs.reflog_info) &&
             (!(revs.tag_objects || revs.tree_objects || revs.blob_objects) &&
              !revs.pending.nr)) ||
            revs.diff)
index 081f89b70d643514f148aaff9121263361fdb956..98c2f42de95cf3d863ff0f1ab2524bb5007f8295 100644 (file)
@@ -365,3 +365,8 @@ void show_reflog_message(struct reflog_walk_info *reflog_info, int oneline,
                strbuf_release(&selector);
        }
 }
+
+int reflog_walk_empty(struct reflog_walk_info *info)
+{
+       return !info || !info->reflogs.nr;
+}
index 27886f793e75de484b2a3c168e6024cf4139aae3..af323610725da76c8ce60fbd11093a9f276acd08 100644 (file)
@@ -20,4 +20,6 @@ extern void get_reflog_selector(struct strbuf *sb,
                const struct date_mode *dmode, int force_date,
                int shorten);
 
+extern int reflog_walk_empty(struct reflog_walk_info *walk);
+
 #endif
index 945aa089eca67f6d3412a27fc9b725d88fba9e6c..8bda862ca7337d38026e8a56ab4077a2cede0b95 100755 (executable)
@@ -102,4 +102,8 @@ test_expect_failure 'walk prefers reflog to ref tip' '
        test_cmp expect actual
 '
 
+test_expect_success 'rev-list -g complains when there are no reflogs' '
+       test_must_fail git rev-list -g
+'
+
 test_done