From: Jiang Xin <worldhello.net@gmail.com>
To: Junio C Hamano <gitster@pobox.com>,
Patrick Steinhardt <ps@pks.im>, Git List <git@vger.kernel.org>
Cc: Jiang Xin <zhiyou.jx@alibaba-inc.com>,
Jiang Xin <worldhello.net@gmail.com>
Subject: [PATCH 2/9] refs: update missing old-oid in transaction from lockfile
Date: Fri, 29 Jul 2022 18:12:38 +0800 [thread overview]
Message-ID: <20220729101245.6469-3-worldhello.net@gmail.com> (raw)
In-Reply-To: <20220729101245.6469-1-worldhello.net@gmail.com>
From: Jiang Xin <zhiyou.jx@alibaba-inc.com>
For commands that update a reference without providing an old-oid, the
"reference-transaction" hook will receive a zero-oid instead of the
correct old-oid.
In order to provide the "reference-transaction" hook with a real old-oid
in any case, get proper old_oid from the lock file and propagate it to
the corresponding update entry of a transaction.
The behavior of the following git commands and four testcases have been
fixed in t1416:
* git branch [-f] <ref> <new-oid> # update branch
* git cherry-pick <oid>
* git rebase
* git tag -d <tag>
* git update-ref --stdin # update refs
* git update-ref -d <ref>
* git update-ref <ref> <new-oid> [<old-oid>] # update ref
Signed-off-by: Jiang Xin <zhiyou.jx@alibaba-inc.com>
---
refs/files-backend.c | 9 +++++++++
t/t1416-ref-transaction-hooks.sh | 12 ++++++------
2 files changed, 15 insertions(+), 6 deletions(-)
diff --git a/refs/files-backend.c b/refs/files-backend.c
index 8db7882aac..957ebe08c0 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -2565,6 +2565,15 @@ static int lock_ref_for_update(struct files_ref_store *refs,
goto out;
}
+ /*
+ * Propagate old_oid from the lock to the update entry, so we can
+ * provide a real old-oid of to the "reference-transaction" hook.
+ */
+ if (!(update->flags & REF_HAVE_OLD)) {
+ oidcpy(&update->old_oid, &lock->old_oid);
+ update->flags |= REF_HAVE_OLD;
+ }
+
/*
* If this update is happening indirectly because of a
* symref update, record the old OID in the parent
diff --git a/t/t1416-ref-transaction-hooks.sh b/t/t1416-ref-transaction-hooks.sh
index a84621516c..eef7489b5b 100755
--- a/t/t1416-ref-transaction-hooks.sh
+++ b/t/t1416-ref-transaction-hooks.sh
@@ -53,7 +53,7 @@ test_expect_success 'hook gets all queued updates in prepared state' '
EOF
cat >expect <<-EOF &&
$ZERO_OID $POST_OID HEAD
- $ZERO_OID $POST_OID refs/heads/main
+ $PRE_OID $POST_OID refs/heads/main
EOF
git update-ref HEAD POST <<-EOF &&
update HEAD $ZERO_OID $POST_OID
@@ -76,7 +76,7 @@ test_expect_success 'hook gets all queued updates in committed state' '
EOF
cat >expect <<-EOF &&
$ZERO_OID $POST_OID HEAD
- $ZERO_OID $POST_OID refs/heads/main
+ $PRE_OID $POST_OID refs/heads/main
EOF
git update-ref HEAD POST &&
test_cmp expect actual
@@ -321,7 +321,7 @@ test_expect_success "update-ref: create new refs" '
test_cmp_heads_and_tags -C workdir expect
'
-test_expect_failure "update-ref: update HEAD, a symbolic-ref" '
+test_expect_success "update-ref: update HEAD, a symbolic-ref" '
test_when_finished "git switch main; rm -f $HOOK_OUTPUT" &&
cat >expect <<-EOF &&
@@ -365,7 +365,7 @@ test_expect_failure "update-ref: call git-pack-refs to create packed_ref_store"
test_path_is_missing $HOOK_OUTPUT
'
-test_expect_failure "update-ref: update refs already packed to .git/packed-refs" '
+test_expect_success "update-ref: update refs already packed to .git/packed-refs" '
test_when_finished "rm -f $HOOK_OUTPUT" &&
cat >expect <<-EOF &&
@@ -485,7 +485,7 @@ test_expect_success "update-ref --stdin: create new refs" '
test_cmp_heads_and_tags -C workdir expect
'
-test_expect_failure "update-ref --stdin: update refs" '
+test_expect_success "update-ref --stdin: update refs" '
test_when_finished "rm -f $HOOK_OUTPUT" &&
cat >expect <<-EOF &&
@@ -639,7 +639,7 @@ test_expect_failure "branch: call git-gc to create packed_ref_store" '
test_path_is_missing $HOOK_OUTPUT
'
-test_expect_failure "branch: update refs to create loose refs" '
+test_expect_success "branch: update refs to create loose refs" '
test_when_finished "rm -f $HOOK_OUTPUT" &&
cat >expect <<-EOF &&
--
2.36.1.25.gc87d5ad63a.dirty
next prev parent reply other threads:[~2022-07-29 10:12 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 ` Jiang Xin [this message]
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 ` [PATCH v2 4/9] refs: do not run transaction hook for git-pack-refs Jiang Xin
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=20220729101245.6469-3-worldhello.net@gmail.com \
--to=worldhello.net@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.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.