-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
@@ -182,7 +182,12 @@ void config_cb(const char *name, const char *value) | |||
182 | else if (!strcmp(name, "max-commit-count")) | 182 | else if (!strcmp(name, "max-commit-count")) |
183 | ctx.cfg.max_commit_count = atoi(value); | 183 | ctx.cfg.max_commit_count = atoi(value); |
184 | else if (!strcmp(name, "project-list")) | ||
185 | ctx.cfg.project_list = xstrdup(expand_macros(value)); | ||
184 | else if (!strcmp(name, "scan-path")) | 186 | else if (!strcmp(name, "scan-path")) |
185 | if (!ctx.cfg.nocache && ctx.cfg.cache_size) | 187 | if (!ctx.cfg.nocache && ctx.cfg.cache_size) |
186 | process_cached_repolist(expand_macros(value)); | 188 | process_cached_repolist(expand_macros(value)); |
189 | else if (ctx.cfg.project_list) | ||
190 | scan_projects(expand_macros(value), | ||
191 | ctx.cfg.project_list, repo_config); | ||
187 | else | 192 | else |
188 | scan_tree(expand_macros(value), repo_config); | 193 | scan_tree(expand_macros(value), repo_config); |
@@ -296,4 +301,5 @@ static void prepare_context(struct cgit_context *ctx) | |||
296 | ctx->cfg.max_stats = 0; | 301 | ctx->cfg.max_stats = 0; |
297 | ctx->cfg.module_link = "./?repo=%s&page=commit&id=%s"; | 302 | ctx->cfg.module_link = "./?repo=%s&page=commit&id=%s"; |
303 | ctx->cfg.project_list = NULL; | ||
298 | ctx->cfg.renamelimit = -1; | 304 | ctx->cfg.renamelimit = -1; |
299 | ctx->cfg.robots = "index, nofollow"; | 305 | ctx->cfg.robots = "index, nofollow"; |
@@ -575,5 +581,8 @@ static int generate_cached_repolist(const char *path, const char *cached_rc) | |||
575 | } | 581 | } |
576 | idx = cgit_repolist.count; | 582 | idx = cgit_repolist.count; |
577 | scan_tree(path, repo_config); | 583 | if (ctx.cfg.project_list) |
584 | scan_projects(path, ctx.cfg.project_list, repo_config); | ||
585 | else | ||
586 | scan_tree(path, repo_config); | ||
578 | print_repolist(f, &cgit_repolist, idx); | 587 | print_repolist(f, &cgit_repolist, idx); |
579 | if (rename(locked_rc, cached_rc)) | 588 | if (rename(locked_rc, cached_rc)) |
@@ -589,7 +598,10 @@ static void process_cached_repolist(const char *path) | |||
589 | char *cached_rc; | 598 | char *cached_rc; |
590 | time_t age; | 599 | time_t age; |
600 | unsigned long hash; | ||
591 | 601 | ||
592 | cached_rc = xstrdup(fmt("%s/rc-%8x", ctx.cfg.cache_root, | 602 | hash = hash_str(path); |
593 | hash_str(path))); | 603 | if (ctx.cfg.project_list) |
604 | hash += hash_str(ctx.cfg.project_list); | ||
605 | cached_rc = xstrdup(fmt("%s/rc-%8x", ctx.cfg.cache_root, hash)); | ||
594 | 606 | ||
595 | if (stat(cached_rc, &st)) { | 607 | if (stat(cached_rc, &st)) { |
@@ -598,6 +610,11 @@ static void process_cached_repolist(const char *path) | |||
598 | * invoke scan_tree manually. | 610 | * invoke scan_tree manually. |
599 | */ | 611 | */ |
600 | if (generate_cached_repolist(path, cached_rc)) | 612 | if (generate_cached_repolist(path, cached_rc)) { |
601 | scan_tree(path, repo_config); | 613 | if (ctx.cfg.project_list) |
614 | scan_projects(path, ctx.cfg.project_list, | ||
615 | repo_config); | ||
616 | else | ||
617 | scan_tree(path, repo_config); | ||
618 | } | ||
602 | return; | 619 | return; |
603 | } | 620 | } |
@@ -167,4 +167,5 @@ struct cgit_config { | |||
167 | char *logo_link; | 167 | char *logo_link; |
168 | char *module_link; | 168 | char *module_link; |
169 | char *project_list; | ||
169 | char *robots; | 170 | char *robots; |
170 | char *root_title; | 171 | char *root_title; |
diff --git a/cgitrc.5.txt b/cgitrc.5.txt index a853522..ec004d4 100644 --- a/cgitrc.5.txt +++ b/cgitrc.5.txt | |||
@@ -225,4 +225,9 @@ noheader:: | |||
225 | on all pages. Default value: none. See also: "embedded". | 225 | on all pages. Default value: none. See also: "embedded". |
226 | 226 | ||
227 | project-list:: | ||
228 | A list of subdirectories inside of scan-path, relative to it, that | ||
229 | should loaded as git repositories. This must be defined prior to | ||
230 | scan-path. Default value: none. See also: scan-path. | ||
231 | |||
227 | renamelimit:: | 232 | renamelimit:: |
228 | Maximum number of files to consider when detecting renames. The value | 233 | Maximum number of files to consider when detecting renames. The value |
@@ -254,5 +259,8 @@ scan-path:: | |||
254 | A path which will be scanned for repositories. If caching is enabled, | 259 | A path which will be scanned for repositories. If caching is enabled, |
255 | the result will be cached as a cgitrc include-file in the cache | 260 | the result will be cached as a cgitrc include-file in the cache |
256 | directory. Default value: none. See also: cache-scanrc-ttl. | 261 | directory. If project-list has been defined prior to scan-path, |
262 | scan-path loads only the directories listed in the file pointed to by | ||
263 | project-list. Default value: none. See also: cache-scanrc-ttl, | ||
264 | project-list. | ||
257 | 265 | ||
258 | section:: | 266 | section:: |
diff --git a/scan-tree.c b/scan-tree.c index 1e18f3c..9bf9b38 100644 --- a/scan-tree.c +++ b/scan-tree.c | |||
@@ -1,2 +1,11 @@ | |||
1 | /* scan-tree.c | ||
2 | * | ||
3 | * Copyright (C) 2008-2009 Lars Hjemli | ||
4 | * Copyright (C) 2010 Jason A. Donenfeld <Jason@zx2c4.com> | ||
5 | * | ||
6 | * Licensed under GNU General Public License v2 | ||
7 | * (see COPYING for full license text) | ||
8 | */ | ||
9 | |||
1 | #include "cgit.h" | 10 | #include "cgit.h" |
2 | #include "configfile.h" | 11 | #include "configfile.h" |
@@ -143,4 +152,32 @@ static void scan_path(const char *base, const char *path, repo_config_fn fn) | |||
143 | } | 152 | } |
144 | 153 | ||
154 | #define lastc(s) s[strlen(s) - 1] | ||
155 | |||
156 | void scan_projects(const char *path, const char *projectsfile, repo_config_fn fn) | ||
157 | { | ||
158 | char line[MAX_PATH * 2], *z; | ||
159 | FILE *projects; | ||
160 | int err; | ||
161 | |||
162 | projects = fopen(projectsfile, "r"); | ||
163 | if (!projects) { | ||
164 | fprintf(stderr, "Error opening projectsfile %s: %s (%d)\n", | ||
165 | projectsfile, strerror(errno), errno); | ||
166 | } | ||
167 | while (fgets(line, sizeof(line), projects) != NULL) { | ||
168 | for (z = &lastc(line); | ||
169 | strlen(line) && strchr("\n\r", *z); | ||
170 | z = &lastc(line)) | ||
171 | *z = '\0'; | ||
172 | if (strlen(line)) | ||
173 | scan_path(path, fmt("%s/%s", path, line), fn); | ||
174 | } | ||
175 | if ((err = ferror(projects))) { | ||
176 | fprintf(stderr, "Error reading from projectsfile %s: %s (%d)\n", | ||
177 | projectsfile, strerror(err), err); | ||
178 | } | ||
179 | fclose(projects); | ||
180 | } | ||
181 | |||
145 | void scan_tree(const char *path, repo_config_fn fn) | 182 | void scan_tree(const char *path, repo_config_fn fn) |
146 | { | 183 | { |
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 @@ | |||
1 | 1 | extern void scan_projects(const char *path, const char *projectsfile, repo_config_fn fn); | |
2 | |||
3 | extern void scan_tree(const char *path, repo_config_fn fn); | 2 | extern void scan_tree(const char *path, repo_config_fn fn); |