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

Re: Buggy handling of non-canonical ref names

From
Michael Haggerty <mhagger@alum.mit.edu>
Date
Aug 25, 2011, 07:54 UTC
Message-ID
<4E55FFAA.9030904@alum.mit.edu>
In-Reply-To
<7vaaayo369.fsf@alter.siamese.dyndns.org>
On 08/25/2011 12:27 AM, Junio C Hamano wrote:
Show 22 quoted lines
> Junio C Hamano <gitster@pobox.com> writes:
>> Michael Haggerty <mhagger@alum.mit.edu> writes:
>>> What is the policy about reference names and their canonicalization?
>>
>> The overall policy has been that we care about well-formed input, and
>> everything else is "undefined", even though as you found out some of them
>> try to work sensibly.
>>
>>>     $ git check-ref-format /foo/bar ; echo $?
>>>     0
>>>
>>>     $ git check-ref-format --print /foo/bar
>>>     /foo/bar
>>
>> I think these are bogus. Patches welcome.
> 
> I actually think the former is correct and the latter should strip the
> leading slash. Essentially what "check-ref-format" (and the underlying
> check_ref_format() function) validates is if the given user string can be
> used under $GIT_DIR/refs/ to name a ref, and $GIT_DIR/refs//foo/bar is
> (because we "tolerate duplicated slashes" cf. comment in the function) the
> same as $GIT_DIR/refs/foo/bar and is allowed.

I can live with either way, but I should point out that such an extra slash can be problematic when used naively in conjunction with Python's standard glue-together-pathname function, os.path.join() [1]:

    $ python
    >>> import os
    >>> os.path.join('.git', '/foo/bar')
    '/foo/bar'
    >>>
Maybe there are other examples of libraries with these semantics.
Show 9 quoted lines
> I think what is missing is a unified way to canonicalize the refnames
> (which led to the inconsistencies you observed), and I strongly suspect
> that check_ref_format() should learn to return the canonicalized format
> (if asked by the caller) and the caller should use the canonicalized
> version after feeding end-user input to it.
> 
> Then the plumbing "check-ref-format --print" can use it just like any
> other caller that should be (or already are) using check_ref_format()
> to validate the end-user input.

Indeed, regardless of the policy about leading slashes, this is a good plan. I will try to find time to work on it.

> Yes, such a change will update the overall policy I stated earlier and
> narrow the scope of "undefined" down a bit, by uniformly codifying that
> leading and duplicate slashes are removed to be nice to the user.
Michael
[1] http://docs.python.org/library/os.path.html#os.path.join
-- 
Michael Haggerty
mhagger@alum.mit.edu
http://softwareswirl.blogspot.com/
Previous: Junio C HamanoNext: Michael Haggerty
Message 5 of 10 in “Buggy handling of non-canonical ref names”
  1. Michael HaggertyAug 24, 2011
  2. Junio C HamanoAug 24, 2011
  3. Carlos Martín NietoAug 24, 2011
  4. Junio C HamanoAug 24, 2011
  5. Michael HaggertyAug 25, 2011
  6. Do not allow refnames to start with a slashMichael Haggerty, Aug 25, 2011
  7. Junio C HamanoAug 25, 2011
  8. check-ref-format --print: Normalize refnames that start with slashesMichael Haggerty, Aug 25, 2011
  9. Junio C HamanoAug 25, 2011
  10. Michael HaggertyAug 25, 2011

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.