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

[PATCH v3 0/4] refs: improve handling of special refs

From
Patrick Steinhardt <ps@pks.im>
Date
Dec 14, 2023, 13:36 UTC
Message-ID
<cover.1702560829.git.ps@pks.im>
In-Reply-To
<cover.1701243201.git.ps@pks.im>
Hi,

this is the third version of my patch series to improve handling of special refs.

Changes combpared to v2:
  - Patch 1: We're now more careful around missing and symbolic refs.
  - Patch 3: Document in the commit message that the extended list of
    special refs is not intended to stay like this forever.
Thanks for your reviews and the discussion!
Patrick
Patrick Steinhardt (4):
  wt-status: read HEAD and ORIG_HEAD via the refdb
  refs: propagate errno when reading special refs fails
  refs: complete list of special refs
  bisect: consistently write BISECT_EXPECTED_REV via the refdb
 bisect.c                    | 25 +++-------------
 builtin/bisect.c            |  8 ++---
 refs.c                      | 59 +++++++++++++++++++++++++++++++++++--
 t/t1403-show-ref.sh         | 10 +++++++
 t/t6030-bisect-porcelain.sh |  2 +-
 wt-status.c                 | 22 +++++++++-----
 6 files changed, 87 insertions(+), 39 deletions(-)
Range-diff against v2:
1:  1db3eb3945 ! 1:  aea9410bd9 wt-status: read HEAD and ORIG_HEAD via the refdb
    @@ Commit message
         via the refdb layer so that we'll also be compatible with alternate
         reference backends.
     
    -    Note that we pass `RESOLVE_REF_NO_RECURSE` to `read_ref_full()`. This is
    -    because we didn't resolve symrefs before either, and in practice none of
    -    the refs in "rebase-merge/" would be symbolic. We thus don't want to
    -    resolve symrefs with the new code either to retain the old behaviour.
    +    There are some subtleties involved here:
    +
    +      - We pass `RESOLVE_REF_READING` so that a missing ref will cause
    +        `read_ref_full()` to return an error.
    +
    +      - We pass `RESOLVE_REF_NO_RECURSE` so that we do not try to resolve
    +        symrefs. The old code didn't resolve symrefs either, and we only
    +        ever write object IDs into the refs in "rebase-merge/".
    +
    +      - In the same spirit we verify that successfully-read refs are not
    +        symbolic refs.
     
         Signed-off-by: Patrick Steinhardt <ps@pks.im>
     
    @@ wt-status.c: static char *read_line_from_git_path(const char *filename)
     -	char *head, *orig_head, *rebase_amend, *rebase_orig_head;
     +	struct object_id head_oid, orig_head_oid;
     +	char *rebase_amend, *rebase_orig_head;
    ++	int head_flags, orig_head_flags;
      
      	if ((!s->amend && !s->nowarn && !s->workdir_dirty) ||
      	    !s->branch || strcmp(s->branch, "HEAD"))
    @@ wt-status.c: static char *read_line_from_git_path(const char *filename)
      
     -	head = read_line_from_git_path("HEAD");
     -	orig_head = read_line_from_git_path("ORIG_HEAD");
    -+	if (read_ref_full("HEAD", RESOLVE_REF_NO_RECURSE, &head_oid, NULL) ||
    -+	    read_ref_full("ORIG_HEAD", RESOLVE_REF_NO_RECURSE, &orig_head_oid, NULL))
    ++	if (read_ref_full("HEAD", RESOLVE_REF_READING | RESOLVE_REF_NO_RECURSE,
    ++			  &head_oid, &head_flags) ||
    ++	    read_ref_full("ORIG_HEAD", RESOLVE_REF_READING | RESOLVE_REF_NO_RECURSE,
    ++			  &orig_head_oid, &orig_head_flags))
    ++		return 0;
    ++	if (head_flags & REF_ISSYMREF || orig_head_flags & REF_ISSYMREF)
     +		return 0;
     +
      	rebase_amend = read_line_from_git_path("rebase-merge/amend");
