X-Git-Url: https://git.cameronkatri.com/cgit.git/blobdiff_plain/fb3655df3bf85bd405c5921bbd4b3a54c705c839..d31be4ccc2f978edd2a40c2721e1efdc1eee2343:/scan-tree.c diff --git a/scan-tree.c b/scan-tree.c index beb584b..e900ad9 100644 --- a/scan-tree.c +++ b/scan-tree.c @@ -1,7 +1,6 @@ /* scan-tree.c - * - * Copyright (C) 2008-2009 Lars Hjemli - * Copyright (C) 2010, 2012 Jason A. Donenfeld + * + * Copyright (C) 2006-2014 cgit Development Team * * Licensed under GNU General Public License v2 * (see COPYING for full license text) @@ -62,7 +61,7 @@ static int gitconfig_config(const char *key, const char *value, void *cb) config_fn(repo, "desc", value); else if (!strcmp(key, "gitweb.category")) config_fn(repo, "section", value); - else if (!prefixcmp(key, "cgit.")) + else if (starts_with(key, "cgit.")) config_fn(repo, key + 5, value); return 0; @@ -106,13 +105,15 @@ 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); 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; @@ -122,9 +123,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) { @@ -145,28 +149,22 @@ static void add_repo(const char *base, struct strbuf *path, repo_config_fn fn) strbuf_setlen(path, pathlen); } - if (!repo->readme) { - strbuf_addstr(path, "README.html"); - if (!stat(path->buf, &st)) - repo->readme = "README.html"; - strbuf_setlen(path, pathlen); - } if (ctx.cfg.section_from_path) { - n = ctx.cfg.section_from_path; + n = ctx.cfg.section_from_path; if (n > 0) { - slash = rel.buf; - while (slash && n && (slash = strchr(slash, '/'))) + 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, '/'))) + while (slash && n && (slash = xstrrchr(rel.buf, slash - 1, '/'))) n++; } if (slash && !n) { *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++; @@ -234,8 +232,6 @@ end: closedir(dir); } -#define lastc(s) s[strlen(s) - 1] - void scan_projects(const char *path, const char *projectsfile, repo_config_fn fn) { struct strbuf line = STRBUF_INIT;