Skip to content

Commit 250ca49

Browse files
committed
Merge branch 'hn/reflog-tests'
Prepare tests on ref API to help testing reftable backends. * hn/reflog-tests: refs/debug: trim trailing LF from reflog message test-ref-store: tweaks to for-each-reflog-ent format t1405: check for_each_reflog_ent_reverse() more thoroughly test-ref-store: don't add newline to reflog message show-branch: show reflog message
2 parents 4f7e2f0 + 6527925 commit 250ca49

File tree

7 files changed

+42
-19
lines changed

7 files changed

+42
-19
lines changed

builtin/show-branch.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
761761
char *logmsg;
762762
char *nth_desc;
763763
const char *msg;
764+
char *end;
764765
timestamp_t timestamp;
765766
int tz;
766767

@@ -770,11 +771,12 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
770771
reflog = i;
771772
break;
772773
}
773-
msg = strchr(logmsg, '\t');
774-
if (!msg)
775-
msg = "(none)";
776-
else
777-
msg++;
774+
775+
end = strchr(logmsg, '\n');
776+
if (end)
777+
*end = '\0';
778+
779+
msg = (*logmsg == '\0') ? "(none)" : logmsg;
778780
reflog_msg[i] = xstrfmt("(%s) %s",
779781
show_date(timestamp, tz,
780782
DATE_MODE(RELATIVE)),

refs/debug.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,15 +284,18 @@ static int debug_print_reflog_ent(struct object_id *old_oid,
284284
int ret;
285285
char o[GIT_MAX_HEXSZ + 1] = "null";
286286
char n[GIT_MAX_HEXSZ + 1] = "null";
287+
char *msgend = strchrnul(msg, '\n');
287288
if (old_oid)
288289
oid_to_hex_r(o, old_oid);
289290
if (new_oid)
290291
oid_to_hex_r(n, new_oid);
291292

292293
ret = dbg->fn(old_oid, new_oid, committer, timestamp, tz, msg,
293294
dbg->cb_data);
294-
trace_printf_key(&trace_refs, "reflog_ent %s (ret %d): %s -> %s, %s %ld \"%s\"\n",
295-
dbg->refname, ret, o, n, committer, (long int)timestamp, msg);
295+
trace_printf_key(&trace_refs,
296+
"reflog_ent %s (ret %d): %s -> %s, %s %ld \"%.*s\"\n",
297+
dbg->refname, ret, o, n, committer,
298+
(long int)timestamp, (int)(msgend - msg), msg);
296299
return ret;
297300
}
298301

t/helper/test-ref-store.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,9 @@ static int each_reflog(struct object_id *old_oid, struct object_id *new_oid,
152152
const char *committer, timestamp_t timestamp,
153153
int tz, const char *msg, void *cb_data)
154154
{
155-
printf("%s %s %s %"PRItime" %d %s\n",
156-
oid_to_hex(old_oid), oid_to_hex(new_oid),
157-
committer, timestamp, tz, msg);
155+
printf("%s %s %s %" PRItime " %+05d%s%s", oid_to_hex(old_oid),
156+
oid_to_hex(new_oid), committer, timestamp, tz,
157+
*msg == '\n' ? "" : "\t", msg);
158158
return 0;
159159
}
160160

t/t1400-update-ref.sh

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -321,8 +321,9 @@ $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150260 +0000 Switch
321321
$B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150860 +0000
322322
EOF
323323
test_expect_success "verifying $m's log (logged by touch)" '
324-
test_when_finished "rm -rf .git/$m .git/logs expect" &&
325-
test_cmp expect .git/logs/$m
324+
test_when_finished "git update-ref -d $m && rm -rf .git/logs actual expect" &&
325+
test-tool ref-store main for-each-reflog-ent $m >actual &&
326+
test_cmp actual expect
326327
'
327328

328329
test_expect_success "create $m (logged by config)" '
@@ -350,8 +351,9 @@ $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150380 +0000 Switch
350351
$B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150980 +0000
351352
EOF
352353
test_expect_success "verifying $m's log (logged by config)" '
353-
test_when_finished "rm -f .git/$m .git/logs/$m expect" &&
354-
test_cmp expect .git/logs/$m
354+
test_when_finished "git update-ref -d $m && rm -rf .git/logs actual expect" &&
355+
test-tool ref-store main for-each-reflog-ent $m >actual &&
356+
test_cmp actual expect
355357
'
356358

357359
test_expect_success 'set up for querying the reflog' '
@@ -467,7 +469,8 @@ $h_OTHER $h_FIXED $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117151040 +0000 co
467469
$h_FIXED $h_MERGED $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117151100 +0000 commit (merge): Merged initial commit and a later commit.
468470
EOF
469471
test_expect_success 'git commit logged updates' '
470-
test_cmp expect .git/logs/$m
472+
test-tool ref-store main for-each-reflog-ent $m >actual &&
473+
test_cmp expect actual
471474
'
472475
unset h_TEST h_OTHER h_FIXED h_MERGED
473476

t/t1405-main-ref-store.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,13 @@ test_expect_success 'for_each_reflog()' '
8989
test_expect_success 'for_each_reflog_ent()' '
9090
$RUN for-each-reflog-ent HEAD >actual &&
9191
head -n1 actual | grep one &&
92-
tail -n2 actual | head -n1 | grep recreate-main
92+
tail -n1 actual | grep recreate-main
9393
'
9494

9595
test_expect_success 'for_each_reflog_ent_reverse()' '
9696
$RUN for-each-reflog-ent-reverse HEAD >actual &&
9797
head -n1 actual | grep recreate-main &&
98-
tail -n2 actual | head -n1 | grep one
98+
tail -n1 actual | grep one
9999
'
100100

101101
test_expect_success 'reflog_exists(HEAD)' '

t/t1406-submodule-ref-store.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,13 @@ test_expect_success 'for_each_reflog()' '
7575
test_expect_success 'for_each_reflog_ent()' '
7676
$RUN for-each-reflog-ent HEAD >actual &&
7777
head -n1 actual | grep first &&
78-
tail -n2 actual | head -n1 | grep main.to.new
78+
tail -n1 actual | grep main.to.new
7979
'
8080

8181
test_expect_success 'for_each_reflog_ent_reverse()' '
8282
$RUN for-each-reflog-ent-reverse HEAD >actual &&
8383
head -n1 actual | grep main.to.new &&
84-
tail -n2 actual | head -n1 | grep first
84+
tail -n1 actual | grep first
8585
'
8686

8787
test_expect_success 'reflog_exists(HEAD)' '

t/t3202-show-branch.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ test_description='test show-branch'
44

55
. ./test-lib.sh
66

7+
# arbitrary reference time: 2009-08-30 19:20:00
8+
GIT_TEST_DATE_NOW=1251660000; export GIT_TEST_DATE_NOW
9+
710
test_expect_success 'setup' '
811
test_commit initial &&
912
for i in $(test_seq 1 10)
@@ -146,4 +149,16 @@ test_expect_success 'show branch --merge-base with N arguments' '
146149
test_cmp expect actual
147150
'
148151

152+
test_expect_success 'show branch --reflog=2' '
153+
sed "s/^> //" >expect <<-\EOF &&
154+
> ! [refs/heads/branch10@{0}] (4 years, 5 months ago) commit: branch10
155+
> ! [refs/heads/branch10@{1}] (4 years, 5 months ago) commit: branch10
156+
> --
157+
> + [refs/heads/branch10@{0}] branch10
158+
> ++ [refs/heads/branch10@{1}] initial
159+
EOF
160+
git show-branch --reflog=2 >actual &&
161+
test_cmp actual expect
162+
'
163+
149164
test_done

0 commit comments

Comments
 (0)