From: Jiang Xin <worldhello.net@gmail.com>
To: Junio C Hamano <gitster@pobox.com>,
Patrick Steinhardt <ps@pks.im>,
Michael Heemskerk <mheemskerk@atlassian.com>,
Git List <git@vger.kernel.org>
Cc: Jiang Xin <zhiyou.jx@alibaba-inc.com>,
Jiang Xin <worldhello.net@gmail.com>
Subject: [PATCH v2 4/9] refs: do not run transaction hook for git-pack-refs
Date: Fri, 19 Aug 2022 11:21:42 +0800 [thread overview]
Message-ID: <20220819032147.28841-5-worldhello.net@gmail.com> (raw)
In-Reply-To: <CANYiYbFw71bX827akAG87RSKOozPk313Hoe573O9dQ65_U6sLQ@mail.gmail.com>
From: Jiang Xin <zhiyou.jx@alibaba-inc.com>
The git-pack-refs command will call "files_pack_refs()" to pack loose
references into the "packed-refs" file, and there are no real changes
to the repository. Therefore, by initializing a transaction with an
empty "hook_flags" field, the "reference-transaction" hook will not run.
The "prune_refs()" and "prune_ref()" functions are called from
"file_pack_refs()", and they are used to prune loose refereces which
have already been packed into "packed-refs". The transaction instance
in "prune_ref()" should also be initialized with an empty "hook_flags"
field.
The behavior of the following git commands and three testcases have been
fixed in t1416:
* git gc
* git pack-refs
Signed-off-by: Jiang Xin <zhiyou.jx@alibaba-inc.com>
---
refs/files-backend.c | 10 ++++++++--
t/t1416-ref-transaction-hooks.sh | 12 +++---------
2 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/refs/files-backend.c b/refs/files-backend.c
index 7c1c25a25c..f0947c9dca 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -1136,7 +1136,8 @@ static void prune_ref(struct files_ref_store *refs, struct ref_to_prune *r)
if (check_refname_format(r->name, 0))
return;
- transaction = ref_store_transaction_begin(&refs->base, &err);
+ /* Called by "files_pack_refs()" and should not run any hooks. */
+ transaction = ref_store_transaction_begin_extended(&refs->base, 0, &err);
if (!transaction)
goto cleanup;
ref_transaction_add_update(
@@ -1207,7 +1208,12 @@ static int files_pack_refs(struct ref_store *ref_store, unsigned int flags)
struct strbuf err = STRBUF_INIT;
struct ref_transaction *transaction;
- transaction = ref_store_transaction_begin(refs->packed_ref_store, &err);
+ /*
+ * No real changes have occurred to the repository and no hooks
+ * should be run for this transaction.
+ */
+ transaction = ref_store_transaction_begin_extended(refs->packed_ref_store,
+ 0, &err);
if (!transaction)
return -1;
diff --git a/t/t1416-ref-transaction-hooks.sh b/t/t1416-ref-transaction-hooks.sh
index 1ae601a73d..b7ffc9415b 100755
--- a/t/t1416-ref-transaction-hooks.sh
+++ b/t/t1416-ref-transaction-hooks.sh
@@ -392,9 +392,7 @@ test_expect_success "update-ref: update HEAD" '
test_cmp_heads_and_tags -C workdir expect
'
-# Failed because the reference-transaction hook was executed even
-# though no refs were changed by running git-pack-refs.
-test_expect_failure "update-ref: prepare packed_ref_store using pack-refs" '
+test_expect_success "update-ref: prepare packed_ref_store using pack-refs" '
test_when_finished "rm -f $HOOK_OUTPUT" &&
git -C workdir pack-refs --all &&
test_path_is_file workdir/.git/packed-refs &&
@@ -737,9 +735,7 @@ test_expect_success "branch: create new branches" '
test_cmp_heads_and_tags -C workdir expect
'
-# Failed because the reference-transaction hook was executed even
-# though no refs were changed by running git-gc.
-test_expect_failure "branch: prepare packed_ref_store using gc" '
+test_expect_success "branch: prepare packed_ref_store using gc" '
test_when_finished "rm -f $HOOK_OUTPUT" &&
git -C workdir gc &&
test_path_is_file workdir/.git/packed-refs &&
@@ -1014,9 +1010,7 @@ test_expect_success "tag: create new tags" '
test_cmp_heads_and_tags -C workdir expect
'
-# Failed because the reference-transaction hook was executed even
-# though no refs were changed by running git-pack-refs.
-test_expect_failure "tag: prepare packed_ref_store using pack-refs" '
+test_expect_success "tag: prepare packed_ref_store using pack-refs" '
test_when_finished "rm -f $HOOK_OUTPUT" &&
git -C workdir pack-refs --all &&
test_path_is_file workdir/.git/packed-refs &&
--
2.36.1.25.gc87d5ad63a.dirty
next prev parent reply other threads:[~2022-08-19 3:22 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-29 10:12 [PATCH 0/9] Fix issues of reference-transaction hook for various git commands Jiang Xin
2022-07-29 10:12 ` [PATCH 1/9] t1416: more testcases for reference-transaction hook Jiang Xin
2022-07-30 6:44 ` Eric Sunshine
2022-07-31 3:25 ` Jiang Xin
2022-07-29 10:12 ` [PATCH 2/9] refs: update missing old-oid in transaction from lockfile Jiang Xin
2022-07-29 10:12 ` [PATCH 3/9] refs: add new field in transaction for running transaction hook Jiang Xin
2022-07-29 10:12 ` [PATCH 4/9] refs: do not run transaction hook for git-pack-refs Jiang Xin
2022-07-29 10:12 ` [PATCH 5/9] refs: avoid duplicate running of the reference-transaction hook Jiang Xin
2022-08-02 12:18 ` Michael Heemskerk
2022-08-05 1:41 ` Jiang Xin
2022-08-19 3:21 ` [PATCH v2 0/9] Fix issues of refx-txn hook for various git commands Jiang Xin
2022-08-19 3:21 ` [PATCH v2 1/9] t1416: more testcases for reference-transaction hook Jiang Xin
2022-08-19 3:21 ` [PATCH v2 2/9] refs: update missing old-oid in transaction from lockfile Jiang Xin
2022-08-19 3:21 ` [PATCH v2 3/9] refs: add new field in transaction for running transaction hook Jiang Xin
2022-08-19 3:21 ` Jiang Xin [this message]
2022-08-19 3:21 ` [PATCH v2 5/9] refs: avoid duplicate running of the reference-transaction hook Jiang Xin
2022-08-19 3:21 ` [PATCH v2 6/9] refs: add reflog_info to hold more fields for reflog entry Jiang Xin
2022-08-19 3:21 ` [PATCH v2 7/9] refs: get error message via refs_update_ref_extended() Jiang Xin
2022-08-19 3:21 ` [PATCH v2 8/9] refs: reimplement files_copy_or_rename_ref() to run refs-txn hook Jiang Xin
2022-08-19 3:21 ` [PATCH v2 9/9] refs: reimplement refs_delete_refs() and run hook once Jiang Xin
2022-07-29 10:12 ` [PATCH 6/9] refs: add reflog_info to hold more fields for reflog entry Jiang Xin
2022-08-01 11:32 ` Jiang Xin
2022-07-29 10:12 ` [PATCH 7/9] refs: get error message via refs_update_ref_extended() Jiang Xin
2022-07-29 10:12 ` [PATCH 8/9] refs: reimplement files_copy_or_rename_ref() to run hook Jiang Xin
2022-07-29 10:12 ` [PATCH 9/9] refs: reimplement refs_delete_refs() and run hook once Jiang Xin
2022-08-02 12:42 ` Michael Heemskerk
2022-08-09 11:05 ` Patrick Steinhardt
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=20220819032147.28841-5-worldhello.net@gmail.com \
--to=worldhello.net@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=mheemskerk@atlassian.com \
--cc=ps@pks.im \
--cc=zhiyou.jx@alibaba-inc.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.