X-Git-Url: https://git.cameronkatri.com/cgit.git/blobdiff_plain/f7f26f88755ac6a3b9af4918b51b0d6e7a692c78..9086260329a88594474a30e0c2f6e44ae0c149ab:/scan-tree.c diff --git a/scan-tree.c b/scan-tree.c index 1a2ea87..6a2f65a 100644 --- a/scan-tree.c +++ b/scan-tree.c @@ -10,6 +10,7 @@ #include "scan-tree.h" #include "configfile.h" #include "html.h" +#include /* return 1 if path contains a objects/ directory and a HEAD file */ static int is_git_dir(const char *path) @@ -45,24 +46,28 @@ 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) +static void scan_tree_repo_config(const char *name, const char *value) { config_fn(repo, name, 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 (!prefixcmp(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; } @@ -105,7 +110,7 @@ static void add_repo(const char *base, struct strbuf *path, repo_config_fn fn) return; strbuf_setlen(path, pathlen); - if (strncmp(base, path->buf, strlen(base))) + if (!starts_with(path->buf, base)) strbuf_addbuf(&rel, path); else strbuf_addstr(&rel, path->buf + strlen(base) + 1); @@ -123,9 +128,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) { @@ -161,7 +169,7 @@ static void add_repo(const char *base, struct strbuf *path, repo_config_fn fn) *slash = '\0'; repo->section = xstrdup(rel.buf); *slash = '/'; - if (!prefixcmp(repo->name, repo->section)) { + if (starts_with(repo->name, repo->section)) { repo->name += strlen(repo->section); if (*repo->name == '/') repo->name++; @@ -171,7 +179,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, &scan_tree_repo_config); strbuf_release(&rel); } @@ -241,7 +249,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);