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

Re: [PATCH v2] git-clone: Add option --branch to override initial branch

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Mar 4, 2009, 08:56 UTC
Message-ID
<alpine.DEB.1.00.0903040953080.8549@intel-tinevez-2-302>
In-Reply-To
<7vbpsh93q5.fsf@gitster.siamese.dyndns.org>
Hi,
On Tue, 3 Mar 2009, Junio C Hamano wrote:
Show 19 quoted lines
> Tor Arne Vestbø <torarnv@gmail.com> writes:
> 
> > +		    if (!prefixcmp(branch, "refs/heads/"))
> > +			branch += offset;
> 
> I suspect that you are trying to protect your code against somebody
> miscounting the length of "refs/heads/" (perhaps when updating this
> codepath in git version 47 that keeps local branches somewhere else, such
> as "refs/local-heads/"), but this "const int offset" does not buy you
> anything.  He will likely to leave "offset" to 11 just the same.
> 
> It is a different story if it were done like this:
> 
> 		static const char heads_prefix[] = "refs/heads/";
>                 if (!prefixcmp(branch, heads_prefix))
>                 	branch += strlen(heads_prefix);
> 
> to let the compiler notice heads_prefix is a constant and optimize the
> strlen() out, but I personally think it is overkill.

Of course you could also do this instead (which I personally think would not be overkill):

		branch = skip_prefix(branch, "refs/heads/");

Ciao, Dscho

Previous: Junio C HamanoNext: Tor Arne Vestbø
Message 12 of 19 in “git-clone: Add option --branch to override initial branch”
  1. git-clone: Add option --branch to override initial branchTor Arne Vestbø, Mar 2, 2009
  2. Johannes SchindelinMar 2, 2009
  3. Junio C HamanoMar 3, 2009
  4. Tor Arne VestbøMar 3, 2009
  5. git-clone: Add option --branch to override initial branchTor Arne Vestbø, Mar 3, 2009
  6. Johannes SchindelinMar 3, 2009
  7. Tor Arne VestbøMar 3, 2009
  8. Junio C HamanoMar 3, 2009
  9. Tor Arne VestbøMar 3, 2009
  10. Junio C HamanoMar 3, 2009
  11. Junio C HamanoMar 4, 2009
  12. Johannes SchindelinMar 4, 2009
  13. Tor Arne VestbøMar 4, 2009
  14. Paolo CiarrocchiMar 9, 2009
  15. Felipe ContrerasMar 9, 2009
  16. Paolo CiarrocchiMar 11, 2009
  17. Miles BaderMar 12, 2009
  18. Paolo CiarrocchiMar 12, 2009
  19. Felipe ContrerasMar 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.