From: "Han-Wen Nienhuys via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>,
"Han-Wen Nienhuys" <hanwen@google.com>,
"Bagas Sanjaya" <bagasdotme@gmail.com>,
"Elijah Newren" <newren@gmail.com>,
"Han-Wen Nienhuys" <hanwenn@gmail.com>
Subject: [PATCH v2 0/5] Inspect reflog data programmatically in more tests
Date: Thu, 25 Nov 2021 15:57:47 +0000 [thread overview]
Message-ID: <pull.1145.v2.git.git.1637855872.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.1145.git.git.1637590855.gitgitgadget@gmail.com>
This helps for reftable support, and will help if we want to reconsider
under which conditions reflogs get created/updated.
Han-Wen Nienhuys (5):
show-branch: show reflog message
test-ref-store: don't add newline to reflog message
t1405: check for_each_reflog_ent_reverse() more thoroughly
test-ref-store: tweaks to for-each-reflog-ent format
refs/debug: trim trailing LF from reflog message
builtin/show-branch.c | 12 +++++++-----
refs/debug.c | 10 ++++++++--
t/helper/test-ref-store.c | 6 +++---
t/t1400-update-ref.sh | 13 ++++++++-----
t/t1405-main-ref-store.sh | 4 ++--
t/t1406-submodule-ref-store.sh | 4 ++--
t/t3202-show-branch.sh | 15 +++++++++++++++
7 files changed, 45 insertions(+), 19 deletions(-)
base-commit: 35151cf0720460a897cde9b8039af364743240e7
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1145%2Fhanwen%2Freflog-prelims-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1145/hanwen/reflog-prelims-v2
Pull-Request: https://github.com/git/git/pull/1145
Range-diff vs v1:
1: fd2595d370a = 1: 9d8394d8c76 show-branch: show reflog message
2: dfb63937323 ! 2: 4a86d212589 refs: trim newline from reflog message
@@ Metadata
Author: Han-Wen Nienhuys <hanwen@google.com>
## Commit message ##
- refs: trim newline from reflog message
+ test-ref-store: don't add newline to reflog message
- Commit 523fa69c ("reflog: cleanse messages in the refs.c layer") standardizes
- how write entries into the reflog. This commit standardizes how we get messages
- out of the reflog. Before, the files backend implicitly added '\n' to the end of
- reflog message on reading, which creates a subtle incompatibility with alternate
- ref storage backends, such as reftable.
-
- We address this by stripping LF from the message before we pass it to the
- user-provided callback.
+ The files backend produces a newline for messages automatically, so before we
+ would print blank lines between entries.
Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
- ## builtin/show-branch.c ##
-@@ builtin/show-branch.c: 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;
-
-@@ builtin/show-branch.c: int cmd_show_branch(int ac, const char **av, const char *prefix)
- break;
- }
-
-- end = strchr(logmsg, '\n');
-- if (end)
-- *end = '\0';
--
- msg = (*logmsg == '\0') ? "(none)" : logmsg;
- reflog_msg[i] = xstrfmt("(%s) %s",
- show_date(timestamp, tz,
-
- ## reflog-walk.c ##
-@@ reflog-walk.c: void get_reflog_message(struct strbuf *sb,
-
- info = &commit_reflog->reflogs->items[commit_reflog->recno+1];
- len = strlen(info->message);
-- if (len > 0)
-- len--; /* strip away trailing newline */
- strbuf_add(sb, info->message, len);
- }
-
-@@ reflog-walk.c: void show_reflog_message(struct reflog_walk_info *reflog_info, int oneline,
- info = &commit_reflog->reflogs->items[commit_reflog->recno+1];
- get_reflog_selector(&selector, reflog_info, dmode, force_date, 0);
- if (oneline) {
-- printf("%s: %s", selector.buf, info->message);
-+ printf("%s: %s\n", selector.buf, info->message);
- }
- else {
-- printf("Reflog: %s (%s)\nReflog message: %s",
-+ printf("Reflog: %s (%s)\nReflog message: %s\n",
- selector.buf, info->email, info->message);
- }
-
-
- ## refs/files-backend.c ##
-@@ refs/files-backend.c: static int show_one_reflog_ent(struct strbuf *sb, each_reflog_ent_fn fn, void *c
- int tz;
- const char *p = sb->buf;
-
-- /* old SP new SP name <email> SP time TAB msg LF */
-- if (!sb->len || sb->buf[sb->len - 1] != '\n' ||
-- parse_oid_hex(p, &ooid, &p) || *p++ != ' ' ||
-+ /* old SP new SP name <email> SP time TAB msg */
-+ if (!sb->len || parse_oid_hex(p, &ooid, &p) || *p++ != ' ' ||
- parse_oid_hex(p, &noid, &p) || *p++ != ' ' ||
-- !(email_end = strchr(p, '>')) ||
-- email_end[1] != ' ' ||
-+ !(email_end = strchr(p, '>')) || email_end[1] != ' ' ||
- !(timestamp = parse_timestamp(email_end + 2, &message, 10)) ||
- !message || message[0] != ' ' ||
-- (message[1] != '+' && message[1] != '-') ||
-- !isdigit(message[2]) || !isdigit(message[3]) ||
-- !isdigit(message[4]) || !isdigit(message[5]))
-+ (message[1] != '+' && message[1] != '-') || !isdigit(message[2]) ||
-+ !isdigit(message[3]) || !isdigit(message[4]) ||
-+ !isdigit(message[5]))
- return 0; /* corrupt? */
- email_end[1] = '\0';
- tz = strtol(message + 1, NULL, 10);
-@@ refs/files-backend.c: static int files_for_each_reflog_ent_reverse(struct ref_store *ref_store,
- strbuf_splice(&sb, 0, 0, bp + 1, endp - (bp + 1));
- scanp = bp;
- endp = bp + 1;
-+ strbuf_trim_trailing_newline(&sb);
- ret = show_one_reflog_ent(&sb, fn, cb_data);
- strbuf_reset(&sb);
- if (ret)
-@@ refs/files-backend.c: static int files_for_each_reflog_ent_reverse(struct ref_store *ref_store,
- * Process it, and we can end the loop.
- */
- strbuf_splice(&sb, 0, 0, buf, endp - buf);
-+ strbuf_trim_trailing_newline(&sb);
- ret = show_one_reflog_ent(&sb, fn, cb_data);
- strbuf_reset(&sb);
- break;
-@@ refs/files-backend.c: static int files_for_each_reflog_ent(struct ref_store *ref_store,
- if (!logfp)
- return -1;
-
-- while (!ret && !strbuf_getwholeline(&sb, logfp, '\n'))
-+ while (!ret && !strbuf_getline(&sb, logfp))
- ret = show_one_reflog_ent(&sb, fn, cb_data);
- fclose(logfp);
- strbuf_release(&sb);
-@@ refs/files-backend.c: static int expire_reflog_ent(struct object_id *ooid, struct object_id *noid,
- if ((*cb->should_prune_fn)(ooid, noid, email, timestamp, tz,
- message, policy_cb)) {
- if (!cb->newlog)
-- printf("would prune %s", message);
-+ printf("would prune %s\n", message);
- else if (cb->flags & EXPIRE_REFLOGS_VERBOSE)
-- printf("prune %s", message);
-+ printf("prune %s\n", message);
- } else {
- if (cb->newlog) {
-- fprintf(cb->newlog, "%s %s %s %"PRItime" %+05d\t%s",
-- oid_to_hex(ooid), oid_to_hex(noid),
-- email, timestamp, tz, message);
-+ fprintf(cb->newlog, "%s %s %s %" PRItime " %+05d\t%s\n",
-+ oid_to_hex(ooid), oid_to_hex(noid), email,
-+ timestamp, tz, message);
- oidcpy(&cb->last_kept_oid, noid);
- }
- if (cb->flags & EXPIRE_REFLOGS_VERBOSE)
-- printf("keep %s", message);
-+ printf("keep %s\n", message);
- }
+ ## t/helper/test-ref-store.c ##
+@@ t/helper/test-ref-store.c: 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 " %d %s", oid_to_hex(old_oid),
++ oid_to_hex(new_oid), committer, timestamp, tz, msg);
return 0;
}
+
## t/t1405-main-ref-store.sh ##
@@ t/t1405-main-ref-store.sh: test_expect_success 'for_each_reflog()' '
3: 8a1b094d547 ! 3: 0319503045b test-ref-store: tweaks to for-each-reflog-ent format
@@ Metadata
Author: Han-Wen Nienhuys <hanwen@google.com>
## Commit message ##
- test-ref-store: tweaks to for-each-reflog-ent format
+ t1405: check for_each_reflog_ent_reverse() more thoroughly
- Follow the reflog format more closely, so it can be used for comparing
- reflogs in tests without using inspecting files under .git/logs/
+ If we are checking for a certain ordering, we should check that there are two
+ entries. Do this by mirroring the preceding test.
Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
- ## t/helper/test-ref-store.c ##
-@@ t/helper/test-ref-store.c: 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\t%s\n", oid_to_hex(old_oid),
-+ oid_to_hex(new_oid), committer, timestamp, tz, msg);
- return 0;
- }
-
-
## t/t1405-main-ref-store.sh ##
@@ t/t1405-main-ref-store.sh: test_expect_success 'for_each_reflog_ent()' '
4: 4ba97a4e70a ! 4: 62f5cb8a824 t1400: use test-helper ref-store to inspect reflog contents
@@ Metadata
Author: Han-Wen Nienhuys <hanwen@google.com>
## Commit message ##
- t1400: use test-helper ref-store to inspect reflog contents
+ test-ref-store: tweaks to for-each-reflog-ent format
- This avoids inspecting the file system, which only works with the files ref
- backend.
+ We have some tests that read from files in .git/logs/ hierarchy
+ when checking if correct reflog entries are created, but that is
+ too specific to the files backend. Other backends like reftable
+ may not store its reflog entries in such a "one line per entry"
+ format.
+
+ Update for-each-reflog-ent test helper to produce output that
+ is identical to lines in a reflog file files backend uses.
+ That way, (1) the current tests can be updated to use the test
+ helper to read the reflog entries instead of (parts of) reflog
+ files, and perform the same inspection for correctness, and (2)
+ when the ref backend is swapped to another backend, the updated
+ test can be used as-is to check the correctness.
+
+ Adapt t1400 to use the for-each-reflog-ent test helper.
Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
- ## t/t1400-update-ref.sh ##
-@@ t/t1400-update-ref.sh: export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
- . ./test-lib.sh
+ ## t/helper/test-ref-store.c ##
+@@ t/helper/test-ref-store.c: 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", 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;
+ }
- Z=$ZERO_OID
-+TAB=' '
-
- m=refs/heads/main
- n_dir=refs/heads/gu
-@@ t/t1400-update-ref.sh: test_expect_success 'symref empty directory removal' '
- cat >expect <<EOF
- $Z $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 Initial Creation
- $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$TAB
+
+ ## t/t1400-update-ref.sh ##
+@@ t/t1400-update-ref.sh: $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" &&
@@ t/t1400-update-ref.sh: test_expect_success 'symref empty directory removal' '
'
test_expect_success "create $m (logged by config)" '
-@@ t/t1400-update-ref.sh: test_expect_success "set $m (logged by config)" '
- cat >expect <<EOF
- $Z $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150320 +0000 Initial Creation
- $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$TAB
+@@ t/t1400-update-ref.sh: $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" &&
-: ----------- > 5: 0288e743eb2 refs/debug: trim trailing LF from reflog message
--
gitgitgadget
next prev parent reply other threads:[~2021-11-25 16:10 UTC|newest]
Thread overview: 60+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-22 14:20 [PATCH 0/4] Inspect reflog data programmatically in more tests Han-Wen Nienhuys via GitGitGadget
2021-11-22 14:20 ` [PATCH 1/4] show-branch: show reflog message Han-Wen Nienhuys via GitGitGadget
2021-11-22 22:22 ` Junio C Hamano
2021-11-23 7:40 ` Bagas Sanjaya
2021-11-23 8:03 ` Elijah Newren
2021-11-22 14:20 ` [PATCH 2/4] refs: trim newline from " Han-Wen Nienhuys via GitGitGadget
2021-11-22 22:27 ` Junio C Hamano
2021-11-23 16:35 ` Han-Wen Nienhuys
2021-11-23 17:09 ` Junio C Hamano
2021-11-23 17:28 ` Han-Wen Nienhuys
2021-11-23 20:34 ` Junio C Hamano
2021-11-24 11:17 ` Han-Wen Nienhuys
2021-11-24 18:53 ` Junio C Hamano
2021-11-24 19:06 ` Han-Wen Nienhuys
2021-11-24 20:55 ` Junio C Hamano
2021-11-25 16:00 ` Han-Wen Nienhuys
2021-11-29 2:30 ` Junio C Hamano
2021-11-24 19:26 ` Junio C Hamano
2021-11-24 19:39 ` Han-Wen Nienhuys
2021-11-26 8:35 ` Re* " Junio C Hamano
2021-11-28 17:50 ` Ævar Arnfjörð Bjarmason
2021-11-28 18:59 ` Junio C Hamano
2021-11-28 19:25 ` Junio C Hamano
2021-11-29 8:39 ` Ævar Arnfjörð Bjarmason
2021-11-23 10:24 ` Ævar Arnfjörð Bjarmason
2021-11-23 16:44 ` Han-Wen Nienhuys
2021-11-22 14:20 ` [PATCH 3/4] test-ref-store: tweaks to for-each-reflog-ent format Han-Wen Nienhuys via GitGitGadget
2021-11-22 22:31 ` Junio C Hamano
2021-11-23 17:06 ` Han-Wen Nienhuys
2021-11-23 18:31 ` Junio C Hamano
2021-11-22 14:20 ` [PATCH 4/4] t1400: use test-helper ref-store to inspect reflog contents Han-Wen Nienhuys via GitGitGadget
2021-11-22 15:20 ` Ævar Arnfjörð Bjarmason
2021-11-22 17:07 ` Han-Wen Nienhuys
2021-11-22 22:22 ` Junio C Hamano
2021-11-25 15:57 ` Han-Wen Nienhuys via GitGitGadget [this message]
2021-11-25 15:57 ` [PATCH v2 1/5] show-branch: show reflog message Han-Wen Nienhuys via GitGitGadget
2021-11-25 15:57 ` [PATCH v2 2/5] test-ref-store: don't add newline to " Han-Wen Nienhuys via GitGitGadget
2021-11-26 7:56 ` Junio C Hamano
2021-11-25 15:57 ` [PATCH v2 3/5] t1405: check for_each_reflog_ent_reverse() more thoroughly Han-Wen Nienhuys via GitGitGadget
2021-11-25 15:57 ` [PATCH v2 4/5] test-ref-store: tweaks to for-each-reflog-ent format Han-Wen Nienhuys via GitGitGadget
2021-11-26 8:02 ` Junio C Hamano
2021-11-25 15:57 ` [PATCH v2 5/5] refs/debug: trim trailing LF from reflog message Han-Wen Nienhuys via GitGitGadget
2021-11-26 8:16 ` Junio C Hamano
2021-11-29 18:29 ` Han-Wen Nienhuys
2021-11-29 19:19 ` Junio C Hamano
2021-11-29 19:35 ` Junio C Hamano
2021-12-02 16:24 ` Han-Wen Nienhuys
2021-12-02 18:36 ` Junio C Hamano
2021-11-29 20:59 ` Ævar Arnfjörð Bjarmason
2021-11-29 9:50 ` [PATCH v2 0/5] Inspect reflog data programmatically in more tests Ævar Arnfjörð Bjarmason
2021-11-29 18:24 ` Han-Wen Nienhuys
2021-11-29 22:30 ` Junio C Hamano
2021-11-29 23:28 ` Ævar Arnfjörð Bjarmason
2021-12-02 16:11 ` Han-Wen Nienhuys
2021-12-02 17:36 ` [PATCH v3 " Han-Wen Nienhuys via GitGitGadget
2021-12-02 17:36 ` [PATCH v3 1/5] show-branch: show reflog message Han-Wen Nienhuys via GitGitGadget
2021-12-02 17:36 ` [PATCH v3 2/5] test-ref-store: don't add newline to " Han-Wen Nienhuys via GitGitGadget
2021-12-02 17:36 ` [PATCH v3 3/5] t1405: check for_each_reflog_ent_reverse() more thoroughly Han-Wen Nienhuys via GitGitGadget
2021-12-02 17:36 ` [PATCH v3 4/5] test-ref-store: tweaks to for-each-reflog-ent format Han-Wen Nienhuys via GitGitGadget
2021-12-02 17:36 ` [PATCH v3 5/5] refs/debug: trim trailing LF from reflog message Han-Wen Nienhuys via GitGitGadget
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=pull.1145.v2.git.git.1637855872.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=avarab@gmail.com \
--cc=bagasdotme@gmail.com \
--cc=git@vger.kernel.org \
--cc=hanwen@google.com \
--cc=hanwenn@gmail.com \
--cc=newren@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).