X-Git-Url: https://git.cameronkatri.com/cgit.git/blobdiff_plain/79c985e13c10b498c3ea62f4607c2e2a460c3b10..32c27e887732298da1724c0740004925fcadae39:/scan-tree.c?ds=sidebyside diff --git a/scan-tree.c b/scan-tree.c index 87fa0c7..08f3f1d 100644 --- a/scan-tree.c +++ b/scan-tree.c @@ -45,8 +45,8 @@ out: return result; } -struct cgit_repo *repo; -repo_config_fn config_fn; +static struct cgit_repo *repo; +static repo_config_fn config_fn; static void repo_config(const char *name, const char *value) { @@ -55,14 +55,18 @@ static void repo_config(const char *name, const char *value) static int gitconfig_config(const char *key, const char *value, void *cb) { + const char *name; + if (!strcmp(key, "gitweb.owner")) config_fn(repo, "owner", value); else if (!strcmp(key, "gitweb.description")) config_fn(repo, "desc", value); else if (!strcmp(key, "gitweb.category")) config_fn(repo, "section", value); - else if (starts_with(key, "cgit.")) - config_fn(repo, key + 5, value); + else if (!strcmp(key, "gitweb.homepage")) + config_fn(repo, "homepage", value); + else if (skip_prefix(key, "cgit.", &name)) + config_fn(repo, name, value); return 0; } @@ -115,7 +119,6 @@ static void add_repo(const char *base, struct strbuf *path, repo_config_fn fn) else if (rel.len && rel.buf[rel.len - 1] == '/') strbuf_setlen(&rel, rel.len - 1); - fprintf(stderr, "add_repo(): %s\n", rel.buf); repo = cgit_add_repo(rel.buf); config_fn = fn; if (ctx.cfg.enable_git_config) { @@ -124,9 +127,12 @@ static void add_repo(const char *base, struct strbuf *path, repo_config_fn fn) strbuf_setlen(path, pathlen); } - if (ctx.cfg.remove_suffix) - if ((p = strrchr(repo->url, '.')) && !strcmp(p, ".git")) - *p = '\0'; + 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) { @@ -162,7 +168,6 @@ static void add_repo(const char *base, struct strbuf *path, repo_config_fn fn) *slash = '\0'; repo->section = xstrdup(rel.buf); *slash = '/'; - fprintf(stderr, "repo->name %s, repo->section %s\n", repo->name, repo->section); if (starts_with(repo->name, repo->section)) { repo->name += strlen(repo->section); if (*repo->name == '/') @@ -173,7 +178,7 @@ static void add_repo(const char *base, struct strbuf *path, repo_config_fn fn) strbuf_addstr(path, "cgitrc"); if (!stat(path->buf, &st)) - parse_configfile(xstrdup(path->buf), &repo_config); + parse_configfile(path->buf, &repo_config); strbuf_release(&rel); } @@ -186,7 +191,6 @@ static void scan_path(const char *base, const char *path, repo_config_fn fn) size_t pathlen = strlen(path); struct stat st; - fprintf(stderr, "scan_path(): %s\n", path); if (!dir) { fprintf(stderr, "Error opening directory %s: %s (%d)\n", path, strerror(errno), errno); @@ -195,7 +199,6 @@ static void scan_path(const char *base, const char *path, repo_config_fn fn) strbuf_add(&pathbuf, path, strlen(path)); if (is_git_dir(pathbuf.buf)) { - fprintf(stderr, "scan_path() is_git_dir: %s\n", path); add_repo(base, &pathbuf, fn); goto end; } @@ -245,7 +248,7 @@ void scan_projects(const char *path, const char *projectsfile, repo_config_fn fn projectsfile, strerror(errno), errno); return; } - while (strbuf_getline(&line, projects, '\n') != EOF) { + while (strbuf_getline(&line, projects) != EOF) { if (!line.len) continue; strbuf_insert(&line, 0, "/", 1);