From patchwork Tue Dec 7 10:55:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 12661583 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4D2C0C433EF for ; Tue, 7 Dec 2021 10:56:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235462AbhLGLAK (ORCPT ); Tue, 7 Dec 2021 06:00:10 -0500 Received: from out4-smtp.messagingengine.com ([66.111.4.28]:38513 "EHLO out4-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229903AbhLGLAI (ORCPT ); Tue, 7 Dec 2021 06:00:08 -0500 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id 1D9685C007D; Tue, 7 Dec 2021 05:56:38 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Tue, 07 Dec 2021 05:56:38 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=date :from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm2; bh=p27TI6q/J8UTCjCcVJFgyTbdw1g RjdzhXN0sOWIFGnk=; b=iGWxrcjlW2Cvz1M7/G9HSezM2ZOpZpojyvvVaxXtmK2 t8eg4Lo+A9umNX7yt+XjaeYP1JFpxSivsmmIXZaDus3z2DGkzYIlvfGwuUrMPjPT JdsKMHy45oK1gWL7Pe3x55ri8TsBJA/bFDmcTH0IR/EwxFqsILTlfOBqiBDKzu0h fRVIAhY2MYQnWTmUTcC7uDfE1VsTDpgsAsYMyiVRd/RcA4Q0brrKfNFLPtOTDyBn oiOQL6HkwoOiat3AIy6jhaf7EWyFXri359Y5dTbsZ5FlI8pTZSgCSodcpVUz0JuE VKCaxn9sbuZKCewLZG9FEKwp+K1do/0CfMZIpeS13+w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=p27TI6 q/J8UTCjCcVJFgyTbdw1gRjdzhXN0sOWIFGnk=; b=KyRJlNA6Y2gGfi/MXmITFi ZdGLcg0+C1gb7V6GjaUxZjkhHL6AkLKJMi/kCAxv5em3feKH3dpbfAfny42piZoW svpqKgwccoGWe/J3DWYq0rcKDyXCnJG3PIA53z5eieFizLSOnRadO+Yeo67nasWZ 1XptzTD63hMn00swl6IPdPqDlpfkHSpWvdvVzykeLTJuHUtPk25gNRFYTWFQRK4u 2iT8MDLwBRQOO7VT5DlIR83y09T1hKDq+OpD+sTTS7gjpMNnBeOgUG2mHR5zMMjW VZ723GHMU2mwSK06roY/2/uXCCaSjwZncB1Y4qYN3sFyR+ImRh/fXNBAceUj2SGA == X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvuddrjeehgddvfecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhrihgt khcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnh epheeghfdtfeeuffehkefgffduleffjedthfdvjeektdfhhedvlefgtefgvdettdfhnecu vehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkh hsrdhimh X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 7 Dec 2021 05:56:36 -0500 (EST) Received: from localhost (ncase [10.192.0.11]) by vm-mail.pks.im (OpenSMTPD) with ESMTPSA id 3f932028 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 7 Dec 2021 12:26:15 +0000 (UTC) Date: Tue, 7 Dec 2021 11:55:56 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Jeff King , Bryan Turner , Waleed Khan Subject: [PATCH 1/6] refs: open-code deletion of packed refs Message-ID: <282c104b9ddbfa7579bd18fba0e64c6b6cc566b7.1638874287.git.ps@pks.im> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org When deleting loose refs, then we also have to delete the refs in the packed backend. This is done by calling `refs_delete_refs()`, which then uses the packed-backend's logic to delete refs. This doesn't allow us to exercise any control over the reference transaction which is being created in the packed backend, which is required in a subsequent commit. Extract a new function `packed_refs_delete_refs()`, which hosts most of the logic to delete refs except for creating the transaction itself. Like this, we can easily create the transactionion in the files backend and thus exert more control over it. Signed-off-by: Patrick Steinhardt --- refs/files-backend.c | 12 +++++++++--- refs/packed-backend.c | 28 +++++++++++++++++++++------- refs/packed-backend.h | 6 ++++++ 3 files changed, 36 insertions(+), 10 deletions(-) diff --git a/refs/files-backend.c b/refs/files-backend.c index 4b14f30d48..453adc38ea 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -1250,6 +1250,7 @@ static int files_delete_refs(struct ref_store *ref_store, const char *msg, { struct files_ref_store *refs = files_downcast(ref_store, REF_STORE_WRITE, "delete_refs"); + struct ref_transaction *transaction = NULL; struct strbuf err = STRBUF_INIT; int i, result = 0; @@ -1259,10 +1260,14 @@ static int files_delete_refs(struct ref_store *ref_store, const char *msg, if (packed_refs_lock(refs->packed_ref_store, 0, &err)) goto error; - if (refs_delete_refs(refs->packed_ref_store, msg, refnames, flags)) { - packed_refs_unlock(refs->packed_ref_store); + transaction = ref_store_transaction_begin(refs->packed_ref_store, &err); + if (!transaction) + goto error; + + result = packed_refs_delete_refs(refs->packed_ref_store, + transaction, msg, refnames, flags); + if (result) goto error; - } packed_refs_unlock(refs->packed_ref_store); @@ -1289,6 +1294,7 @@ static int files_delete_refs(struct ref_store *ref_store, const char *msg, else error(_("could not delete references: %s"), err.buf); + ref_transaction_free(transaction); strbuf_release(&err); return -1; } diff --git a/refs/packed-backend.c b/refs/packed-backend.c index 9da932a540..cb19b5291e 100644 --- a/refs/packed-backend.c +++ b/refs/packed-backend.c @@ -1522,15 +1522,10 @@ static int packed_initial_transaction_commit(struct ref_store *ref_store, static int packed_delete_refs(struct ref_store *ref_store, const char *msg, struct string_list *refnames, unsigned int flags) { - struct packed_ref_store *refs = - packed_downcast(ref_store, REF_STORE_WRITE, "delete_refs"); struct strbuf err = STRBUF_INIT; struct ref_transaction *transaction; - struct string_list_item *item; int ret; - (void)refs; /* We need the check above, but don't use the variable */ - if (!refnames->nr) return 0; @@ -1544,6 +1539,27 @@ static int packed_delete_refs(struct ref_store *ref_store, const char *msg, if (!transaction) return -1; + ret = packed_refs_delete_refs(ref_store, transaction, + msg, refnames, flags); + + ref_transaction_free(transaction); + return ret; +} + +int packed_refs_delete_refs(struct ref_store *ref_store, + struct ref_transaction *transaction, + const char *msg, + struct string_list *refnames, + unsigned int flags) +{ + struct packed_ref_store *refs = + packed_downcast(ref_store, REF_STORE_WRITE, "delete_refs"); + struct strbuf err = STRBUF_INIT; + struct string_list_item *item; + int ret; + + (void)(refs); /* We need the check above, but don't use the variable */ + for_each_string_list_item(item, refnames) { if (ref_transaction_delete(transaction, item->string, NULL, flags, msg, &err)) { @@ -1554,7 +1570,6 @@ static int packed_delete_refs(struct ref_store *ref_store, const char *msg, } ret = ref_transaction_commit(transaction, &err); - if (ret) { if (refnames->nr == 1) error(_("could not delete reference %s: %s"), @@ -1563,7 +1578,6 @@ static int packed_delete_refs(struct ref_store *ref_store, const char *msg, error(_("could not delete references: %s"), err.buf); } - ref_transaction_free(transaction); strbuf_release(&err); return ret; } diff --git a/refs/packed-backend.h b/refs/packed-backend.h index f61a73ec25..5e0dd7d08e 100644 --- a/refs/packed-backend.h +++ b/refs/packed-backend.h @@ -27,6 +27,12 @@ int packed_refs_lock(struct ref_store *ref_store, int flags, struct strbuf *err) void packed_refs_unlock(struct ref_store *ref_store); int packed_refs_is_locked(struct ref_store *ref_store); +int packed_refs_delete_refs(struct ref_store *ref_store, + struct ref_transaction *transaction, + const char *msg, + struct string_list *refnames, + unsigned int flags); + /* * Return true if `transaction` really needs to be carried out against * the specified packed_ref_store, or false if it can be skipped From patchwork Tue Dec 7 10:56:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 12661585 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 20F31C433EF for ; Tue, 7 Dec 2021 10:56:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235471AbhLGLAN (ORCPT ); Tue, 7 Dec 2021 06:00:13 -0500 Received: from out4-smtp.messagingengine.com ([66.111.4.28]:36701 "EHLO out4-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229903AbhLGLAM (ORCPT ); Tue, 7 Dec 2021 06:00:12 -0500 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 3DA1E5C01AA; Tue, 7 Dec 2021 05:56:42 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Tue, 07 Dec 2021 05:56:42 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=date :from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm2; bh=JN53XZrnaxgabDmZVd4rxXohVUX r0gQyUeN2eH4kgac=; b=k01gloU+Xrh1mi08/foVAiQDutfcxdNDBXUfDHNfk3S hfraNzgZq/mVnjp9vqYH4Ci//u5AJ0ldsH18wgJecAPv/riEH34MdDEzMnzQAOq/ 5kXvHHHBs8uuvFE98r4PafGRNdLBfhShmUvVq4eW6YZ3xiAeiEKd87IaD7QREBOq ojYiYjV/opE1plMiLeNGpgajDEdF98dnsJuXhtzwJv9DIns4XlATlLlec04hvZPs J5m5zyYN6DwjX+13Y23s4FRtfNZBVe1OW5ihQnK4H63P5PdHvfvECCX4/rqhhD9Q se4OSnvMzfGVn7WOE6D5g/o4Ei5TB74U127rCgzU2gQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=JN53XZ rnaxgabDmZVd4rxXohVUXr0gQyUeN2eH4kgac=; b=dVK/ncr9e/fM8pGN2om3p3 GB036k0dWSViJYHtA5DvJVcM6GTu32NZ7xq7GLj8RP5y6vT8KcJEaO5p599xUmZs pHmKl1obw3TuqJyqXNRrShFMZQ2nRWrvypxnJcuvI1bSQay6CdHbV7SROOzhC5sc EBVn07AgTyLQnRFpDSF7rel+02NQlmh5MCxkCah3eMxkE80lIXO58d7bxKL9Tw4F diDI83KF6JgDfjbbi0SuhlnEv2bAy4M3S3t+aND7SCUQxRz/CCNL3Ee+stjkj2W5 woLOGWdL89GWlD8HLOfKeDKkXOJG2vhpWGjSjW5TcUw6AR0HmQl0LKKQYRlY+l/Q == X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvuddrjeehgddvfecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhrihgt khcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnh epheeghfdtfeeuffehkefgffduleffjedthfdvjeektdfhhedvlefgtefgvdettdfhnecu vehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkh hsrdhimh X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 7 Dec 2021 05:56:41 -0500 (EST) Received: from localhost (ncase [10.192.0.11]) by vm-mail.pks.im (OpenSMTPD) with ESMTPSA id 2b349db0 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 7 Dec 2021 12:26:19 +0000 (UTC) Date: Tue, 7 Dec 2021 11:56:00 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Jeff King , Bryan Turner , Waleed Khan Subject: [PATCH 2/6] refs: allow passing flags when beginning transactions Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org We do not currently have any flags when creating reference transactions, but we'll add one to disable execution of the reference transaction hook in some cases. Allow passing flags to `ref_store_transaction_begin()` to prepare for this change. Signed-off-by: Patrick Steinhardt --- refs.c | 8 +++++--- refs.h | 3 ++- refs/files-backend.c | 10 +++++----- refs/packed-backend.c | 2 +- refs/refs-internal.h | 1 + sequencer.c | 2 +- 6 files changed, 15 insertions(+), 11 deletions(-) diff --git a/refs.c b/refs.c index 996ac27164..1c8a0c01f1 100644 --- a/refs.c +++ b/refs.c @@ -800,7 +800,7 @@ int refs_delete_ref(struct ref_store *refs, const char *msg, struct ref_transaction *transaction; struct strbuf err = STRBUF_INIT; - transaction = ref_store_transaction_begin(refs, &err); + transaction = ref_store_transaction_begin(refs, 0, &err); if (!transaction || ref_transaction_delete(transaction, refname, old_oid, flags, msg, &err) || @@ -1005,6 +1005,7 @@ int read_ref_at(struct ref_store *refs, const char *refname, } struct ref_transaction *ref_store_transaction_begin(struct ref_store *refs, + unsigned int flags, struct strbuf *err) { struct ref_transaction *tr; @@ -1012,12 +1013,13 @@ struct ref_transaction *ref_store_transaction_begin(struct ref_store *refs, CALLOC_ARRAY(tr, 1); tr->ref_store = refs; + tr->flags = flags; return tr; } struct ref_transaction *ref_transaction_begin(struct strbuf *err) { - return ref_store_transaction_begin(get_main_ref_store(the_repository), err); + return ref_store_transaction_begin(get_main_ref_store(the_repository), 0, err); } void ref_transaction_free(struct ref_transaction *transaction) @@ -1148,7 +1150,7 @@ int refs_update_ref(struct ref_store *refs, const char *msg, struct strbuf err = STRBUF_INIT; int ret = 0; - t = ref_store_transaction_begin(refs, &err); + t = ref_store_transaction_begin(refs, 0, &err); if (!t || ref_transaction_update(t, refname, new_oid, old_oid, flags, msg, &err) || diff --git a/refs.h b/refs.h index 45c34e99e3..e3d3b7aa14 100644 --- a/refs.h +++ b/refs.h @@ -231,7 +231,7 @@ char *repo_default_branch_name(struct repository *r, int quiet); * struct strbuf err = STRBUF_INIT; * int ret = 0; * - * transaction = ref_store_transaction_begin(refs, &err); + * transaction = ref_store_transaction_begin(refs, 0, &err); * if (!transaction || * ref_transaction_update(...) || * ref_transaction_create(...) || @@ -551,6 +551,7 @@ enum action_on_err { * be freed by calling ref_transaction_free(). */ struct ref_transaction *ref_store_transaction_begin(struct ref_store *refs, + unsigned int flags, struct strbuf *err); struct ref_transaction *ref_transaction_begin(struct strbuf *err); diff --git a/refs/files-backend.c b/refs/files-backend.c index 453adc38ea..95583dcd00 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -1122,7 +1122,7 @@ 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); + transaction = ref_store_transaction_begin(&refs->base, 0, &err); if (!transaction) goto cleanup; ref_transaction_add_update( @@ -1193,7 +1193,7 @@ 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); + transaction = ref_store_transaction_begin(refs->packed_ref_store, 0, &err); if (!transaction) return -1; @@ -1260,7 +1260,7 @@ static int files_delete_refs(struct ref_store *ref_store, const char *msg, if (packed_refs_lock(refs->packed_ref_store, 0, &err)) goto error; - transaction = ref_store_transaction_begin(refs->packed_ref_store, &err); + transaction = ref_store_transaction_begin(refs->packed_ref_store, 0, &err); if (!transaction) goto error; @@ -2767,7 +2767,7 @@ static int files_transaction_prepare(struct ref_store *ref_store, */ if (!packed_transaction) { packed_transaction = ref_store_transaction_begin( - refs->packed_ref_store, err); + refs->packed_ref_store, 0, err); if (!packed_transaction) { ret = TRANSACTION_GENERIC_ERROR; goto cleanup; @@ -3038,7 +3038,7 @@ static int files_initial_transaction_commit(struct ref_store *ref_store, &affected_refnames)) BUG("initial ref transaction called with existing refs"); - packed_transaction = ref_store_transaction_begin(refs->packed_ref_store, err); + packed_transaction = ref_store_transaction_begin(refs->packed_ref_store, 0, err); if (!packed_transaction) { ret = TRANSACTION_GENERIC_ERROR; goto cleanup; diff --git a/refs/packed-backend.c b/refs/packed-backend.c index cb19b5291e..ac4d92460e 100644 --- a/refs/packed-backend.c +++ b/refs/packed-backend.c @@ -1535,7 +1535,7 @@ static int packed_delete_refs(struct ref_store *ref_store, const char *msg, * updates into a single transaction. */ - transaction = ref_store_transaction_begin(ref_store, &err); + transaction = ref_store_transaction_begin(ref_store, 0, &err); if (!transaction) return -1; diff --git a/refs/refs-internal.h b/refs/refs-internal.h index fb2c58ce3b..5bec9014ac 100644 --- a/refs/refs-internal.h +++ b/refs/refs-internal.h @@ -213,6 +213,7 @@ struct ref_transaction { size_t nr; enum ref_transaction_state state; void *backend_data; + unsigned int flags; }; /* diff --git a/sequencer.c b/sequencer.c index b4135a78c9..78122e0f0c 100644 --- a/sequencer.c +++ b/sequencer.c @@ -3599,7 +3599,7 @@ static int do_label(struct repository *r, const char *name, int len) strbuf_addf(&ref_name, "refs/rewritten/%.*s", len, name); strbuf_addf(&msg, "rebase (label) '%.*s'", len, name); - transaction = ref_store_transaction_begin(refs, &err); + transaction = ref_store_transaction_begin(refs, 0, &err); if (!transaction) { error("%s", err.buf); ret = -1; From patchwork Tue Dec 7 10:56:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 12661587 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 23BF7C433F5 for ; Tue, 7 Dec 2021 10:56:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235463AbhLGLAR (ORCPT ); Tue, 7 Dec 2021 06:00:17 -0500 Received: from out4-smtp.messagingengine.com ([66.111.4.28]:44857 "EHLO out4-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235466AbhLGLAQ (ORCPT ); Tue, 7 Dec 2021 06:00:16 -0500 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 3D2F25C0039; Tue, 7 Dec 2021 05:56:46 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Tue, 07 Dec 2021 05:56:46 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=date :from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm2; bh=z/MQqbskvrmSpKBAcDfjMcY0Lkm u//JN6oxgS/8PpMk=; b=q57wPpj4uBmirYPxV7oI/djAClmXQw7Mlo1nhvzsJlj tVd5SvD62NCj9noGiB7Kq4yHl4rf9IukQoPqK+8h8nmjdVuegNp3qBndMLEgbzl6 BDtjO+0X4UVJOzhv4NO3SlPfxv3yDcdnjf24MNkTZfDvYXmv1pS+FdUvWpyV8k4c xP4l6R7dpfw9o5zOcqpy0pfdmr2HfuBI3QhCtmqshaoJF+ag1qyefUCCUrksK4gZ H+UlhK5P9GVmf1DX7Xy9TDXmWVXd0kj/603DNooaNk1ArXPrgSFNY71GwvGmWEmD shvcY96vPvQIECBsyLLco24q+CRhgECPQrtRVdmn7Dw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=z/MQqb skvrmSpKBAcDfjMcY0Lkmu//JN6oxgS/8PpMk=; b=SxFF3MaYZptGnQk28tq+MA fhOkh8y/80/7FZpk3OU58xFbfnzCWZEejzraLUIB1Wni9dmIwy9sLbEbIJ94wUS4 ExK/d8nba9cdUYFyqSkFqrS4MoJBILfAod3ETTYeSKIhdHQS8AwFQuj/KN8a3g+R Z8byyLw052rksWuWHSkXbtjyG+GoJt+3qn7mSgpeVHgid8gLmJNi+wt5ZZC0Cw/T lj5frw7hkfu09y17yRmc8GwPjQntENMpN9ajuiJRKt0tjeFfLYM0Xdks/2mjDzpK QlluDYB2a5cW8zaxwMr5WnRHSpr5rWr7kWSiRlf6sZCNhfs7xT2EM2G3NFt9HRjQ == X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvuddrjeehgddvfecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhrihgt khcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnh epheeghfdtfeeuffehkefgffduleffjedthfdvjeektdfhhedvlefgtefgvdettdfhnecu vehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkh hsrdhimh X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 7 Dec 2021 05:56:45 -0500 (EST) Received: from localhost (ncase [10.192.0.11]) by vm-mail.pks.im (OpenSMTPD) with ESMTPSA id 044aa871 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 7 Dec 2021 12:26:23 +0000 (UTC) Date: Tue, 7 Dec 2021 11:56:05 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Jeff King , Bryan Turner , Waleed Khan Subject: [PATCH 3/6] refs: allow skipping the reference-transaction hook Message-ID: <0e42fc07f80903135bae10ac91e139f85ca9db54.1638874287.git.ps@pks.im> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The reference-transaction hook is executing whenever we prepare, commit or abort a reference transaction. While this is mostly intentional, in case of the files backend we're leaking the implementation detail that the store is in fact a composite store with one loose and one packed backend to the caller. So while we want to execute the hook for all logical updates, executing it for such implementation details is unexpected. Prepare for a fix by adding a new flag which allows to skip execution of the hook. Signed-off-by: Patrick Steinhardt --- refs.c | 3 +++ refs.h | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/refs.c b/refs.c index 1c8a0c01f1..462e629d37 100644 --- a/refs.c +++ b/refs.c @@ -2076,6 +2076,9 @@ static int run_transaction_hook(struct ref_transaction *transaction, const char *hook; int ret = 0, i; + if (transaction->flags & REF_TRANSACTION_SKIP_HOOK) + return 0; + hook = find_hook("reference-transaction"); if (!hook) return ret; diff --git a/refs.h b/refs.h index e3d3b7aa14..840fa02613 100644 --- a/refs.h +++ b/refs.h @@ -546,6 +546,11 @@ enum action_on_err { UPDATE_REFS_QUIET_ON_ERR }; +/* + * Skip executing the reference-transaction hook. + */ +#define REF_TRANSACTION_SKIP_HOOK (1 << 0) + /* * Begin a reference transaction. The reference transaction must * be freed by calling ref_transaction_free(). From patchwork Tue Dec 7 10:56:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 12661589 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id ECBFCC433F5 for ; Tue, 7 Dec 2021 10:56:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235476AbhLGLAV (ORCPT ); Tue, 7 Dec 2021 06:00:21 -0500 Received: from out4-smtp.messagingengine.com ([66.111.4.28]:33845 "EHLO out4-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235472AbhLGLAU (ORCPT ); Tue, 7 Dec 2021 06:00:20 -0500 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 56BA55C019E; Tue, 7 Dec 2021 05:56:50 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Tue, 07 Dec 2021 05:56:50 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=date :from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm2; bh=vI3cdpdBRlTNX2hgcUA6QBY2yq/ C09JPb3RsMRjj9qs=; b=e155owaqlP/jo+HdDolaaJ/Oyw9iBs1FZN23uby2qq8 ueg+bi7EcPBYYZJ1pbcBtu0Oid8KBteoTi7PnhZj210Jplz4UR4QlxpYnia3Sp73 ffOvdvXjnEy5hEBpKEc5Eo5lm1AjOcvrtogmbQ2tvE72JsQii45gYEXM0enEtm3a tJWAxs1mGCebF8BrzZDyUrdB502TLRtz3PsOVvbT5ggsmLj3pT29qfRTS+Q/poPn VAGSwHkcHInHYa/yNPfjfjGK2Ok431ebp1ZjGektmEU/B8+s1+f553hSSZm03DmK tDczOsDSJCSxTOv0aTASdxELZPlQtd9SwscgQxjeyjA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=vI3cdp dBRlTNX2hgcUA6QBY2yq/C09JPb3RsMRjj9qs=; b=Sg/X4ZeJMqTtqP6cvJv6kW XeV2w46aWS9VEZJX0QAYn8ZYb7MaHcETYsW95Rov6D0Bqcg0d8GNE4Nb+21/qEp/ 6EEWCUhRmR1dqcm8g7XMeTA8kiMVCz8Wg9h6R7fkCwRERNqHzj3RMD7bFn3t7Gmq 8LRz4+za3AiUJuELAYk6p6CSEMe4sh71CVlFfCjs8L2RcCdxZQVJzTSvb4z5gsey TfFR2Wda1A8PtK9toWOg+YF0+rNFLw9mGNFYXVwHYcW144wKDqjDRTIqBCqgCjr1 7bw1ytojIFxJ+rycf3cmRUVQ9D3fAdgMpbYlc8JclMy/fqSHZi/81GpwQTjo0RIQ == X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvuddrjeehgddvfecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhrihgt khcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnh epheeghfdtfeeuffehkefgffduleffjedthfdvjeektdfhhedvlefgtefgvdettdfhnecu vehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkh hsrdhimh X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 7 Dec 2021 05:56:49 -0500 (EST) Received: from localhost (ncase [10.192.0.11]) by vm-mail.pks.im (OpenSMTPD) with ESMTPSA id 584b0f8a (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 7 Dec 2021 12:26:27 +0000 (UTC) Date: Tue, 7 Dec 2021 11:56:09 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Jeff King , Bryan Turner , Waleed Khan Subject: [PATCH 4/6] refs: demonstrate excessive execution of the reference-transaction hook Message-ID: <972ba1bc34974cb5a93c9863fa86fbc471ee6606.1638874287.git.ps@pks.im> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Add tests which demonstate which demonstrates that we're executing the reference-transaction hook too often in some cases, which thus leaks implementation details about the reference store's implementation itself. Behaviour will be fixed in follow-up commits. Signed-off-by: Patrick Steinhardt --- t/t1416-ref-transaction-hooks.sh | 64 ++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/t/t1416-ref-transaction-hooks.sh b/t/t1416-ref-transaction-hooks.sh index 6c941027a8..0567fbdf0b 100755 --- a/t/t1416-ref-transaction-hooks.sh +++ b/t/t1416-ref-transaction-hooks.sh @@ -136,4 +136,68 @@ test_expect_success 'interleaving hook calls succeed' ' test_cmp expect target-repo.git/actual ' +test_expect_success 'hook does not get called on packing refs' ' + # Pack references first such that we are in a known state. + git pack-refs --all && + + write_script .git/hooks/reference-transaction <<-\EOF && + echo "$@" >>actual + cat >>actual + EOF + rm -f actual && + + git update-ref refs/heads/unpacked-ref $POST_OID && + git pack-refs --all && + + # We only expect a single hook invocation, which is the call to + # git-update-ref(1). But currently, packing refs will also trigger the + # hook. + cat >expect <<-EOF && + prepared + $ZERO_OID $POST_OID refs/heads/unpacked-ref + committed + $ZERO_OID $POST_OID refs/heads/unpacked-ref + prepared + $ZERO_OID $POST_OID refs/heads/unpacked-ref + committed + $ZERO_OID $POST_OID refs/heads/unpacked-ref + prepared + $POST_OID $ZERO_OID refs/heads/unpacked-ref + committed + $POST_OID $ZERO_OID refs/heads/unpacked-ref + EOF + + test_cmp expect actual +' + +test_expect_success 'deleting packed ref calls hook once' ' + # Create a reference and pack it. + git update-ref refs/heads/to-be-deleted $POST_OID && + git pack-refs --all && + + write_script .git/hooks/reference-transaction <<-\EOF && + echo "$@" >>actual + cat >>actual + EOF + rm -f actual && + + git update-ref -d refs/heads/to-be-deleted $POST_OID && + + # We only expect a single hook invocation, which is the logical + # deletion. But currently, we see two interleaving transactions, once + # for deleting the loose refs and once for deleting the packed ref. + cat >expect <<-EOF && + prepared + $ZERO_OID $ZERO_OID refs/heads/to-be-deleted + prepared + $POST_OID $ZERO_OID refs/heads/to-be-deleted + committed + $ZERO_OID $ZERO_OID refs/heads/to-be-deleted + committed + $POST_OID $ZERO_OID refs/heads/to-be-deleted + EOF + + test_cmp expect actual +' + test_done From patchwork Tue Dec 7 10:56:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 12661591 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C4DC2C433EF for ; Tue, 7 Dec 2021 10:56:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235478AbhLGLAZ (ORCPT ); Tue, 7 Dec 2021 06:00:25 -0500 Received: from out4-smtp.messagingengine.com ([66.111.4.28]:33625 "EHLO out4-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235472AbhLGLAY (ORCPT ); Tue, 7 Dec 2021 06:00:24 -0500 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 739CC5C019E; Tue, 7 Dec 2021 05:56:54 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Tue, 07 Dec 2021 05:56:54 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=date :from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm2; bh=HemMUxYexzt6UrZS38Rast9rIRK q0c+cXxe7osGeW7E=; b=IfxjitxKIM73KzO/cMFdxDWlI1tPF9rRvAsf+Z1WUzr xJyZtIQhL+bAxboGBp+Z5xKm/8vOd6LQLPZll1zjwPOM5Ayqz6v9d0AEbyg6uf4v By494wof8WHltq/G6gvge+MVUfyrIeSaQv98qTmtG7i1x7ulOILnV+OWKHcDLCHq QBiwusNgpWDPyYPKqegRE0aZQjWUOagm5t7DDqCzcVezxRDEwgLlHAj2M/pP0z4w heqovm+PVPtrHh3eQKWcbwLT2JtFrATiA8fYV+glnKDlK6IwGnPqiylDale1o2al Fn1KiUZM+4Vf3SOG9msrR0rTvTw434uss8wMy372gjg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=HemMUx Yexzt6UrZS38Rast9rIRKq0c+cXxe7osGeW7E=; b=XWmQAfwvcrvve3Hb4YidQt 3XnNJlOqmsopJwhV4WLL+KFVTpB5GZZv3dtxeC14etxQDVMTws+/7n03as6HmMwY 8ivK9erkDObyIZur13HzoDwvh5vuX3UhuhzCcUcwjWaPz6lI2YuySnDJ0A6LDT78 BvS+IByZCg1/tESrfEo0bhVENf50F8ZtSLoqqCvqr6Wcjwl+ToNveM96TikODG43 kRlcKbQ5vBg0WU7s0YMDAudaFJD0dR1z+w2K0KaHqhdn2CWFMRMhuwBFk/Q7NBm5 RGuvzNf66suCcNJMyNB9aERGkfzIRiS5W6cgSpo4fXin+SA70jPrYAeAM4Po3xeA == X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvuddrjeehgddvfecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhrihgt khcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnh epheeghfdtfeeuffehkefgffduleffjedthfdvjeektdfhhedvlefgtefgvdettdfhnecu vehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkh hsrdhimh X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 7 Dec 2021 05:56:53 -0500 (EST) Received: from localhost (ncase [10.192.0.11]) by vm-mail.pks.im (OpenSMTPD) with ESMTPSA id 87838cd9 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 7 Dec 2021 12:26:32 +0000 (UTC) Date: Tue, 7 Dec 2021 11:56:13 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Jeff King , Bryan Turner , Waleed Khan Subject: [PATCH 5/6] refs: do not execute reference-transaction hook on packing refs Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The reference-transaction hook is supposed to track logical changes to references, but it currently also gets executed when packing refs in a repository. This is unexpected and ultimately not all that useful: packing refs is not supposed to result in any user-visible change to the refs' state, and it ultimately is an implementation detail of how refs stores work. Fix this excessive execution of the hook when packing refs. Reported-by: Waleed Khan Signed-off-by: Patrick Steinhardt --- refs/files-backend.c | 6 ++++-- t/t1416-ref-transaction-hooks.sh | 11 +---------- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/refs/files-backend.c b/refs/files-backend.c index 95583dcd00..f2bc72f81b 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -1122,7 +1122,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, 0, &err); + transaction = ref_store_transaction_begin(&refs->base, + REF_TRANSACTION_SKIP_HOOK, &err); if (!transaction) goto cleanup; ref_transaction_add_update( @@ -1193,7 +1194,8 @@ 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, 0, &err); + transaction = ref_store_transaction_begin(refs->packed_ref_store, + REF_TRANSACTION_SKIP_HOOK, &err); if (!transaction) return -1; diff --git a/t/t1416-ref-transaction-hooks.sh b/t/t1416-ref-transaction-hooks.sh index 0567fbdf0b..f9d3d5213f 100755 --- a/t/t1416-ref-transaction-hooks.sh +++ b/t/t1416-ref-transaction-hooks.sh @@ -150,21 +150,12 @@ test_expect_success 'hook does not get called on packing refs' ' git pack-refs --all && # We only expect a single hook invocation, which is the call to - # git-update-ref(1). But currently, packing refs will also trigger the - # hook. + # git-update-ref(1). cat >expect <<-EOF && prepared $ZERO_OID $POST_OID refs/heads/unpacked-ref committed $ZERO_OID $POST_OID refs/heads/unpacked-ref - prepared - $ZERO_OID $POST_OID refs/heads/unpacked-ref - committed - $ZERO_OID $POST_OID refs/heads/unpacked-ref - prepared - $POST_OID $ZERO_OID refs/heads/unpacked-ref - committed - $POST_OID $ZERO_OID refs/heads/unpacked-ref EOF test_cmp expect actual From patchwork Tue Dec 7 10:56:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 12661593 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 83460C433EF for ; Tue, 7 Dec 2021 10:57:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235482AbhLGLA3 (ORCPT ); Tue, 7 Dec 2021 06:00:29 -0500 Received: from out4-smtp.messagingengine.com ([66.111.4.28]:58283 "EHLO out4-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235472AbhLGLA2 (ORCPT ); Tue, 7 Dec 2021 06:00:28 -0500 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 8605C5C019E; Tue, 7 Dec 2021 05:56:58 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Tue, 07 Dec 2021 05:56:58 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=date :from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm2; bh=okJ2Nn9XAaNmRwqOFXZiX+YiI1E otfryC/lDqgAC8Zc=; b=WZn1tKowUngYxHsJrWU/fWHpoTSbKvQqkMdQ/WowTqr 9wKBxutB23YF1+hHPWISOlfDixVOoXdVp4DAv6pF1FSG68Y/V/1BRgpVH0zwOLvR jlT6e7GlACqBJ7V+GVKK43KmPeGM5RTdmzmGHbyoRD+p1izfkHrvSPJrNSvs/MIL sZmU+ETzljTGJB5brFKYSE1SwHaIHcW+3CTlM4ajKw8SdrRaAHyqrSV0okDW0FXY esF8UxzBHfLl4jIjLPdzXvqTiY5bP2WPx8wgjGxdYVQEkm1pouLMCghpLstOQ+4/ 4d6j44lRDtbIWSpFnYPbIITcMxODydl7Eo/dzpbnDqw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=okJ2Nn 9XAaNmRwqOFXZiX+YiI1EotfryC/lDqgAC8Zc=; b=VkJUy7J6bO3kgHPpclj48Y ahsPdz+0yW6ohyWt3fteiskCF0EItb0Q5hperWvuk4qC2lYQhtqT501OAg3r+Ece TwkkcirX6cAzlizuPs+VfY4ghEs04cxBe8P951YiHNPZoUdWZYblr2VmyqKOphad yV11gDaMsfWCsk8uL8guf8Y7+2GvfsC2PpJG98RiZYE0aU6uwgkEn6rZlnu2Gga5 CZqt+ec/XWStKEjJRn/FekBRsboqkxItczS1nKBsbbgmfDspYXzeLxW/UVbxepud qHLcrUTl/KmLDxo2+WfSUnxPUokWlKA9S/DdkHOIARxfagrULoc0IVJ8iiU/dBKg == X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvuddrjeehgddvfecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhrihgt khcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnh epheeghfdtfeeuffehkefgffduleffjedthfdvjeektdfhhedvlefgtefgvdettdfhnecu vehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkh hsrdhimh X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 7 Dec 2021 05:56:57 -0500 (EST) Received: from localhost (ncase [10.192.0.11]) by vm-mail.pks.im (OpenSMTPD) with ESMTPSA id 4d304524 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 7 Dec 2021 12:26:36 +0000 (UTC) Date: Tue, 7 Dec 2021 11:56:17 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Jeff King , Bryan Turner , Waleed Khan Subject: [PATCH 6/6] refs: skip hooks when deleting uncovered packed refs Message-ID: <04d65ff7991f880920a1fcaab3e4450fad0f15de.1638874287.git.ps@pks.im> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org When deleting refs from the loose-files refs backend, then we need to be careful to also delete the same ref from the packed refs backend, if it exists. If we don't, then deleting the loose ref would "uncover" the packed ref. We thus always have to queue up deletions of refs for both the loose and the packed refs backend. This is done in two separate transactions, where the end result is that the reference-transaction hook is executed twice for the deleted refs. This behaviour is quite misleading: it's exposing implementation details of how the files backend works to the user, in contrast to the logical updates that we'd really want to expose via the hook. Worse yet, whether the hook gets executed once or twice depends on how well-packed the repository is: if the ref only exists as a loose ref, then we execute it once, otherwise if it is also packed then we execute it twice. Fix this behaviour and don't execute the reference-transaction hook at all when refs in the packed-refs backend if it's driven by the files backend. Signed-off-by: Patrick Steinhardt --- refs/files-backend.c | 9 ++++++--- t/t1416-ref-transaction-hooks.sh | 7 +------ 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/refs/files-backend.c b/refs/files-backend.c index f2bc72f81b..0a2b5ea5da 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -1262,7 +1262,8 @@ static int files_delete_refs(struct ref_store *ref_store, const char *msg, if (packed_refs_lock(refs->packed_ref_store, 0, &err)) goto error; - transaction = ref_store_transaction_begin(refs->packed_ref_store, 0, &err); + transaction = ref_store_transaction_begin(refs->packed_ref_store, + REF_TRANSACTION_SKIP_HOOK, &err); if (!transaction) goto error; @@ -2769,7 +2770,8 @@ static int files_transaction_prepare(struct ref_store *ref_store, */ if (!packed_transaction) { packed_transaction = ref_store_transaction_begin( - refs->packed_ref_store, 0, err); + refs->packed_ref_store, + REF_TRANSACTION_SKIP_HOOK, err); if (!packed_transaction) { ret = TRANSACTION_GENERIC_ERROR; goto cleanup; @@ -3040,7 +3042,8 @@ static int files_initial_transaction_commit(struct ref_store *ref_store, &affected_refnames)) BUG("initial ref transaction called with existing refs"); - packed_transaction = ref_store_transaction_begin(refs->packed_ref_store, 0, err); + packed_transaction = ref_store_transaction_begin(refs->packed_ref_store, + REF_TRANSACTION_SKIP_HOOK, err); if (!packed_transaction) { ret = TRANSACTION_GENERIC_ERROR; goto cleanup; diff --git a/t/t1416-ref-transaction-hooks.sh b/t/t1416-ref-transaction-hooks.sh index f9d3d5213f..4e1e84a91f 100755 --- a/t/t1416-ref-transaction-hooks.sh +++ b/t/t1416-ref-transaction-hooks.sh @@ -175,16 +175,11 @@ test_expect_success 'deleting packed ref calls hook once' ' git update-ref -d refs/heads/to-be-deleted $POST_OID && # We only expect a single hook invocation, which is the logical - # deletion. But currently, we see two interleaving transactions, once - # for deleting the loose refs and once for deleting the packed ref. + # deletion. cat >expect <<-EOF && - prepared - $ZERO_OID $ZERO_OID refs/heads/to-be-deleted prepared $POST_OID $ZERO_OID refs/heads/to-be-deleted committed - $ZERO_OID $ZERO_OID refs/heads/to-be-deleted - committed $POST_OID $ZERO_OID refs/heads/to-be-deleted EOF