Re: [PATCH v2 0/2] object-name: fix resolution of object names containing curly braces
From: Junio C Hamano <hidden>
Date: 2025-01-04 17:51:58
Elijah Newren [off-list ref] writes:
quoted
In general what would we do if a string can be interpreted in multiple ways in _different_ parts of the object-name codepaths. We all know that "affed" would trigger the "ambiguous object name" error if there are more than one object whose object name begins with "affed", but if "${garbage}-gaffed" can be interpreted as the name of an object whose object name begins with "affed" and also can be interpreted as the name of another object that sits at a path that ends with "-gaffed" in some tree object, regardless of how the leading part "${garbage}" looks like, it would be desirable if we declared such a string as "ambiguous" the same way.How would that be desirable?
In "a:b/c-0-gabcde", *if* "a:b/c-0" *were* a valid way to spell a
valid refname, then the whole thing is an ambiguous object name,
i.e. it could be "something reachable from object 'a:b/c' whose
object name begins with abcde", or it could be "object at the path
b/c-0-gabcde in a tree-ish a", and in such a case our code should be
set up to allow us to give a "that's ambiguous" error, instead of
yielding the first possible interpretation (i.e. if we happen to
have checked the describe name first and "$garbage-0-gabcde", we
yield "abcde" before even checking if $garbage part gives a possible
leading part of a tree-ish; but if a future refactoring of the code
flips the order of checking, we may end up yielding 'an object at a
path, which ends with -0-gabcde, sitting in a tree-ish', without
checking if that could be a valid describe name).
Of course we should make sure that the syntax cannot be ambiguous
when we introduce a new syntax to represent a new feature ;-)
Now, I think ":" has always been a byte that is invalid as a part of
any refname, so "${garbage}-gabcde" with a colon in ${garbage}
cannot be a describe name. So in the above about "a:b/c-0" is an
impossible example, but I was wondering more about the general
principle we should follow.