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

Re: [PATCH 00/12] show-ref: introduce mode to check for ref existence

From
Patrick Steinhardt <ps@pks.im>
Date
Oct 26, 2023, 09:44 UTC
Message-ID
<ZTo1Af8JKaovhJtk@tanuki>
In-Reply-To
<CAFQ2z_PqNsz+zycSxz=q2cUVOpJS-AEjwHxEM-fiafxd3dxc9g@mail.gmail.com>
On Wed, Oct 25, 2023 at 04:26:35PM +0200, Han-Wen Nienhuys wrote:
Show 21 quoted lines
> On Tue, Oct 24, 2023 at 9:17 PM Junio C Hamano <gitster@pobox.com> wrote:
> >
> > Patrick Steinhardt <ps@pks.im> writes:
> >
> > > this patch series introduces a new `--exists` mode to git-show-ref(1) to
> > > explicitly check for the existence of a reference, only.
> >
> > I agree that show-ref would be the best place for this feature (not
> > rev-parse, which is already a kitchen sink).  After all, the command
> > was designed for validating refs in 358ddb62 (Add "git show-ref"
> > builtin command, 2006-09-15).
> >
> > Thanks.  Hopefully I can take a look before I go offline.
> 
> The series description doesn't say why users would care about this.
> 
> If this is just to ease testing, I suggest adding functionality to a
> suitable test helper. Anything you add to git-show-ref is a publicly
> visible API that needs documentation and comes with a stability
> guarantee that is more expensive to maintain than test helper
> functionality.

The first patch of the original patch series where I split this out from did exactly that, see [1]. Junio questioned though whether this should be part of production code instead of being a test helper.

And I tend to agree with him, or otherwise I wouldn't have written this series. It's actually a bit surprising that we do not have any way to test for reference existence in any of our helpers in a generic way. All current tooling that I'm aware of is lacking in some ways:

    - git-rev-parse(1) will fail to parse symbolic refs whose target
      does not exist.
    - git-symbolic-ref(1) can look up such unborn branches, but the
      caller needs to be aware that 
    - git-show-ref(1) tries to resolve symbolic references.
    - git-for-each-ref(1) is simply not an obvious way to check for ref
      existence.
    - All of these will fail to parse references with malformed names.

So the new `git show-ref --exists` mode is a trivial-to-use and generic way to simply ask "Do you know this reference?". The lack of this option likely shows that you can most often get away without such a tool, but I still find it funny that there is no obvious way to perform this query right now.

At the Contributor's Summit, we've also discussed the issue that our plumbing layer has become less useful over the years. It is often missing functionality that exists in user-facing commands. It also has inherited many of the restrictions of our porcelain tools, like not being able to look up references with bad names. So this series is a small step into the direction of making our plumbing more useful again.

I also assume that it's only going to become more important to address these limitations in our plumbing layer once we have something like the reftable backend. A user or admin would have been able to fix issues with misformatted referencen names rather easily in the reffiles backend even without support in our plumbing layer, as it mostly was a single "rm .git/refs/$broken_ref" away. But that's not going to be an easy solution anymore with reftable due to the complexity of its format. So I also see it as part of the upcoming preparatory work to make sure that they have all the necessary tools to address such situations, at least up to a reasonable point.

