aboutsummaryrefslogtreecommitdiff
path: root/scan-tree.c
diff refs
from:
to:
flip
diff options
context:
space:
mode:
Diffstat (limited to 'scan-tree.c')
-rw-r--r--scan-tree.c69
1 files changed, 38 insertions, 31 deletions
diff --git a/scan-tree.c b/scan-tree.c
index 49de658..c120efe 100644
--- a/scan-tree.c
+++ b/scan-tree.c
@@ -10,6 +10,7 @@
#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)
@@ -45,24 +46,28 @@ out:
return result;
}
-struct cgit_repo *repo;
-repo_config_fn config_fn;
+static struct cgit_repo *repo;
-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);
+ cgit_repo_config(repo, name, value);
}
-static int gitconfig_config(const char *key, const char *value, void *cb)
+static int gitconfig_config(const char *key, const char *value,
+ const __attribute__((unused)) struct config_context *ctx, void *cb)
{
+ const char *name;
+
if (!strcmp(key, "gitweb.owner"))
- config_fn(repo, "owner", value);
+ cgit_repo_config(repo, "owner", value);
else if (!strcmp(key, "gitweb.description"))
- config_fn(repo, "desc", value);
+ cgit_repo_config(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);
+ cgit_repo_config(repo, "section", value);
+ else if (!strcmp(key, "gitweb.homepage"))
+ cgit_repo_config(repo, "homepage", value);
+ else if (skip_prefix(key, "cgit.", &name))
+ cgit_repo_config(repo, name, value);
return 0;
}
@@ -74,7 +79,7 @@ static char *xstrrchr(char *s, char *from, int c)
return from < s ? NULL : from;
}
-static void add_repo(const char *base, struct strbuf *path, repo_config_fn fn)
+static void add_repo(const char *base, struct strbuf *path)
{
struct stat st;
struct passwd *pwd;
@@ -105,7 +110,7 @@ static void add_repo(const char *base, struct strbuf *path, repo_config_fn fn)
return;
strbuf_setlen(path, pathlen);
- if (prefixcmp(path->buf, base))
+ if (!starts_with(path->buf, base))
strbuf_addbuf(&rel, path);
else
strbuf_addstr(&rel, path->buf + strlen(base) + 1);
@@ -116,17 +121,19 @@ static void add_repo(const char *base, struct strbuf *path, repo_config_fn fn)
strbuf_setlen(&rel, rel.len - 1);
repo = cgit_add_repo(rel.buf);
- config_fn = fn;
if (ctx.cfg.enable_git_config) {
strbuf_addstr(path, "config");
git_config_from_file(gitconfig_config, path->buf, NULL);
strbuf_setlen(path, pathlen);
}
- if (ctx.cfg.remove_suffix)
- if ((p = strrchr(repo->url, '.')) && !strcmp(p, ".git"))
- *p = '\0';
- repo->path = xstrdup(path->buf);
+ 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 = strdup_first_line(path->buf);
while (!repo->owner) {
if ((pwd = getpwuid(st.st_uid)) == NULL) {
fprintf(stderr, "Error reading owner-info for %s: %s (%d)\n",
@@ -136,13 +143,13 @@ static void add_repo(const char *base, struct strbuf *path, repo_config_fn fn)
if (pwd->pw_gecos)
if ((p = strchr(pwd->pw_gecos, ',')))
*p = '\0';
- repo->owner = xstrdup(pwd->pw_gecos ? pwd->pw_gecos : pwd->pw_name);
+ repo->owner = strdup_first_line(pwd->pw_gecos ? pwd->pw_gecos : pwd->pw_name);
}
if (repo->desc == cgit_default_repo_desc || !repo->desc) {
strbuf_addstr(path, "description");
if (!stat(path->buf, &st))
- readfile(path->buf, &repo->desc, &size);
+ read_first_line(path->buf, &repo->desc, &size);
strbuf_setlen(path, pathlen);
}
@@ -159,9 +166,9 @@ static void add_repo(const char *base, struct strbuf *path, repo_config_fn fn)
}
if (slash && !n) {
*slash = '\0';
- repo->section = xstrdup(rel.buf);
+ repo->section = strdup_first_line(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,12 +178,12 @@ 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);
}
-static void scan_path(const char *base, const char *path, repo_config_fn fn)
+static void scan_path(const char *base, const char *path)
{
DIR *dir = opendir(path);
struct dirent *ent;
@@ -192,12 +199,12 @@ 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)) {
- add_repo(base, &pathbuf, fn);
+ add_repo(base, &pathbuf);
goto end;
}
strbuf_addstr(&pathbuf, "/.git");
if (is_git_dir(pathbuf.buf)) {
- add_repo(base, &pathbuf, fn);
+ add_repo(base, &pathbuf);
goto end;
}
/*
@@ -222,14 +229,14 @@ static void scan_path(const char *base, const char *path, repo_config_fn fn)
continue;
}
if (S_ISDIR(st.st_mode))
- scan_path(base, pathbuf.buf, fn);
+ scan_path(base, pathbuf.buf);
}
end:
strbuf_release(&pathbuf);
closedir(dir);
}
-void scan_projects(const char *path, const char *projectsfile, repo_config_fn fn)
+void scan_projects(const char *path, const char *projectsfile)
{
struct strbuf line = STRBUF_INIT;
FILE *projects;
@@ -241,12 +248,12 @@ 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);
strbuf_insert(&line, 0, path, strlen(path));
- scan_path(path, line.buf, fn);
+ scan_path(path, line.buf);
}
if ((err = ferror(projects))) {
fprintf(stderr, "Error reading from projectsfile %s: %s (%d)\n",
@@ -256,7 +263,7 @@ void scan_projects(const char *path, const char *projectsfile, repo_config_fn fn
strbuf_release(&line);
}
-void scan_tree(const char *path, repo_config_fn fn)
+void scan_tree(const char *path)
{
- scan_path(path, path, fn);
+ scan_path(path, path);
}