/* scan-tree.c
- *
- * Copyright (C) 2008-2009 Lars Hjemli
- * Copyright (C) 2010-2013 Jason A. Donenfeld <Jason@zx2c4.com>
+ *
+ * Copyright (C) 2006-2014 cgit Development Team <cgit@lists.zx2c4.com>
*
* Licensed under GNU General Public License v2
* (see COPYING for full license text)
#include "scan-tree.h"
#include "configfile.h"
#include "html.h"
+#include <config.h>
/* return 1 if path contains a objects/ directory and a HEAD file */
static int is_git_dir(const char *path)
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;
}
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);
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) {
*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++;
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);
}
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;
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);