Patrick
[1]: <e947feb1c77f7e9f3c7f983bbe47137fbce42367.1697607222.git.ps@pks.im>
Previous: Phillip WoodNext: Patrick Steinhardt
Message 28 of 66 in “show-ref: introduce mode to check for ref existence”
  1. 00/12 show-ref: introduce mode to check for ref existencePatrick Steinhardt, Oct 24, 2023
  2. 01/12 builtin/show-ref: convert pattern to a local variablePatrick Steinhardt, Oct 24, 2023
  3. 02/12 builtin/show-ref: split up different subcommandsPatrick Steinhardt, Oct 24, 2023
  4. Eric SunshineOct 24, 2023
  5. 03/12 builtin/show-ref: fix leaking string bufferPatrick Steinhardt, Oct 24, 2023
  6. 04/12 builtin/show-ref: fix dead code when passing patternsPatrick Steinhardt, Oct 24, 2023
  7. Eric SunshineOct 24, 2023
  8. 05/12 builtin/show-ref: refactor `--exclude-existing` optionsPatrick Steinhardt, Oct 24, 2023
  9. Eric SunshineOct 24, 2023
  10. Patrick SteinhardtOct 25, 2023
  11. 06/12 builtin/show-ref: stop using global variable to count matchesPatrick Steinhardt, Oct 24, 2023
  12. 07/12 builtin/show-ref: stop using global vars for `show_one()`Patrick Steinhardt, Oct 24, 2023
  13. 08/12 builtin/show-ref: refactor options for patterns subcommandPatrick Steinhardt, Oct 24, 2023
  14. 09/12 builtin/show-ref: ensure mutual exclusiveness of subcommandsPatrick Steinhardt, Oct 24, 2023
  15. Eric SunshineOct 24, 2023
  16. 10/12 builtin/show-ref: explicitly spell out different modes in synopsisPatrick Steinhardt, Oct 24, 2023
  17. Eric SunshineOct 24, 2023
  18. Patrick SteinhardtOct 25, 2023
  19. 11/12 builtin/show-ref: add new mode to check for reference existencePatrick Steinhardt, Oct 24, 2023
  20. Eric SunshineOct 24, 2023
  21. Patrick SteinhardtOct 25, 2023
  22. 12/12 t: use git-show-ref(1) to check for ref existencePatrick Steinhardt, Oct 24, 2023
  23. Junio C HamanoOct 24, 2023
  24. Han-Wen NienhuysOct 25, 2023
  25. Phillip WoodOct 25, 2023
  26. Patrick SteinhardtOct 26, 2023
  27. Phillip WoodOct 27, 2023
  28. Patrick SteinhardtOct 26, 2023
  29. 00/12 show-ref: introduce mode to check for ref existencePatrick Steinhardt, Oct 26, 2023
  30. 01/12 builtin/show-ref: convert pattern to a local variablePatrick Steinhardt, Oct 26, 2023
  31. 02/12 builtin/show-ref: split up different subcommandsPatrick Steinhardt, Oct 26, 2023
  32. 03/12 builtin/show-ref: fix leaking string bufferPatrick Steinhardt, Oct 26, 2023
  33. Taylor BlauOct 30, 2023
  34. 04/12 builtin/show-ref: fix dead code when passing patternsPatrick Steinhardt, Oct 26, 2023
  35. Taylor BlauOct 30, 2023
  36. 05/12 builtin/show-ref: refactor `--exclude-existing` optionsPatrick Steinhardt, Oct 26, 2023
  37. Taylor BlauOct 30, 2023
  38. Patrick SteinhardtOct 31, 2023
  39. Taylor BlauOct 30, 2023
  40. Patrick SteinhardtOct 31, 2023
  41. 06/12 builtin/show-ref: stop using global variable to count matchesPatrick Steinhardt, Oct 26, 2023
  42. Taylor BlauOct 30, 2023
  43. 07/12 builtin/show-ref: stop using global vars for `show_one()`Patrick Steinhardt, Oct 26, 2023
  44. 08/12 builtin/show-ref: refactor options for patterns subcommandPatrick Steinhardt, Oct 26, 2023
  45. 09/12 builtin/show-ref: ensure mutual exclusiveness of subcommandsPatrick Steinhardt, Oct 26, 2023
  46. Taylor BlauOct 30, 2023
  47. Patrick SteinhardtOct 31, 2023
  48. 10/12 builtin/show-ref: explicitly spell out different modes in synopsisPatrick Steinhardt, Oct 26, 2023
  49. 11/12 builtin/show-ref: add new mode to check for reference existencePatrick Steinhardt, Oct 26, 2023
  50. 12/12 t: use git-show-ref(1) to check for ref existencePatrick Steinhardt, Oct 26, 2023
  51. Taylor BlauOct 30, 2023
  52. Junio C HamanoOct 31, 2023
  53. 00/12 builtin/show-ref: introduce mode to check for ref existencePatrick Steinhardt, Oct 31, 2023
  54. 01/12 builtin/show-ref: convert pattern to a local variablePatrick Steinhardt, Oct 31, 2023
  55. 02/12 builtin/show-ref: split up different subcommandsPatrick Steinhardt, Oct 31, 2023
  56. 03/12 builtin/show-ref: fix leaking string bufferPatrick Steinhardt, Oct 31, 2023
  57. 04/12 builtin/show-ref: fix dead code when passing patternsPatrick Steinhardt, Oct 31, 2023
  58. 05/12 builtin/show-ref: refactor `--exclude-existing` optionsPatrick Steinhardt, Oct 31, 2023
  59. 06/12 builtin/show-ref: stop using global variable to count matchesPatrick Steinhardt, Oct 31, 2023
  60. 07/12 builtin/show-ref: stop using global vars for `show_one()`Patrick Steinhardt, Oct 31, 2023
  61. 08/12 builtin/show-ref: refactor options for patterns subcommandPatrick Steinhardt, Oct 31, 2023
  62. 09/12 builtin/show-ref: ensure mutual exclusiveness of subcommandsPatrick Steinhardt, Oct 31, 2023
  63. 10/12 builtin/show-ref: explicitly spell out different modes in synopsisPatrick Steinhardt, Oct 31, 2023
  64. 11/12 builtin/show-ref: add new mode to check for reference existencePatrick Steinhardt, Oct 31, 2023
  65. 12/12 t: use git-show-ref(1) to check for ref existencePatrick Steinhardt, Oct 31, 2023
  66. Taylor BlauOct 31, 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.