On Wed, Mar 30, 2011 at 18:00, Julius Plenz <[email protected]> wrote: > @@ -105,6 +107,25 @@ static void add_repo(const char *base, const char *path, > repo_config_fn fn) > *p = '\0'; > repo->name = repo->url; > repo->path = xstrdup(path); > + > + fd = open(fmt("%s/HEAD", repo->path), O_RDONLY); > + if (fd != -1) { > + int len; > + memset(buffer, 0, sizeof(buffer)-1); > + len = read_in_full(fd, buffer, sizeof(buffer)-1); > + if(!memcmp(buffer, "ref: refs/heads/", 16)) { > + repo->defbranch = xstrndup(buffer+16, len-17); > + } else if(strlen(buffer) == 41) { /* probably contains a SHA1 > sum */ > + memset(buffer, 0, sizeof(buffer)-1); > + readlink(fmt("%s/HEAD", repo->path), buffer, > sizeof(buffer)-1); > + char *ref_start; > + ref_start = memmem(buffer, sizeof(buffer)-1, > "refs/heads/", 11); > + if(ref_start) > + repo->defbranch = xstrdup(ref_start+11); > + } > + close(fd); > + } > +
Thanks. This seems like a workable solution, but with two issues: * The feature only works for repos added by scan-path * I prefer to declare variables at the start of the function Both issues can thus be solved by a simple refactoring. -- larsh _______________________________________________ cgit mailing list [email protected] http://hjemli.net/mailman/listinfo/cgit
