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
This commit is contained in:
Junio C Hamano 2021-12-15 09:39:48 -08:00
commit 250ca49b4f
7 changed files with 42 additions and 19 deletions

View File

@ -761,6 +761,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
char *logmsg; char *logmsg;
char *nth_desc; char *nth_desc;
const char *msg; const char *msg;
char *end;
timestamp_t timestamp; timestamp_t timestamp;
int tz; int tz;
@ -770,11 +771,12 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
reflog = i; reflog = i;
break; break;
} }
msg = strchr(logmsg, '\t');
if (!msg) end = strchr(logmsg, '\n');
msg = "(none)"; if (end)
else *end = '\0';
msg++;
msg = (*logmsg == '\0') ? "(none)" : logmsg;
reflog_msg[i] = xstrfmt("(%s) %s", reflog_msg[i] = xstrfmt("(%s) %s",
show_date(timestamp, tz, show_date(timestamp, tz,
DATE_MODE(RELATIVE)), DATE_MODE(RELATIVE)),

View File

@ -284,6 +284,7 @@ static int debug_print_reflog_ent(struct object_id *old_oid,
int ret; int ret;
char o[GIT_MAX_HEXSZ + 1] = "null"; char o[GIT_MAX_HEXSZ + 1] = "null";
char n[GIT_MAX_HEXSZ + 1] = "null"; char n[GIT_MAX_HEXSZ + 1] = "null";
char *msgend = strchrnul(msg, '\n');
if (old_oid) if (old_oid)
oid_to_hex_r(o, old_oid); oid_to_hex_r(o, old_oid);
if (new_oid) if (new_oid)
@ -291,8 +292,10 @@ static int debug_print_reflog_ent(struct object_id *old_oid,
ret = dbg->fn(old_oid, new_oid, committer, timestamp, tz, msg, ret = dbg->fn(old_oid, new_oid, committer, timestamp, tz, msg,
dbg->cb_data); dbg->cb_data);
trace_printf_key(&trace_refs, "reflog_ent %s (ret %d): %s -> %s, %s %ld \"%s\"\n", trace_printf_key(&trace_refs,
dbg->refname, ret, o, n, committer, (long int)timestamp, msg); "reflog_ent %s (ret %d): %s -> %s, %s %ld \"%.*s\"\n",
dbg->refname, ret, o, n, committer,
(long int)timestamp, (int)(msgend - msg), msg);
return ret; return ret;
} }

View File

@ -152,9 +152,9 @@ static int each_reflog(struct object_id *old_oid, struct object_id *new_oid,
const char *committer, timestamp_t timestamp, const char *committer, timestamp_t timestamp,
int tz, const char *msg, void *cb_data) int tz, const char *msg, void *cb_data)
{ {
printf("%s %s %s %"PRItime" %d %s\n", printf("%s %s %s %" PRItime " %+05d%s%s", oid_to_hex(old_oid),
oid_to_hex(old_oid), oid_to_hex(new_oid), oid_to_hex(new_oid), committer, timestamp, tz,
committer, timestamp, tz, msg); *msg == '\n' ? "" : "\t", msg);
return 0; return 0;
} }

View File

@ -321,8 +321,9 @@ $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150260 +0000 Switch
$B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150860 +0000 $B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150860 +0000
EOF EOF
test_expect_success "verifying $m's log (logged by touch)" ' test_expect_success "verifying $m's log (logged by touch)" '
test_when_finished "rm -rf .git/$m .git/logs expect" && test_when_finished "git update-ref -d $m && rm -rf .git/logs actual expect" &&
test_cmp expect .git/logs/$m test-tool ref-store main for-each-reflog-ent $m >actual &&
test_cmp actual expect
' '
test_expect_success "create $m (logged by config)" ' test_expect_success "create $m (logged by config)" '
@ -350,8 +351,9 @@ $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150380 +0000 Switch
$B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150980 +0000 $B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150980 +0000
EOF EOF
test_expect_success "verifying $m's log (logged by config)" ' test_expect_success "verifying $m's log (logged by config)" '
test_when_finished "rm -f .git/$m .git/logs/$m expect" && test_when_finished "git update-ref -d $m && rm -rf .git/logs actual expect" &&
test_cmp expect .git/logs/$m test-tool ref-store main for-each-reflog-ent $m >actual &&
test_cmp actual expect
' '
test_expect_success 'set up for querying the reflog' ' 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
$h_FIXED $h_MERGED $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117151100 +0000 commit (merge): Merged initial commit and a later commit. $h_FIXED $h_MERGED $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117151100 +0000 commit (merge): Merged initial commit and a later commit.
EOF EOF
test_expect_success 'git commit logged updates' ' test_expect_success 'git commit logged updates' '
test_cmp expect .git/logs/$m test-tool ref-store main for-each-reflog-ent $m >actual &&
test_cmp expect actual
' '
unset h_TEST h_OTHER h_FIXED h_MERGED unset h_TEST h_OTHER h_FIXED h_MERGED

View File

@ -89,13 +89,13 @@ test_expect_success 'for_each_reflog()' '
test_expect_success 'for_each_reflog_ent()' ' test_expect_success 'for_each_reflog_ent()' '
$RUN for-each-reflog-ent HEAD >actual && $RUN for-each-reflog-ent HEAD >actual &&
head -n1 actual | grep one && head -n1 actual | grep one &&
tail -n2 actual | head -n1 | grep recreate-main tail -n1 actual | grep recreate-main
' '
test_expect_success 'for_each_reflog_ent_reverse()' ' test_expect_success 'for_each_reflog_ent_reverse()' '
$RUN for-each-reflog-ent-reverse HEAD >actual && $RUN for-each-reflog-ent-reverse HEAD >actual &&
head -n1 actual | grep recreate-main && head -n1 actual | grep recreate-main &&
tail -n2 actual | head -n1 | grep one tail -n1 actual | grep one
' '
test_expect_success 'reflog_exists(HEAD)' ' test_expect_success 'reflog_exists(HEAD)' '

View File

@ -75,13 +75,13 @@ test_expect_success 'for_each_reflog()' '
test_expect_success 'for_each_reflog_ent()' ' test_expect_success 'for_each_reflog_ent()' '
$RUN for-each-reflog-ent HEAD >actual && $RUN for-each-reflog-ent HEAD >actual &&
head -n1 actual | grep first && head -n1 actual | grep first &&
tail -n2 actual | head -n1 | grep main.to.new tail -n1 actual | grep main.to.new
' '
test_expect_success 'for_each_reflog_ent_reverse()' ' test_expect_success 'for_each_reflog_ent_reverse()' '
$RUN for-each-reflog-ent-reverse HEAD >actual && $RUN for-each-reflog-ent-reverse HEAD >actual &&
head -n1 actual | grep main.to.new && head -n1 actual | grep main.to.new &&
tail -n2 actual | head -n1 | grep first tail -n1 actual | grep first
' '
test_expect_success 'reflog_exists(HEAD)' ' test_expect_success 'reflog_exists(HEAD)' '

View File

@ -4,6 +4,9 @@ test_description='test show-branch'
. ./test-lib.sh . ./test-lib.sh
# arbitrary reference time: 2009-08-30 19:20:00
GIT_TEST_DATE_NOW=1251660000; export GIT_TEST_DATE_NOW
test_expect_success 'setup' ' test_expect_success 'setup' '
test_commit initial && test_commit initial &&
for i in $(test_seq 1 10) for i in $(test_seq 1 10)
@ -146,4 +149,16 @@ test_expect_success 'show branch --merge-base with N arguments' '
test_cmp expect actual test_cmp expect actual
' '
test_expect_success 'show branch --reflog=2' '
sed "s/^> //" >expect <<-\EOF &&
> ! [refs/heads/branch10@{0}] (4 years, 5 months ago) commit: branch10
> ! [refs/heads/branch10@{1}] (4 years, 5 months ago) commit: branch10
> --
> + [refs/heads/branch10@{0}] branch10
> ++ [refs/heads/branch10@{1}] initial
EOF
git show-branch --reflog=2 >actual &&
test_cmp actual expect
'
test_done test_done