- p = fmt("%s", path + strlen(base) + 1);
-
- if (!strcmp(p + strlen(p) - 5, "/.git"))
- p[strlen(p) - 5] = '\0';
-
- repo = cgit_add_repo(xstrdup(p));
- repo->name = repo->url;
- repo->path = xstrdup(path);
- p = (pwd && pwd->pw_gecos) ? strchr(pwd->pw_gecos, ',') : NULL;
- if (p)
- *p = '\0';
- repo->owner = (pwd ? xstrdup(pwd->pw_gecos ? pwd->pw_gecos : pwd->pw_name) : "");
-
- p = fmt("%s/description", path);
- if (!stat(p, &st))
- readfile(p, &repo->desc, &size);
-
- p = fmt("%s/README.html", path);
- if (!stat(p, &st))
- repo->readme = "README.html";
+ strbuf_addstr(&rel, path->buf + strlen(base) + 1);
+
+ if (!strcmp(rel.buf + rel.len - 5, "/.git"))
+ strbuf_setlen(&rel, rel.len - 5);
+ else if (rel.len && rel.buf[rel.len - 1] == '/')
+ strbuf_setlen(&rel, rel.len - 1);
+
+ repo = cgit_add_repo(rel.buf);
+ config_fn = fn;
+ if (ctx.cfg.enable_git_config) {
+ strbuf_addstr(path, "config");
+ git_config_from_file(gitconfig_config, path->buf, NULL);
+ strbuf_setlen(path, pathlen);
+ }
+
+ if (ctx.cfg.remove_suffix) {
+ size_t urllen;
+ strip_suffix(repo->url, ".git", &urllen);
+ strip_suffix_mem(repo->url, &urllen, "/");
+ repo->url[urllen] = '\0';
+ }
+ repo->path = xstrdup(path->buf);
+ while (!repo->owner) {
+ if ((pwd = getpwuid(st.st_uid)) == NULL) {
+ fprintf(stderr, "Error reading owner-info for %s: %s (%d)\n",
+ path->buf, strerror(errno), errno);
+ break;
+ }
+ if (pwd->pw_gecos)
+ if ((p = strchr(pwd->pw_gecos, ',')))
+ *p = '\0';
+ repo->owner = xstrdup(pwd->pw_gecos ? pwd->pw_gecos : pwd->pw_name);
+ }
+
+ if (repo->desc == cgit_default_repo_desc || !repo->desc) {
+ strbuf_addstr(path, "description");
+ if (!stat(path->buf, &st))
+ readfile(path->buf, &repo->desc, &size);
+ strbuf_setlen(path, pathlen);
+ }
+
+ if (ctx.cfg.section_from_path) {
+ n = ctx.cfg.section_from_path;
+ if (n > 0) {
+ slash = rel.buf - 1;
+ while (slash && n && (slash = strchr(slash + 1, '/')))
+ n--;
+ } else {
+ slash = rel.buf + rel.len;
+ while (slash && n && (slash = xstrrchr(rel.buf, slash - 1, '/')))
+ n++;
+ }
+ if (slash && !n) {
+ *slash = '\0';
+ repo->section = xstrdup(rel.buf);
+ *slash = '/';
+ if (starts_with(repo->name, repo->section)) {
+ repo->name += strlen(repo->section);
+ if (*repo->name == '/')
+ repo->name++;
+ }
+ }
+ }
+
+ strbuf_addstr(path, "cgitrc");
+ if (!stat(path->buf, &st))
+ parse_configfile(path->buf, &scan_tree_repo_config);
+
+ strbuf_release(&rel);