Re: [PATCH 5/9] refs: avoid duplicate running of the reference-transaction hook
- From
Jiang Xin <worldhello.net@gmail.com>
- Date
- Aug 5, 2022, 01:41 UTC
- Message-ID
- <CANYiYbFw71bX827akAG87RSKOozPk313Hoe573O9dQ65_U6sLQ@mail.gmail.com>
- In-Reply-To
- <CAJDSCnOFSnhOU06UHF6T9RT31Gq56BhJn5fQ4_ys2ERrN1stSw@mail.gmail.com>
On Tue, Aug 2, 2022 at 8:18 PM Michael Heemskerk <mheemskerk@atlassian.com> wrote:
Show 21 quoted lines
> > On Fri, Jul 29, 2022 at 12:20 PM Jiang Xin <worldhello.net@gmail.com> wrote: > > > > From: Jiang Xin <zhiyou.jx@alibaba-inc.com> > > > > If there are references to be deleted in a transaction, we should remove > > each reference from both loose references and the "packed-refs" file. > > The "reference-transaction" hook will run twice, once for the primary > > ref-store (loose references), and another for the second ref-store (i.e. > > packed ref-store). > > > > To avoid duplicate running of the "reference-trancaction" hook, we pass > > a special "hook-flags" parameter to initialize the second ref-store. > > The "REF_TRANSACTION_RUN_PREPARED_HOOK" bit is preserved for the > > transaction of the second ref-store because we may still want to call > > command "reference-trancaction prepared" for some pre-checks, such as > > terminate unwanted transaction for the "packed-refs" file. > > Can you elaborate on the rationale for continuing to invoke the "prepared" > reference-transaction hook for the "packed-refs" file? Did you have a specific > type of check in mind?
Use "reference-transaction prepared" hook command, we can implement write lock for repositories. We can create a lock file (e.g. "site.lock") inside a repository or in a parent directory to disable write operations for one repository, a group of repositories or all repositories. The magic is in the "reference-transaction prepared" hook command. As a transaction may be triggered twice, one for packed-refs, and one for loose-refs, we should make sure the "reference-transaction prepared" command must run for both transactions on different ref-stores.
BTW, I'm on vacation for the next few days and I will pick up this topic next week.
-- Jiang Xin