-rw-r--r-- | cgit.c | 27 | ||||
-rw-r--r-- | cgit.h | 1 | ||||
-rw-r--r-- | cgitrc.5.txt | 10 | ||||
-rw-r--r-- | scan-tree.c | 37 | ||||
-rw-r--r-- | scan-tree.h | 3 |
5 files changed, 70 insertions, 8 deletions
@@ -183,2 +183,4 @@ void config_cb(const char *name, const char *value) ctx.cfg.max_commit_count = atoi(value); + else if (!strcmp(name, "project-list")) + ctx.cfg.project_list = xstrdup(expand_macros(value)); else if (!strcmp(name, "scan-path")) @@ -186,2 +188,5 @@ void config_cb(const char *name, const char *value) process_cached_repolist(expand_macros(value)); + else if (ctx.cfg.project_list) + scan_projects(expand_macros(value), + ctx.cfg.project_list, repo_config); else @@ -297,2 +302,3 @@ static void prepare_context(struct cgit_context *ctx) ctx->cfg.module_link = "./?repo=%s&page=commit&id=%s"; + ctx->cfg.project_list = NULL; ctx->cfg.renamelimit = -1; @@ -576,3 +582,6 @@ static int generate_cached_repolist(const char *path, const char *cached_rc) idx = cgit_repolist.count; - scan_tree(path, repo_config); + if (ctx.cfg.project_list) + scan_projects(path, ctx.cfg.project_list, repo_config); + else + scan_tree(path, repo_config); print_repolist(f, &cgit_repolist, idx); @@ -590,5 +599,8 @@ static void process_cached_repolist(const char *path) time_t age; + unsigned long hash; - cached_rc = xstrdup(fmt("%s/rc-%8x", ctx.cfg.cache_root, - hash_str(path))); + hash = hash_str(path); + if (ctx.cfg.project_list) + hash += hash_str(ctx.cfg.project_list); + cached_rc = xstrdup(fmt("%s/rc-%8x", ctx.cfg.cache_root, hash)); @@ -599,4 +611,9 @@ static void process_cached_repolist(const char *path) */ - if (generate_cached_repolist(path, cached_rc)) - scan_tree(path, repo_config); + if (generate_cached_repolist(path, cached_rc)) { + if (ctx.cfg.project_list) + scan_projects(path, ctx.cfg.project_list, + repo_config); + else + scan_tree(path, repo_config); + } return; @@ -168,2 +168,3 @@ struct cgit_config { char *module_link; + char *project_list; char *robots; diff --git a/cgitrc.5.txt b/cgitrc.5.txt index a853522..ec004d4 100644 --- a/cgitrc.5.txt +++ b/cgitrc.5.txt @@ -226,2 +226,7 @@ noheader:: +project-list:: + A list of subdirectories inside of scan-path, relative to it, that + should loaded as git repositories. This must be defined prior to + scan-path. Default value: none. See also: scan-path. + renamelimit:: @@ -255,3 +260,6 @@ scan-path:: the result will be cached as a cgitrc include-file in the cache - directory. Default value: none. See also: cache-scanrc-ttl. + directory. If project-list has been defined prior to scan-path, + scan-path loads only the directories listed in the file pointed to by + project-list. Default value: none. See also: cache-scanrc-ttl, + project-list. diff --git a/scan-tree.c b/scan-tree.c index 1e18f3c..9bf9b38 100644 --- a/scan-tree.c +++ b/scan-tree.c @@ -1 +1,10 @@ +/* scan-tree.c + * + * Copyright (C) 2008-2009 Lars Hjemli + * Copyright (C) 2010 Jason A. Donenfeld <Jason@zx2c4.com> + * + * Licensed under GNU General Public License v2 + * (see COPYING for full license text) + */ + #include "cgit.h" @@ -144,2 +153,30 @@ static void scan_path(const char *base, const char *path, repo_config_fn fn) +#define lastc(s) s[strlen(s) - 1] + +void scan_projects(const char *path, const char *projectsfile, repo_config_fn fn) +{ + char line[MAX_PATH * 2], *z; + FILE *projects; + int err; + + projects = fopen(projectsfile, "r"); + if (!projects) { + fprintf(stderr, "Error opening projectsfile %s: %s (%d)\n", + projectsfile, strerror(errno), errno); + } + while (fgets(line, sizeof(line), projects) != NULL) { + for (z = &lastc(line); + strlen(line) && strchr("\n\r", *z); + z = &lastc(line)) + *z = '\0'; + if (strlen(line)) + scan_path(path, fmt("%s/%s", path, line), fn); + } + if ((err = ferror(projects))) { + fprintf(stderr, "Error reading from projectsfile %s: %s (%d)\n", + projectsfile, strerror(err), err); + } + fclose(projects); +} + void scan_tree(const char *path, repo_config_fn fn) diff --git a/scan-tree.h b/scan-tree.h index 11539f4..1afbd4b 100644 --- a/scan-tree.h +++ b/scan-tree.h @@ -1,3 +1,2 @@ - - +extern void scan_projects(const char *path, const char *projectsfile, repo_config_fn fn); extern void scan_tree(const char *path, repo_config_fn fn); |