[PATCH 1/5] guess default branch from HEAD

Lars Hjemli hjemli at gmail.com
Sat Mar 26 11:08:46 CET 2011


On Wed, Mar 16, 2011 at 11:53, Julius Plenz <plenz at cis.fu-berlin.de> wrote:
> Hi, Lars!
>
> * Lars Hjemli <hjemli at gmail.com> [2011-03-10 18:24]:
>> On Thu, Mar 10, 2011 at 17:03, Julius Plenz <plenz at cis.fu-berlin.de> wrote:
>> > This is a saner alternative than hardcoding the default branch to be
>> > "master". The add_repo() function will now check for a symbolic ref in
>> > repo_path/HEAD. If there is a suitable one, overwrite repo->defbranch
>> > with it.
>>
>> I agree with the motivation, but...
>
>> > +        fd = open(fmt("%s/HEAD", repo->path), O_RDONLY);
>
>> ...since git supports fs links, you'll need to lstat() and then
>> either readlink() or read_in_full(). And if you readlink(), you'll
>> obviously need to parse the result differently.
>
> I just tried this out:
>
>    $ cd /repositories/...
>    $ mv HEAD head
>    $ ln -s head HEAD
>
> The patch handles that just fine (it wouldn't if I were to add the
> O_NOFOLLOW flag);

Yeah, but try this instead:

$ cd $repo/.git
$ mv HEAD HEAD.old
$ ln -s refs/heads/master HEAD

This is what git supports, and the patch needs to readlink() to handle the same.

--
larsh




More information about the CGit mailing list