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

Re: [PATCH v2 1/2] object-name: fix resolution of object names containing curly braces

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 5, 2025, 16:14 UTC
Message-ID
<xmqqmsg52q7l.fsf@gitster.g>
In-Reply-To
<13f68bebe90549ba19452f12abb6fea41c2517fb.1735949870.git.gitgitgadget@gmail.com>
"Elijah Newren via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 12 quoted lines
> Given a branch name of 'foo{bar', commands like
>
>     git cat-file -p foo{bar:README.md
>
> should succeed (assuming that branch had a README.md file, of course).
> However, the change in cce91a2caef9 (Change 'master@noon' syntax to
> 'master@{noon}'., 2006-05-19) presumed that curly braces would always
> come after an '@' or '^' and be paired, causing e.g. 'foo{bar:README.md'
> to entirely miss the ':' and assume there's no object being referenced.
> In short, git would report:
>
>     fatal: Not a valid object name foo{bar:README.md

Naïvely, it seems that a solution is to parse from left to right, i.e., (1) notice there is a colon, (2) see if everything before that colon resolves to a treeish, and (3) see if everything after it is a path that appears in the treeish.

 - When we are given foo@{some:thing}, if we did that, we realize
   that "foo@{some" is not a valid tree-ish object name (since "@{"
   cannot appear in a refname) and then can backtrack by realizing
   "foo" is a ref, and @{...} could be a reflog reference (most
   likely a way to spell some sort of timestamp), and try that.
 - Similarly, for foo:path-gaffed, we would notice "foo" is a valid
   tree-ish object name, and if path-gaffed is a path in it, we'd be
   happy.  Or foo may not be a tree-ish, or path-gaffed may not
   exist in that tree-ish.  In which case, we can backtrack and see
   foo:path-g is an allowed prefix in a desribe name.

Now in the above description, I have assumed that an alternative interpretation kicks in only as a fallback when we backtrack, but we could make sure we try all possibilities and notice ambiguity if we wanted to.

In any case, such an updated structure of the parsing code paths (whether alternative interpretations are treated as fallbacks or equally plausible candidates subject to disambiguation) would be a vast departure from what we currently have, so a targeted "fix" like these two patches attempt would be more appropriate as an initial approach, I think.

Thanks, will queue, but probably we'd look at in any seriousness after the 2.48 final gets tagged.

Previous: Elijah NewrenNext: Elijah Newren via GitGitGadget
Message 12 of 25 in “object-name: fix resolution of object names containing curly braces”
  1. object-name: fix resolution of object names containing curly bracesElijah Newren via GitGitGadget, Jan 1, 2025
  2. Junio C HamanoJan 1, 2025
  3. Elijah NewrenJan 3, 2025
  4. Junio C HamanoJan 4, 2025
  5. Patrick SteinhardtJan 3, 2025
  6. Junio C HamanoJan 3, 2025
  7. Elijah NewrenJan 3, 2025
  8. 0/2 object-name: fix resolution of object names containing curly bracesElijah Newren via GitGitGadget, Jan 4, 2025
  9. 1/2 object-name: fix resolution of object names containing curly bracesElijah Newren via GitGitGadget, Jan 4, 2025
  10. Junio C HamanoJan 4, 2025
  11. Elijah NewrenJan 4, 2025
  12. Junio C HamanoJan 5, 2025
  13. 2/2 object-name: be more strict in parsing describe-like outputElijah Newren via GitGitGadget, Jan 4, 2025
  14. Junio C HamanoJan 4, 2025
  15. Elijah NewrenJan 4, 2025
  16. Junio C HamanoJan 4, 2025
  17. Elijah NewrenJan 4, 2025
  18. Junio C HamanoJan 6, 2025
  19. Elijah NewrenJan 6, 2025
  20. Junio C HamanoJan 6, 2025
  21. 0/2 object-name: fix a pair of object name resolution issuesElijah Newren via GitGitGadget, Jan 13, 2025
  22. 1/2 object-name: fix resolution of object names containing curly bracesElijah Newren via GitGitGadget, Jan 13, 2025
  23. 2/2 object-name: be more strict in parsing describe-like outputElijah Newren via GitGitGadget, Jan 13, 2025
  24. Junio C HamanoJan 13, 2025
  25. Elijah NewrenJan 13, 2025

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.