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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

On Tue, 3 Mar 2009, Junio C Hamano wrote:

> Tor Arne Vestbø <torarnv@xxxxxxxxx> 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

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux