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

Re: [PATCH/RFC 3/4] git check-ref-format --print

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 12, 2009, 21:06 UTC
Message-ID
<7veip8e302.fsf@alter.siamese.dyndns.org>
In-Reply-To
<20091012143922.GL9261@spearce.org>
"Shawn O. Pearce" <spearce@spearce.org> writes:
Show 18 quoted lines
> Jonathan Nieder <jrnieder@gmail.com> wrote:
>> +valid_ref_normalized 'heads/foo' 'heads/foo'
>> +valid_ref_normalized 'refs///heads/foo' 'refs/heads/foo'
>> +invalid_ref_normalized 'foo'
>> +invalid_ref_normalized 'heads/foo/../bar'
>> +invalid_ref_normalized 'heads/./foo'
>> +invalid_ref_normalized 'heads\foo'
>
> What about '/refs/heads/foo'?  Shouldn't that drop the leading /?
>
> I actually had someone enter that into Gerrit Code Review once,
> exposing a bug I have yet to fix that permits that as a valid
> branch name.  *sigh*
>
> FWIW, I think this is heading in the right direction.  Rather
> than teaching the UIs how clean up a name, give us a tool to
> do the normalization and validation, and let us call it when
> we get user input.

I understand that you prefer the latter between "there is no tool; the caller is responsibile to make sure it feeds us canonical representation" and "there is a tool that makes a slightly malformed string into canonical form for the callers to use before calling us." And that would be my preference between these two as well.

But that is based on the current behaviour of accepting slightly malformed and silently making it canonical. If we throw a third alternative, Jonathan's original patch, that did "we reject malformed string", in the mix, what would be your preference?

I moderately favour the "tool to canonicalize is given, and it would be a bug for the caller not to use it" approach this series takes primarily because that approach won't break scripts that do something like this to make a new branch, optionally grouped by the owner (e.g. 'sp/smart-http' or 'next'):

	owner=$1 topic=$2
	branch=$owner/$topic
        git branch "$branch"

This currently works as expected as long as it does not later try to compare for-each-ref output with "refs/heads/$branch" and expects a match. With the third approach, the optional username grouping becomes mandatory for such a script, as 'git branch' will error out. To keep the grouping still optinal, such a script needs to be written perhaps like:

	if test -z "$2"
        then
		branch="$1"
	else
        	branch="$1/$2"
	fi

and that would be a hassle for the scripters, but this _could_ be a kind of backward incompatible tightening we might want to consider for 1.7.0, as somebody suggested earlier.

But now I have spelled this out, I do not see much upside for rejecting, and more importantly, I think it would be an independent issue. We can reject or just keep normalizing silently, and a tool to show the normalized name would be useful and necessary regardless of that.

Previous: Shawn O. PearceNext: Shawn O. Pearce
Message 12 of 17 in “disallow refs containing successive slashes”
  1. disallow refs containing successive slashesJens Lehmann, Oct 10, 2009
  2. Junio C HamanoOct 10, 2009
  3. Jens LehmannOct 11, 2009
  4. Junio C HamanoOct 11, 2009
  5. Jonathan NiederOct 12, 2009
  6. Nanako ShiraishiOct 12, 2009
  7. 0/4 plumbing to help fix git-guiJonathan Nieder, Oct 12, 2009
  8. 1/4 Add tests for git check-ref-formatJonathan Nieder, Oct 12, 2009
  9. 2/4 Documentation: describe check-ref-format --branchJonathan Nieder, Oct 12, 2009
  10. 3/4 git check-ref-format --printJonathan Nieder, Oct 12, 2009
  11. Shawn O. PearceOct 12, 2009
  12. Junio C HamanoOct 12, 2009
  13. Shawn O. PearceOct 12, 2009
  14. Junio C HamanoOct 12, 2009
  15. Jonathan NiederOct 13, 2009
  16. 4/4 check-ref-format: simplify --print implementationJonathan Nieder, Oct 12, 2009
  17. Jonathan NiederOct 12, 2009

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.