Skip to content

Commit 7f97de5

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7c2f08a commit 7f97de5

File tree

4 files changed

+13
-1
lines changed

4 files changed

+13
-1
lines changed

builtin/rev-list.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "graph.h"
1212
#include "bisect.h"
1313
#include "progress.h"
14+
#include "reflog-walk.h"
1415

1516
static const char rev_list_usage[] =
1617
"git rev-list [OPTION] <commit-id>... [ -- paths... ]\n"
@@ -348,7 +349,7 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
348349
/* Only --header was specified */
349350
revs.commit_format = CMIT_FMT_RAW;
350351

351-
if ((!revs.commits &&
352+
if ((!revs.commits && reflog_walk_empty(revs.reflog_info) &&
352353
(!(revs.tag_objects || revs.tree_objects || revs.blob_objects) &&
353354
!revs.pending.nr)) ||
354355
revs.diff)

reflog-walk.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,3 +365,8 @@ void show_reflog_message(struct reflog_walk_info *reflog_info, int oneline,
365365
strbuf_release(&selector);
366366
}
367367
}
368+
369+
int reflog_walk_empty(struct reflog_walk_info *info)
370+
{
371+
return !info || !info->reflogs.nr;
372+
}

reflog-walk.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,6 @@ extern void get_reflog_selector(struct strbuf *sb,
2020
const struct date_mode *dmode, int force_date,
2121
int shorten);
2222

23+
extern int reflog_walk_empty(struct reflog_walk_info *walk);
24+
2325
#endif

t/t1414-reflog-walk.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,8 @@ test_expect_failure 'walk prefers reflog to ref tip' '
102102
test_cmp expect actual
103103
'
104104

105+
test_expect_success 'rev-list -g complains when there are no reflogs' '
106+
test_must_fail git rev-list -g
107+
'
108+
105109
test_done

0 commit comments

Comments
 (0)