2:  24032a62e5 = 2:  455ab69177 refs: propagate errno when reading special refs fails
3:  3dd9089fd5 ! 3:  81ac092281 refs: complete list of special refs
    @@ Commit message
     
         We're already mostly good with regard to the first item, except for
         `BISECT_EXPECTED_REV` which will be addressed in a subsequent commit.
    -    But the current list of special refs is missing a lot of refs that
    -    really should be treated specially. Right now, we only treat
    -    `FETCH_HEAD` and `MERGE_HEAD` specially here.
    +    But the current list of special refs is missing some refs that really
    +    should be treated specially. Right now, we only treat `FETCH_HEAD` and
    +    `MERGE_HEAD` specially here.
     
         Introduce a new function `is_special_ref()` that contains all current
         instances of special refs to fix the reading path.
     
    +    Note that this is only a temporary measure where we record and rectify
    +    the current state. Ideally, the list of special refs should in the end
    +    only contain `FETCH_HEAD` and `MERGE_HEAD` again because they both may
    +    reference multiple objects and can contain annotations, so they indeed
    +    are special.
    +
         Based-on-patch-by: Han-Wen Nienhuys <hanwenn@gmail.com>
         Signed-off-by: Patrick Steinhardt <ps@pks.im>
     
4:  4a4447a3f5 = 4:  3244678161 bisect: consistently write BISECT_EXPECTED_REV via the refdb
base-commit: 1a87c842ece327d03d08096395969aca5e0a6996
-- 
2.43.GIT
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 35 of 41 in “refs: improve handling of special refs”
  1. 0/4 refs: improve handling of special refsPatrick Steinhardt, Nov 29, 2023
  2. 1/4 wt-status: read HEAD and ORIG_HEAD via the refdbPatrick Steinhardt, Nov 29, 2023
  3. Taylor BlauNov 29, 2023
  4. Patrick SteinhardtNov 30, 2023
  5. Taylor BlauNov 30, 2023
  6. 2/4 refs: propagate errno when reading special refs failsPatrick Steinhardt, Nov 29, 2023
  7. Taylor BlauNov 29, 2023
  8. Patrick SteinhardtNov 30, 2023
  9. 3/4 refs: complete list of special refsPatrick Steinhardt, Nov 29, 2023
  10. Taylor BlauNov 29, 2023
  11. Patrick SteinhardtNov 30, 2023
  12. Phillip WoodNov 30, 2023
  13. Patrick SteinhardtDec 1, 2023
  14. Phillip WoodDec 4, 2023
  15. 4/4 bisect: consistently write BISECT_EXPECTED_REV via the refdbPatrick Steinhardt, Nov 29, 2023
  16. Taylor BlauNov 29, 2023
  17. Taylor BlauNov 29, 2023
  18. Patrick SteinhardtNov 30, 2023
  19. Taylor BlauNov 30, 2023
  20. 0/4 refs: improve handling of special refsPatrick Steinhardt, Dec 12, 2023
  21. 1/4 wt-status: read HEAD and ORIG_HEAD via the refdbPatrick Steinhardt, Dec 12, 2023
  22. Junio C HamanoDec 12, 2023
  23. Ramsay JonesDec 12, 2023
  24. Junio C HamanoDec 13, 2023
  25. Patrick SteinhardtDec 13, 2023
  26. Junio C HamanoDec 13, 2023
  27. Patrick SteinhardtDec 14, 2023
  28. Junio C HamanoDec 14, 2023
  29. Patrick SteinhardtDec 14, 2023
  30. 2/4 refs: propagate errno when reading special refs failsPatrick Steinhardt, Dec 12, 2023
  31. Junio C HamanoDec 12, 2023
  32. Patrick SteinhardtDec 13, 2023
  33. 3/4 refs: complete list of special refsPatrick Steinhardt, Dec 12, 2023
  34. 4/4 bisect: consistently write BISECT_EXPECTED_REV via the refdbPatrick Steinhardt, Dec 12, 2023
  35. 0/4 refs: improve handling of special refsPatrick Steinhardt, Dec 14, 2023
  36. 1/4 wt-status: read HEAD and ORIG_HEAD via the refdbPatrick Steinhardt, Dec 14, 2023
  37. 2/4 refs: propagate errno when reading special refs failsPatrick Steinhardt, Dec 14, 2023
  38. 3/4 refs: complete list of special refsPatrick Steinhardt, Dec 14, 2023
  39. 4/4 bisect: consistently write BISECT_EXPECTED_REV via the refdbPatrick Steinhardt, Dec 14, 2023
  40. Junio C HamanoDec 20, 2023
  41. Patrick SteinhardtDec 21, 2023

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.