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

Re: [PATCH 4/8] interpret_branch_name: allow callers to restrict expansions

From
Jeff King <peff@peff.net>
Date
Feb 28, 2017, 21:37 UTC
Message-ID
<20170228213726.3gvwomlpn2ukdcfl@sigill.intra.peff.net>
In-Reply-To
<xmqqr32ijc1q.fsf@gitster.mtv.corp.google.com>
On Tue, Feb 28, 2017 at 12:27:45PM -0800, Junio C Hamano wrote:
Show 16 quoted lines
> Jeff King <peff@peff.net> writes:
> 
> > The original purpose of interpret_branch_name() was to be used by
> > get_sha1() in resolving refs.  As such, some of its expansions may
> > point to refs outside of the local "refs/heads" namespace.
> 
> I am not sure the reference to "get_sha1()" is entirely correct.
> 
> Until it was renamed at 431b1969fc ("Rename interpret/substitute
> nth_last_branch functions", 2009-03-21), the function was called
> interpret_nth_last_branch() which was originally introduced for the
> name, not sha1, at ae5a6c3684 ("checkout: implement "@{-N}" shortcut
> name for N-th last branch", 2009-01-17).  The use of the same syntax
> and function for the object name came a bit later.
> 
> But I think that is an insignificant detail.  Let's read on.

Yeah, sorry, I was lazy about digging up the history. I think the problem actually started in ae0ba8e20a (Teach @{upstream} syntax to strbuf_branchanme(), 2010-01-19), when the features were ported over from get_sha1() to interpret_branch_name().

Since I need to re-roll anyway, I'll tweak this to be more accurate.
Show 13 quoted lines
> > @@ -405,7 +405,7 @@ int refname_match(const char *abbrev_name, const char *full_name)
> >  static char *substitute_branch_name(const char **string, int *len)
> >  {
> >  	struct strbuf buf = STRBUF_INIT;
> > -	int ret = interpret_branch_name(*string, *len, &buf);
> > +	int ret = interpret_branch_name(*string, *len, &buf, 0);
> >  
> >  	if (ret == *len) {
> >  		size_t size;
> 
> This is the one used by dwim_ref/log, so we'd need to allow it to
> resolve to anything, e.g. "@" -> "HEAD", and pretend that the user
> typed that expansion.  OK.

Yeah. Left them all as "0" here, and then split the updates into their own commits. So there's no commit that says "and we are leaving this spot, because it is correct as-is". The other notable one is the strbuf_branchname() call in merge_name().

I can mention those in the commit message here (I think I did in the cover letter, but it would be nice to stick it in the history, since that will be what comes up if you blame those lines).

-Peff
Previous: Junio C HamanoNext: Jeff King
Message 7 of 15 in “Re: [BUG] branch renamed to 'HEAD'”
  1. Jeff KingFeb 28, 2017
  2. 1/8 interpret_branch_name: move docstring to header fileJeff King, Feb 28, 2017
  3. 4/8 interpret_branch_name: allow callers to restrict expansionsJeff King, Feb 28, 2017
  4. Jeff KingFeb 28, 2017
  5. Jeff KingFeb 28, 2017
  6. Junio C HamanoFeb 28, 2017
  7. Jeff KingFeb 28, 2017
  8. 3/8 strbuf_branchname: add docstringJeff King, Feb 28, 2017
  9. 8/8 checkout: restrict @-expansions when finding branchJeff King, Feb 28, 2017
  10. 6/8 branch: restrict @-expansions when deletingJeff King, Feb 28, 2017
  11. 7/8 strbuf_check_ref_format(): expand only local branchesJeff King, Feb 28, 2017
  12. 5/8 t3204: test git-branch @-expansion corner casesJeff King, Feb 28, 2017
  13. 2/8 strbuf_branchname: drop return valueJeff King, Feb 28, 2017
  14. Jacob KellerFeb 28, 2017
  15. Junio C HamanoMar 1, 2017

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.