This option specifies the location of a projectlist file as used by gitweb - when 'scan-tree' is later specified, only the projects listed in the projectlist file will be added.
Unified · Split
| @@ -181,9 +181,14 @@ void config_cb(const char *name, const char *value) · 180 unmodified lines | ||
| 181 | 181 | ctx.cfg.max_repo_count = atoi(value); |
| 182 | 182 | else if (!strcmp(name, "max-commit-count")) |
| 183 | 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 | 186 | else if (!strcmp(name, "scan-path")) |
| 185 | 187 | if (!ctx.cfg.nocache && ctx.cfg.cache_size) |
| 186 | 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 | 192 | else |
| 188 | 193 | scan_tree(expand_macros(value), repo_config); |
| 189 | 194 | else if (!strcmp(name, "source-filter")) |
| @@ -295,6 +300,7 @@ static void prepare_context(struct cgit_context *ctx) · 105 unmodified lines | ||
| 295 | 300 | ctx->cfg.max_blob_size = 0; |
| 296 | 301 | ctx->cfg.max_stats = 0; |
| 297 | 302 | ctx->cfg.module_link = "./?repo=%s&page=commit&id=%s"; |
| 303 | + ctx->cfg.project_list = NULL; | |
| 298 | 304 | ctx->cfg.renamelimit = -1; |
| 299 | 305 | ctx->cfg.robots = "index, nofollow"; |
| 300 | 306 | ctx->cfg.root_title = "Git repository browser"; |
| @@ -574,7 +580,10 @@ static int generate_cached_repolist(const char *path, const char *cached_rc) · 273 unmodified lines | ||
| 574 | 580 | return errno; |
| 575 | 581 | } |
| 576 | 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 | 587 | print_repolist(f, &cgit_repolist, idx); |
| 579 | 588 | if (rename(locked_rc, cached_rc)) |
| 580 | 589 | fprintf(stderr, "[cgit] Error renaming %s to %s: %s (%d)\n", |
| @@ -588,17 +597,25 @@ static void process_cached_repolist(const char *path) · 7 unmodified lines | ||
| 588 | 597 | struct stat st; |
| 589 | 598 | char *cached_rc; |
| 590 | 599 | time_t age; |
| 600 | + unsigned long hash; | |
| 591 | 601 | |
| 592 | − cached_rc = xstrdup(fmt("%s/rc-%8x", ctx.cfg.cache_root, | |
| 593 | − hash_str(path))); | |
| 602 | + hash = 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 | 607 | if (stat(cached_rc, &st)) { |
| 596 | 608 | /* Nothing is cached, we need to scan without forking. And |
| 597 | 609 | * if we fail to generate a cached repolist, we need to |
| 598 | 610 | * invoke scan_tree manually. |
| 599 | 611 | */ |
| 600 | − if (generate_cached_repolist(path, cached_rc)) | |
| 601 | − scan_tree(path, repo_config); | |
| 612 | + if (generate_cached_repolist(path, cached_rc)) { | |
| 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 | 619 | return; |
| 603 | 620 | } |
| 604 | 621 | |
| @@ -166,6 +166,7 @@ struct cgit_config { · 165 unmodified lines | ||
| 166 | 166 | char *logo; |
| 167 | 167 | char *logo_link; |
| 168 | 168 | char *module_link; |
| 169 | + char *project_list; | |
| 169 | 170 | char *robots; |
| 170 | 171 | char *root_title; |
| 171 | 172 | char *root_desc; |
| @@ -224,6 +224,11 @@ noheader:: · 223 unmodified lines | ||
| 224 | 224 | Flag which, when set to "1", will make cgit omit the standard header |
| 225 | 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 | 232 | renamelimit:: |
| 228 | 233 | Maximum number of files to consider when detecting renames. The value |
| 229 | 234 | "-1" uses the compiletime value in git (for further info, look at |
| @@ -253,7 +258,10 @@ root-title:: · 23 unmodified lines | ||
| 253 | 258 | scan-path:: |
| 254 | 259 | A path which will be scanned for repositories. If caching is enabled, |
| 255 | 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 | 266 | section:: |
| 259 | 267 | The name of the current repository section - all repositories defined |
| @@ -1,3 +1,12 @@ | ||
| 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 | 10 | #include "cgit.h" |
| 2 | 11 | #include "configfile.h" |
| 3 | 12 | #include "html.h" |
| @@ -142,6 +151,34 @@ static void scan_path(const char *base, const char *path, repo_config_fn fn) · 138 unmodified lines | ||
| 142 | 151 | closedir(dir); |
| 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 | 182 | void scan_tree(const char *path, repo_config_fn fn) |
| 146 | 183 | { |
| 147 | 184 | scan_path(path, path, fn); |
| @@ -1,3 +1,2 @@ | ||
| 1 | − | |
| 2 | − | |
| 1 | +extern void scan_projects(const char *path, const char *projectsfile, repo_config_fn fn); | |
| 3 | 2 | extern void scan_tree(const char *path, repo_config_fn fn); |