Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 794151e

Browse files
peffgitster
authored andcommitted
reflog-walk: always make HEAD@{0} show indexed selectors
When we are showing reflog selectors during a walk, we infer from context whether the user wanted to see the index in each selector, or the reflog date. The current rules are: 1. if the user asked for an explicit date format in the output, show the date 2. if the user asked for ref@{now}, show the date 3. if neither is true, show the index However, if we see "ref@{0}", that should be a strong clue that the user wants to see the counted version. In fact, it should be much stronger than the date format in (1). The user may have been setting the date format to use in another part of the output (e.g., in --format="%gd (%ad)", they may have wanted to influence the author date). This patch flips the rules to: 1. if the user asked for ref@{0}, always show the index 2. if the user asked for ref@{now}, always show the date 3. otherwise, we have just "ref"; show them counted by default, but respect the presence of "--date" as a clue that the user wanted them date-based Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a763126 commit 794151e

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

reflog-walk.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,8 @@ void get_reflog_selector(struct strbuf *sb,
272272
}
273273

274274
strbuf_addf(sb, "%s@{", printed_ref);
275-
if (commit_reflog->selector == SELECTOR_DATE || dmode) {
275+
if (commit_reflog->selector == SELECTOR_DATE ||
276+
(commit_reflog->selector == SELECTOR_NONE && dmode)) {
276277
info = &commit_reflog->reflogs->items[commit_reflog->recno+1];
277278
strbuf_addstr(sb, show_date(info->timestamp, info->tz, dmode));
278279
} else {

t/t1411-reflog-show.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,14 @@ test_expect_success 'log.date does not invoke "--date" magic (format=%gd)' '
127127
test_cmp expect actual
128128
'
129129

130+
cat >expect <<'EOF'
131+
HEAD@{0}
132+
EOF
133+
test_expect_success '--date magic does not override explicit @{0} syntax' '
134+
git log -g -1 --format=%gd --date=raw HEAD@{0} >actual &&
135+
test_cmp expect actual
136+
'
137+
130138
: >expect
131139
test_expect_success 'empty reflog file' '
132140
git branch empty &&

0 commit comments

Comments
 (0)