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, 12:33 UTC
Message-ID
<20170228123331.wubqplp5zjwzz6is@sigill.intra.peff.net>
In-Reply-To
<20170228122338.xkefanyhtwbomoit@sigill.intra.peff.net>
On Tue, Feb 28, 2017 at 07:23:38AM -0500, Jeff King wrote:
Show 26 quoted lines
> > -int interpret_branch_name(const char *name, int namelen, struct strbuf *buf)
> > +int interpret_branch_name(const char *name, int namelen, struct strbuf *buf,
> > +			  unsigned allowed)
> >  {
> >  	char *at;
> >  	const char *start;
> > @@ -1254,24 +1275,29 @@ int interpret_branch_name(const char *name, int namelen, struct strbuf *buf)
> >  		if (len == namelen)
> >  			return len; /* consumed all */
> >  		else
> > -			return reinterpret(name, namelen, len, buf);
> > +			return reinterpret(name, namelen, len, buf, allowed);
> >  	}
> 
> It's hard to see from this context, but a careful reader may note that
> we do not check "allowed" at all before calling
> interpret_nth_prior_checkout(). This is looking for branch names via
> HEAD, so I don't think it can ever return anything but a local name.
> 
> Which, hmm. I guess was valid when the flag was "only_branches", but
> would not be valid under INTERPRET_BRANCH_REMOTE. I wonder if
> 
>   git branch -r -D @{-1}
> 
> incorrectly deletes refs/remotes/origin/master if you previously had
> refs/heads/origin/master checked out.

The answer is "yes", it's broken. So interpret_branch_name() should do an "allowed" check before expanding the nth-prior. The fix should be easy, especially on top of the earlier 426f76595 (which, incidentally, I already based this series on).

I'll hold off on re-rolling to see if it collects any other review.
-Peff
Previous: Jeff KingNext: Junio C Hamano
Message 5 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.