Diffstat (limited to 'scan-tree.c')
| -rw-r--r-- | scan-tree.c | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/scan-tree.c b/scan-tree.c index 867fcf7..8858b74 100644 --- a/scan-tree.c +++ b/scan-tree.c @@ -47,10 +47,11 @@ out: } static struct cgit_repo *repo; +static repo_config_fn config_fn; static void scan_tree_repo_config(const char *name, const char *value) { - cgit_repo_config(repo, name, value); + config_fn(repo, name, value); } static int gitconfig_config(const char *key, const char *value, @@ -59,15 +60,15 @@ static int gitconfig_config(const char *key, const char *value, const char *name; if (!strcmp(key, "gitweb.owner")) - cgit_repo_config(repo, "owner", value); + config_fn(repo, "owner", value); else if (!strcmp(key, "gitweb.description")) - cgit_repo_config(repo, "desc", value); + config_fn(repo, "desc", value); else if (!strcmp(key, "gitweb.category")) - cgit_repo_config(repo, "section", value); + config_fn(repo, "section", value); else if (!strcmp(key, "gitweb.homepage")) - cgit_repo_config(repo, "homepage", value); + config_fn(repo, "homepage", value); else if (skip_prefix(key, "cgit.", &name)) - cgit_repo_config(repo, name, value); + config_fn(repo, name, value); return 0; } @@ -79,7 +80,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) +static void add_repo(const char *base, struct strbuf *path, repo_config_fn fn) { struct stat st; struct passwd *pwd; @@ -121,6 +122,7 @@ static void add_repo(const char *base, struct strbuf *path) 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); @@ -183,7 +185,7 @@ static void add_repo(const char *base, struct strbuf *path) strbuf_release(&rel); } -static void scan_path(const char *base, const char *path) +static void scan_path(const char *base, const char *path, repo_config_fn fn) { DIR *dir = opendir(path); struct dirent *ent; @@ -199,12 +201,12 @@ static void scan_path(const char *base, const char *path) strbuf_add(&pathbuf, path, strlen(path)); if (is_git_dir(pathbuf.buf)) { - add_repo(base, &pathbuf); + add_repo(base, &pathbuf, fn); goto end; } strbuf_addstr(&pathbuf, "/.git"); if (is_git_dir(pathbuf.buf)) { - add_repo(base, &pathbuf); + add_repo(base, &pathbuf, fn); goto end; } /* @@ -229,14 +231,14 @@ static void scan_path(const char *base, const char *path) continue; } if (S_ISDIR(st.st_mode)) - scan_path(base, pathbuf.buf); + scan_path(base, pathbuf.buf, fn); } end: strbuf_release(&pathbuf); closedir(dir); } -void scan_projects(const char *path, const char *projectsfile) +void scan_projects(const char *path, const char *projectsfile, repo_config_fn fn) { struct strbuf line = STRBUF_INIT; FILE *projects; @@ -253,7 +255,7 @@ void scan_projects(const char *path, const char *projectsfile) continue; strbuf_insert(&line, 0, "/", 1); strbuf_insert(&line, 0, path, strlen(path)); - scan_path(path, line.buf); + scan_path(path, line.buf, fn); } if ((err = ferror(projects))) { fprintf(stderr, "Error reading from projectsfile %s: %s (%d)\n", @@ -263,7 +265,7 @@ void scan_projects(const char *path, const char *projectsfile) strbuf_release(&line); } -void scan_tree(const char *path) +void scan_tree(const char *path, repo_config_fn fn) { - scan_path(path, path); + scan_path(path, path, fn); } |