summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <gitster@pobox.com>2021-12-15 09:39:48 -0800
committerLibravatar Junio C Hamano <gitster@pobox.com>2021-12-15 09:39:49 -0800
commit250ca49b4f3ee0781a98c47f4515ae597ca3dbab (patch)
tree098f5771954d02fa7803fa51c5c803825f294cfa
parentMerge branch 'rj/receive-pack-avoid-sigpipe-during-status-reporting' (diff)
parentrefs/debug: trim trailing LF from reflog message (diff)
downloadtgif-250ca49b4f3ee0781a98c47f4515ae597ca3dbab.tar.xz
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
-rw-r--r--builtin/show-branch.c12
-rw-r--r--refs/debug.c7
-rw-r--r--t/helper/test-ref-store.c6
-rwxr-xr-xt/t1400-update-ref.sh13
-rwxr-xr-xt/t1405-main-ref-store.sh4
-rwxr-xr-xt/t1406-submodule-ref-store.sh4
-rwxr-xr-xt/t3202-show-branch.sh15
7 files changed, 42 insertions, 19 deletions
diff --git a/builtin/show-branch.c b/builtin/show-branch.c
index 082449293b..f1e8318592 100644
--- a/builtin/show-branch.c
+++ b/builtin/show-branch.c
@@ -761,6 +761,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
char *logmsg;
char *nth_desc;
const char *msg;
+ char *end;
timestamp_t timestamp;
int tz;
@@ -770,11 +771,12 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
reflog = i;
break;
}
- msg = strchr(logmsg, '\t');
- if (!msg)
- msg = "(none)";
- else
- msg++;
+
+ end = strchr(logmsg, '\n');
+ if (end)
+ *end = '\0';
+
+ msg = (*logmsg == '\0') ? "(none)" : logmsg;
reflog_msg[i] = xstrfmt("(%s) %s",
show_date(timestamp, tz,
DATE_MODE(RELATIVE)),
diff --git a/refs/debug.c b/refs/debug.c
index 756d07c724..791423c6a7 100644
--- a/refs/debug.c
+++ b/refs/debug.c
@@ -284,6 +284,7 @@ static int debug_print_reflog_ent(struct object_id *old_oid,
int ret;
char o[GIT_MAX_HEXSZ + 1] = "null";
char n[GIT_MAX_HEXSZ + 1] = "null";
+ char *msgend = strchrnul(msg, '\n');
if (old_oid)
oid_to_hex_r(o, old_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,
dbg->cb_data);
- trace_printf_key(&trace_refs, "reflog_ent %s (ret %d): %s -> %s, %s %ld \"%s\"\n",
- dbg->refname, ret, o, n, committer, (long int)timestamp, msg);
+ trace_printf_key(&trace_refs,
+ "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;
}
diff --git a/t/helper/test-ref-store.c b/t/helper/test-ref-store.c
index 73461c29d3..971b755579 100644
--- a/t/helper/test-ref-store.c
+++ b/t/helper/test-ref-store.c
@@ -152,9 +152,9 @@ static int each_reflog(struct object_id *old_oid, struct object_id *new_oid,
const char *committer, timestamp_t timestamp,
int tz, const char *msg, void *cb_data)
{
- printf("%s %s %s %"PRItime" %d %s\n",
- oid_to_hex(old_oid), oid_to_hex(new_oid),
- committer, timestamp, tz, msg);
+ printf("%s %s %s %" PRItime " %+05d%s%s", oid_to_hex(old_oid),
+ oid_to_hex(new_oid), committer, timestamp, tz,
+ *msg == '\n' ? "" : "\t", msg);
return 0;
}
diff --git a/t/t1400-update-ref.sh b/t/t1400-update-ref.sh
index 0d4f73acaa..ef8fdcef46 100755
--- a/t/t1400-update-ref.sh
+++ b/t/t1400-update-ref.sh
@@ -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
EOF
test_expect_success "verifying $m's log (logged by touch)" '
- test_when_finished "rm -rf .git/$m .git/logs expect" &&
- test_cmp expect .git/logs/$m
+ test_when_finished "git update-ref -d $m && rm -rf .git/logs actual expect" &&
+ test-tool ref-store main for-each-reflog-ent $m >actual &&
+ test_cmp actual expect
'
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
EOF
test_expect_success "verifying $m's log (logged by config)" '
- test_when_finished "rm -f .git/$m .git/logs/$m expect" &&
- test_cmp expect .git/logs/$m
+ test_when_finished "git update-ref -d $m && rm -rf .git/logs actual expect" &&
+ test-tool ref-store main for-each-reflog-ent $m >actual &&
+ test_cmp actual expect
'
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.
EOF
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
diff --git a/t/t1405-main-ref-store.sh b/t/t1405-main-ref-store.sh
index c89cef2d26..3cb5e23d6d 100755
--- a/t/t1405-main-ref-store.sh
+++ b/t/t1405-main-ref-store.sh
@@ -89,13 +89,13 @@ test_expect_success 'for_each_reflog()' '
test_expect_success 'for_each_reflog_ent()' '
$RUN for-each-reflog-ent HEAD >actual &&
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()' '
$RUN for-each-reflog-ent-reverse HEAD >actual &&
head -n1 actual | grep recreate-main &&
- tail -n2 actual | head -n1 | grep one
+ tail -n1 actual | grep one
'
test_expect_success 'reflog_exists(HEAD)' '
diff --git a/t/t1406-submodule-ref-store.sh b/t/t1406-submodule-ref-store.sh
index c95c5d47aa..e6a7f7334b 100755
--- a/t/t1406-submodule-ref-store.sh
+++ b/t/t1406-submodule-ref-store.sh
@@ -75,13 +75,13 @@ test_expect_success 'for_each_reflog()' '
test_expect_success 'for_each_reflog_ent()' '
$RUN for-each-reflog-ent HEAD >actual &&
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()' '
$RUN for-each-reflog-ent-reverse HEAD >actual &&
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)' '
diff --git a/t/t3202-show-branch.sh b/t/t3202-show-branch.sh
index ad9902a06b..d4d64401e4 100755
--- a/t/t3202-show-branch.sh
+++ b/t/t3202-show-branch.sh
@@ -4,6 +4,9 @@ test_description='test show-branch'
. ./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_commit initial &&
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_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