From: Maciej Ciemborowicz <maciej.ciemborowicz@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
"Patrick Steinhardt" <ps@pks.im>,
"Phil Hord" <phil.hord@gmail.com>,
"Elijah Newren" <newren@gmail.com>,
"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>,
"D . Ben Knoble" <ben.knoble@gmail.com>,
"Maciej Ciemborowicz" <maciej.ciemborowicz@gmail.com>
Subject: [PATCH 2/3] branch, tag: retain old OIDs in batched deletions
Date: Sat, 19 Sep 2026 22:11:57 +0200 [thread overview]
Message-ID: <20260919201158.43415-3-maciej.ciemborowicz@gmail.com> (raw)
In-Reply-To: <20260919201158.43415-1-maciej.ciemborowicz@gmail.com>
Since 8198907795 (use delete_refs when deleting tags or branches,
2021-01-21), branch and tag deletion pass no old OIDs to the ref transaction.
As a result, reference-transaction hooks report zero as both the old and new
OID.
Both commands already resolve the old OIDs before starting the deletion. Pass
those values to refs_delete_refs() so hooks receive useful old values without
adding any ref reads.
Signed-off-by: Maciej Ciemborowicz <maciej.ciemborowicz@gmail.com>
---
builtin/branch.c | 6 +++++-
builtin/tag.c | 6 +++++-
t/t1416-ref-transaction-hooks.sh | 28 ++++++++++++++++++++++++++++
3 files changed, 38 insertions(+), 2 deletions(-)
diff --git a/builtin/branch.c b/builtin/branch.c
index f1abeb681d..9f03ebc095 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -16,6 +16,7 @@
#include "commit.h"
#include "gettext.h"
#include "object-name.h"
+#include "oid-array.h"
#include "remote.h"
#include "parse-options.h"
#include "branch.h"
@@ -230,6 +231,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
struct strbuf bname = STRBUF_INIT;
enum interpret_branch_kind allowed_interpret;
struct string_list refs_to_delete = STRING_LIST_INIT_DUP;
+ struct oid_array old_oids = OID_ARRAY_INIT;
struct string_list_item *item;
int branch_name_pos;
const char *fmt_remotes = "refs/remotes/%s";
@@ -314,6 +316,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
}
item = string_list_append(&refs_to_delete, name);
+ oid_array_append(&old_oids, &oid);
item->util = xstrdup((flags & REF_ISBROKEN) ? "broken"
: (flags & REF_ISSYMREF) ? target
: repo_find_unique_abbrev(the_repository, &oid, DEFAULT_ABBREV));
@@ -323,7 +326,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
}
if (refs_delete_refs(get_main_ref_store(the_repository), NULL,
- &refs_to_delete, NULL, REF_NO_DEREF))
+ &refs_to_delete, &old_oids, REF_NO_DEREF))
ret = 1;
for_each_string_list_item(item, &refs_to_delete) {
@@ -342,6 +345,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
free(describe_ref);
}
string_list_clear(&refs_to_delete, 0);
+ oid_array_clear(&old_oids);
free(name);
strbuf_release(&bname);
diff --git a/builtin/tag.c b/builtin/tag.c
index 40874a2923..0a3eb70faf 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -119,11 +119,14 @@ static int delete_tags(const char **argv)
{
int result;
struct string_list refs_to_delete = STRING_LIST_INIT_DUP;
+ struct oid_array old_oids = OID_ARRAY_INIT;
struct string_list_item *item;
result = for_each_tag_name(argv, collect_tags, (void *)&refs_to_delete);
+ for_each_string_list_item(item, &refs_to_delete)
+ oid_array_append(&old_oids, item->util);
if (refs_delete_refs(get_main_ref_store(the_repository), NULL,
- &refs_to_delete, NULL, REF_NO_DEREF))
+ &refs_to_delete, &old_oids, REF_NO_DEREF))
result = 1;
for_each_string_list_item(item, &refs_to_delete) {
@@ -137,6 +140,7 @@ static int delete_tags(const char **argv)
free(oid);
}
string_list_clear(&refs_to_delete, 0);
+ oid_array_clear(&old_oids);
return result;
}
diff --git a/t/t1416-ref-transaction-hooks.sh b/t/t1416-ref-transaction-hooks.sh
index 4fe9d9b234..8d400cd7ac 100755
--- a/t/t1416-ref-transaction-hooks.sh
+++ b/t/t1416-ref-transaction-hooks.sh
@@ -14,6 +14,34 @@ test_expect_success setup '
POST_OID=$(git rev-parse POST)
'
+test_expect_success 'hook gets old values for batched branch/tag deletion' '
+ test_when_finished "rm -f actual" &&
+ git branch to-delete PRE &&
+ git tag delete-tag POST &&
+ git pack-refs --all &&
+ test_hook reference-transaction <<-\EOF &&
+ if test "$1" = committed
+ then
+ # Ignore backend-internal zero-to-zero records.
+ while read -r old new ref
+ do
+ case "$old" in
+ *[!0]*)
+ echo "$old $new $ref"
+ ;;
+ esac
+ done >>actual
+ fi
+ EOF
+ cat >expect <<-EOF &&
+ $PRE_OID $ZERO_OID refs/heads/to-delete
+ $POST_OID $ZERO_OID refs/tags/delete-tag
+ EOF
+ git branch -D to-delete &&
+ git tag -d delete-tag &&
+ test_cmp expect actual
+'
+
test_expect_success 'hook allows updating ref if successful' '
git reset --hard PRE &&
test_hook reference-transaction <<-\EOF &&
--
2.39.3 (Apple Git-146)
next prev parent reply other threads:[~2026-09-19 20:12 UTC|newest]
Thread overview: 52+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-19 13:34 [BUG] reference-transaction reports zero OIDs for branch and tag deletion Maciej Ciemborowicz
2026-09-19 14:59 ` D. Ben Knoble
2026-09-19 15:42 ` Maciej Ciemborowicz
2026-09-19 20:11 ` [PATCH 0/3] refs: report old OIDs for batched deletions Maciej Ciemborowicz
2026-09-19 20:11 ` [PATCH 1/3] refs: allow callers to supply old OIDs for batch deletion Maciej Ciemborowicz
2026-09-19 20:41 ` Karthik Nayak
2026-09-20 10:38 ` Maciej Ciemborowicz
2026-09-20 10:54 ` [PATCH v2 0/3] refs: report old OIDs for batched deletions Maciej Ciemborowicz
2026-09-20 10:54 ` [PATCH v2 1/3] refs: allow callers to supply old OIDs for batch deletion Maciej Ciemborowicz
2026-09-21 13:12 ` Karthik Nayak
2026-09-21 23:55 ` Junio C Hamano
2026-09-20 10:54 ` [PATCH v2 2/3] branch, tag: retain old OIDs in batched deletions Maciej Ciemborowicz
2026-09-21 13:19 ` Karthik Nayak
2026-09-20 10:54 ` [PATCH v2 3/3] fetch, remote: retain old OIDs when pruning refs Maciej Ciemborowicz
2026-09-21 13:56 ` Karthik Nayak
2026-09-21 13:57 ` [PATCH v2 0/3] refs: report old OIDs for batched deletions Karthik Nayak
2026-09-21 20:01 ` Maciej Ciemborowicz
2026-09-22 12:26 ` [PATCH v3 " Maciej Ciemborowicz
2026-09-22 12:26 ` [PATCH v3 1/3] refs: allow callers to supply old OIDs for batch deletion Maciej Ciemborowicz
2026-09-22 18:55 ` Junio C Hamano
2026-09-22 19:21 ` Maciej Ciemborowicz
2026-09-22 23:31 ` Junio C Hamano
2026-09-22 12:26 ` [PATCH v3 2/3] branch, tag: retain old OIDs in batched deletions Maciej Ciemborowicz
2026-09-22 12:26 ` [PATCH v3 3/3] fetch, remote: retain old OIDs when pruning refs Maciej Ciemborowicz
2026-09-22 19:16 ` Junio C Hamano
2026-09-22 22:29 ` [PATCH v4 0/3] refs: report old OIDs for batched deletions Maciej Ciemborowicz
2026-09-22 22:31 ` [PATCH v4 1/3] refs: allow callers to supply old OIDs for batch deletion Maciej Ciemborowicz
2026-09-22 22:31 ` [PATCH v4 2/3] branch, tag: retain old OIDs in batched deletions Maciej Ciemborowicz
2026-09-22 22:31 ` [PATCH v4 3/3] fetch, remote: retain old OIDs when pruning refs Maciej Ciemborowicz
2026-09-23 20:03 ` Junio C Hamano
2026-09-23 21:02 ` Maciej Ciemborowicz
2026-09-23 21:04 ` [PATCH v5 0/3] refs: report old OIDs for batched deletions Maciej Ciemborowicz
2026-09-23 21:04 ` [PATCH v5 1/3] refs: allow callers to supply old OIDs for batch deletion Maciej Ciemborowicz
2026-09-24 10:04 ` Karthik Nayak
2026-09-24 16:34 ` Junio C Hamano
2026-09-24 19:43 ` Maciej Ciemborowicz
2026-09-24 11:07 ` Patrick Steinhardt
2026-09-24 16:45 ` Junio C Hamano
2026-09-24 20:13 ` Maciej Ciemborowicz
2026-09-28 6:44 ` Patrick Steinhardt
2026-09-28 6:43 ` Patrick Steinhardt
2026-09-24 19:56 ` Maciej Ciemborowicz
2026-09-23 21:04 ` [PATCH v5 2/3] branch, tag: retain old OIDs in batched deletions Maciej Ciemborowicz
2026-09-24 11:08 ` Patrick Steinhardt
2026-09-23 21:04 ` [PATCH v5 3/3] fetch, remote: retain old OIDs when pruning refs Maciej Ciemborowicz
2026-09-23 21:55 ` [PATCH v5 0/3] refs: report old OIDs for batched deletions Junio C Hamano
2026-09-24 22:33 ` [PATCH v6 0/1] refs: report old values to transaction hooks Maciej Ciemborowicz
2026-09-24 22:33 ` [PATCH v6 1/1] " Maciej Ciemborowicz
2026-09-30 3:11 ` Maciej Ciemborowicz
2026-10-01 17:37 ` Maciej Ciemborowicz
2026-09-19 20:11 ` Maciej Ciemborowicz [this message]
2026-09-19 20:11 ` [PATCH 3/3] fetch, remote: retain old OIDs when pruning refs Maciej Ciemborowicz
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=20260919201158.43415-3-maciej.ciemborowicz@gmail.com \
--to=maciej.ciemborowicz@gmail.com \
--cc=avarab@gmail.com \
--cc=ben.knoble@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=newren@gmail.com \
--cc=phil.hord@gmail.com \
--cc=ps@pks.im \
/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