git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 1/2] Modify pseudo refs through ref backend storage

From
Han-Wen Nienhuys <hanwen@google.com>
Date
Jul 7, 2020, 13:56 UTC
Message-ID
<CAFQ2z_OPbcX9FGsFnmraAUpTu2eKuf2PZ+DO-CTWvaBZD6WQQQ@mail.gmail.com>
In-Reply-To
<xmqqimf09ypc.fsf@gitster.c.googlers.com>
On Mon, Jul 6, 2020 at 10:27 PM Junio C Hamano <gitster@pobox.com> wrote:
Show 13 quoted lines
>
> "Han-Wen Nienhuys via GitGitGadget" <gitgitgadget@gmail.com> writes:
>
> > Subject: Re: [PATCH 1/2] Modify pseudo refs through ref backend storage
> > From: Han-Wen Nienhuys <hanwen@google.com>
>
> With what definition of "pseudo refs" has this change been made?
> Those things like HEAD, CHERRY_PICK_HEAD, FETCH_HEAD etc. that have
> traditionally been written as a plain text file in $GIT_DIR and are
> used to name objects by having a full object name in it?
>
> Or the entities that behave like refs and stored in ref backends,
> with all-uppercase-names but do not sit inside refs/ hierarchy?
I thought these were the same? - see below :)
Show 15 quoted lines
> I think it is OK (and possibly a good move in the longer term, but
> that is just my gut feeling) to make ref backends resopnsible for
> enumerating, reading and writing them (i.e. I think we want to use
> the latter definition for the longer term health of the project).
> And we would want to ...
>
> > The previous behavior was introduced in commit 74ec19d4be
> > ("pseudorefs: create and use pseudoref update and delete functions",
> > Jul 31, 2015), with the justification "alternate ref backends still
> > need to store pseudorefs in GIT_DIR".
>
> ... declare that justification invalid for that purpose.
>
> Is that what is going on?  I just want to make sure I am following
> your flow of thought.
yep.
Show 7 quoted lines
> >               const char *refname = refnames->items[i].string;
> > -
> >               if (refs_delete_ref(&refs->base, msg, refname, NULL, flags))
> >                       result |= error(_("could not remove reference %s"), refname);
> >       }
>
> Unreleated change?
oops.
Show 19 quoted lines
> > @@ -2436,7 +2435,9 @@ static int lock_ref_for_update(struct files_ref_store *refs,
> >       update->backend_data = lock;
> >
> >       if (update->type & REF_ISSYMREF) {
> > -             if (update->flags & REF_NO_DEREF) {
> > +             if (update->flags & REF_NO_DEREF ||
> > +                 (ref_type(update->refname) == REF_TYPE_PSEUDOREF &&
> > +                  strcmp(update->refname, "HEAD"))) {
> >                       /*
> >                        * We won't be reading the referent as part of
> >                        * the transaction, so we have to read it here
>
> The old "if we are not dereferencing" condition in if() exactly
> matched the comment, but the condition in if() after this change is
> not "if we are not dereferencing".  Even if we are dereferencing,
> under some new condition, we would still drop into this block and do
> not follow the "else" side that creates a new update for the
> referent.  Is this part of "modify pseudo refs via backend" topic,
> or should it be a separate modification?  Why is this change needed?
There is a  test (mentioned in the commit message), t1405, which does

$RUN create-symref FOO refs/heads/master nothing && # calls refs_create_symref() .. $RUN delete-refs 0 nothing FOO refs/tags/new-tag && # calls refs_delete_refs, which calls delete_pseudoref .. git rev-parse master >expected &&

Previously, the delete_pseudoref code would delete just .git/FOO file. Without the change here, going through the ref backend ends up in the !REF_NO_DEREF case, deleting the master branch.

I don't know what the correct semantics are (are symrefs used for anything except HEAD ?), so

Show 24 quoted lines
> It seems that no matter where in the refs/ hierarchy (or even
> outside) a symbolic ref resides, the way to update itself (not the
> referent through the symbolic ref) should be the same, which is what
> the original says, and we want to change that reasoning here, but it
> is not quite clear to me why.
>
> > @@ -2782,8 +2783,10 @@ static int files_transaction_finish(struct ref_store *ref_store,
> >               struct ref_update *update = transaction->updates[i];
> >               struct ref_lock *lock = update->backend_data;
> >
> > -             if (update->flags & REF_NEEDS_COMMIT ||
> > -                 update->flags & REF_LOG_ONLY) {
> > +             if ((ref_type(lock->ref_name) != REF_TYPE_PSEUDOREF ||
> > +                  !strcmp(lock->ref_name, "HEAD")) &&
> > +                 (update->flags & REF_NEEDS_COMMIT ||
> > +                  update->flags & REF_LOG_ONLY)) {
>
> And this one stops the files backend from touching all pseudorefs
> other than HEAD with this codepath.  That somehow feels totally
> opposite from what the log message explained above---weren't we
> updating the code to write these pseudorefs through the individual
> backends, which the files backend is one example of?  Isn't this
> change stopping the backend from writing the pseudorefs other than
> HEAD instead?
There is a test
  'core.logAllRefUpdates=always creates no reflog for ORIG_HEAD'

that wants there to not be reflog updates for ORIG_HEAD. I don't see why that behavior exists, and would be happy to change it, but I'm too much of a newbie to decide what is right here.

Show 11 quoted lines
> > --- a/t/t1400-update-ref.sh
> > +++ b/t/t1400-update-ref.sh
> > @@ -476,7 +476,7 @@ test_expect_success 'git cat-file blob master@{2005-05-26 23:42}:F (expect OTHER
> >  test_expect_success 'given old value for missing pseudoref, do not create' '
> >       test_must_fail git update-ref PSEUDOREF $A $B 2>err &&
> >       test_path_is_missing .git/PSEUDOREF &&
>
> The reason why I asked what this patch thinks the definition of
> pseudoref is is because of this thing.  Shouldn't this line be fixed
> not to depend on the files backend?  Likewise for $(cat .git/PSEUDOREF)
> in the remaining two hunks.

This patch doesn't introduce reftable yet, so both definitions are equivalent for the sake of this patch.

-- 
Han-Wen Nienhuys - Google Munich
I work 80%. Don't expect answers from me on Fridays.
--

Google Germany GmbH, Erika-Mann-Strasse 33, 80636 Munich
Registergericht und -nummer: Hamburg, HRB 86891
Sitz der Gesellschaft: Hamburg
Geschäftsführer: Paul Manicle, Halimah DeLaine Prado
Previous: Junio C HamanoNext: Junio C Hamano
Message 4 of 39 in “Remove special casing for PSEUDOREF updates”
  1. 0/2 Remove special casing for PSEUDOREF updatesHan-Wen Nienhuys via GitGitGadget, Jul 6, 2020
  2. 1/2 Modify pseudo refs through ref backend storageHan-Wen Nienhuys via GitGitGadget, Jul 6, 2020
  3. Junio C HamanoJul 6, 2020
  4. Han-Wen NienhuysJul 7, 2020
  5. Junio C HamanoJul 7, 2020
  6. Han-Wen NienhuysJul 7, 2020
  7. Junio C HamanoJul 7, 2020
  8. 2/2 Make HEAD a PSEUDOREF rather than PER_WORKTREE.Han-Wen Nienhuys via GitGitGadget, Jul 6, 2020
  9. Junio C HamanoJul 6, 2020
  10. Han-Wen NienhuysJul 7, 2020
  11. 0/3 Remove special casing for PSEUDOREF updatesHan-Wen Nienhuys via GitGitGadget, Jul 9, 2020
  12. 2/3 Modify pseudo refs through ref backend storageHan-Wen Nienhuys via GitGitGadget, Jul 9, 2020
  13. 3/3 Make HEAD a PSEUDOREF rather than PER_WORKTREE.Han-Wen Nienhuys via GitGitGadget, Jul 9, 2020
  14. 1/3 t1400: use git rev-parse for testing PSEUDOREF existenceHan-Wen Nienhuys via GitGitGadget, Jul 9, 2020
  15. Junio C HamanoJul 10, 2020
  16. 0/3 Remove special casing for PSEUDOREF updatesHan-Wen Nienhuys via GitGitGadget, Jul 16, 2020
  17. 1/3 t1400: use git rev-parse for testing PSEUDOREF existenceHan-Wen Nienhuys via GitGitGadget, Jul 16, 2020
  18. 3/3 Make HEAD a PSEUDOREF rather than PER_WORKTREE.Han-Wen Nienhuys via GitGitGadget, Jul 16, 2020
  19. 2/3 Modify pseudo refs through ref backend storageHan-Wen Nienhuys via GitGitGadget, Jul 16, 2020
  20. Johannes SchindelinJul 17, 2020
  21. Han-Wen NienhuysJul 27, 2020
  22. Junio C HamanoJul 16, 2020
  23. Han-Wen NienhuysJul 27, 2020
  24. Junio C HamanoJul 27, 2020
  25. Han-Wen NienhuysAug 3, 2020
  26. Junio C HamanoAug 3, 2020
  27. Junio C HamanoAug 5, 2020
  28. Han-Wen NienhuysAug 5, 2020
  29. Junio C HamanoAug 5, 2020
  30. Han-Wen NienhuysAug 10, 2020
  31. Junio C HamanoAug 10, 2020
  32. Han-Wen NienhuysAug 11, 2020
  33. Junio C HamanoAug 11, 2020
  34. Han-Wen NienhuysAug 19, 2020
  35. Junio C HamanoAug 19, 2020
  36. 0/3 Remove special casing for PSEUDOREF updatesHan-Wen Nienhuys via GitGitGadget, Jul 27, 2020
  37. 1/3 t1400: use git rev-parse for testing PSEUDOREF existenceHan-Wen Nienhuys via GitGitGadget, Jul 27, 2020
  38. 2/3 Modify pseudo refs through ref backend storageHan-Wen Nienhuys via GitGitGadget, Jul 27, 2020
  39. 3/3 Make HEAD a PSEUDOREF rather than PER_WORKTREE.Han-Wen Nienhuys via GitGitGadget, Jul 27, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.