From a519f8abc0d138d9f547b013c34aceb9a223ca64 Mon Sep 17 00:00:00 2001 From: Jason A. Donenfeld Date: Thu, 29 Jul 2010 17:52:29 +0200 Subject: [PATCH 1/3] Optionally use a projects.list like gitweb, which allows cgit to more easily interface with gitolite. --- cgit.c | 7 ++++++- cgit.h | 1 + cgitrc.5.txt | 10 +++++++++- scan-tree.c | 27 ++++++++++++++++++++++++++- scan-tree.h | 3 +-- 5 files changed, 43 insertions(+), 5 deletions(-) diff --git a/cgit.c b/cgit.c index c263872..4dadbce 100644 --- a/cgit.c +++ b/cgit.c @@ -181,8 +181,12 @@ void config_cb(const char *name, const char *value) ctx.cfg.max_repo_count = atoi(value); else if (!strcmp(name, "max-commit-count")) 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")) - if (!ctx.cfg.nocache && ctx.cfg.cache_size) + if (ctx.cfg.project_list) + scan_projects(expand_macros(value), ctx.cfg.project_list, repo_config); + else if (!ctx.cfg.nocache && ctx.cfg.cache_size) process_cached_repolist(expand_macros(value)); else scan_tree(expand_macros(value), repo_config); @@ -295,6 +299,7 @@ static void prepare_context(struct cgit_context *ctx) ctx->cfg.max_blob_size = 0; ctx->cfg.max_stats = 0; ctx->cfg.module_link = "./?repo=%s&page=commit&id=%s"; + ctx->cfg.project_list = 0; ctx->cfg.renamelimit = -1; ctx->cfg.robots = "index, nofollow"; ctx->cfg.root_title = "Git repository browser"; diff --git a/cgit.h b/cgit.h index e9e2718..4591f8c 100644 --- a/cgit.h +++ b/cgit.h @@ -166,6 +166,7 @@ struct cgit_config { char *logo; char *logo_link; char *module_link; + char *project_list; char *robots; char *root_title; char *root_desc; diff --git a/cgitrc.5.txt b/cgitrc.5.txt index a853522..8e408f7 100644 --- a/cgitrc.5.txt +++ b/cgitrc.5.txt @@ -224,6 +224,11 @@ noheader:: Flag which, when set to "1", will make cgit omit the standard header on all pages. Default value: none. See also: "embedded". +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:: Maximum number of files to consider when detecting renames. The value "-1" uses the compiletime value in git (for further info, look at @@ -253,7 +258,10 @@ root-title:: scan-path:: A path which will be scanned for repositories. If caching is enabled, 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, and caching is disabled. Default value: none. See also: + cache-scanrc-ttl, project-list. section:: The name of the current repository section - all repositories defined diff --git a/scan-tree.c b/scan-tree.c index 1e18f3c..5b20414 100644 --- a/scan-tree.c +++ b/scan-tree.c @@ -1,3 +1,12 @@ +/* scan-tree.c + * + * Copyright (C) 2008-2009 Lars Hjemli + * Copyright (C) 2010 Jason A. Donenfeld + * + * Licensed under GNU General Public License v2 + * (see COPYING for full license text) + */ + #include "cgit.h" #include "configfile.h" #include "html.h" @@ -141,7 +150,23 @@ static void scan_path(const char *base, const char *path, repo_config_fn fn) } closedir(dir); } - +void scan_projects(const char *path, const char *projectsfile, repo_config_fn fn) +{ + char *buf; + FILE *projects = fopen(projectsfile, "r"); + if (projects != NULL) { + char project[512]; + while (fgets(project, sizeof(project), projects) != NULL) { + if (project[strlen(project) - 1] == '\n') + project[strlen(project) - 1] = '\0'; + buf = malloc(strlen(path) + strlen(project) + 2); + sprintf(buf, "%s/%s", path, project); + scan_path(path, buf, fn); + free(buf); + } + fclose(projects); + } +} void scan_tree(const char *path, repo_config_fn fn) { scan_path(path, path, 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); -- 1.7.2