X-Git-Url: https://git.cameronkatri.com/cgit.git/blobdiff_plain/9a725f4f0991710336584bb284a83dcf5fa5bf1e..0899eb644fab415e9a3b304f53da9da50aaf91aa:/scan-tree.c?ds=sidebyside diff --git a/scan-tree.c b/scan-tree.c index a1ec8fb..6a2f65a 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) @@ -11,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) @@ -46,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; } @@ -106,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); @@ -124,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) { @@ -147,28 +154,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++; @@ -178,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); } @@ -236,8 +237,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; @@ -250,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);