summaryrefslogtreecommitdiffabout
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--cgit.c27
-rw-r--r--cgit.h1
-rw-r--r--cgitrc.5.txt10
-rw-r--r--scan-tree.c37
-rw-r--r--scan-tree.h3
5 files changed, 70 insertions, 8 deletions
diff --git a/cgit.c b/cgit.c
index c263872..2364d1c 100644
--- a/cgit.c
+++ b/cgit.c
@@ -178,15 +178,20 @@ void config_cb(const char *name, const char *value)
else if (!strcmp(name, "max-blob-size"))
ctx.cfg.max_blob_size = atoi(value);
else if (!strcmp(name, "max-repo-count"))
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)
process_cached_repolist(expand_macros(value));
+ else if (ctx.cfg.project_list)
+ scan_projects(expand_macros(value),
+ ctx.cfg.project_list, repo_config);
else
scan_tree(expand_macros(value), repo_config);
else if (!strcmp(name, "source-filter"))
ctx.cfg.source_filter = new_filter(value, 1);
else if (!strcmp(name, "summary-log"))
ctx.cfg.summary_log = atoi(value);
@@ -292,12 +297,13 @@ static void prepare_context(struct cgit_context *ctx)
ctx->cfg.max_lock_attempts = 5;
ctx->cfg.max_msg_len = 80;
ctx->cfg.max_repodesc_len = 80;
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 = NULL;
ctx->cfg.renamelimit = -1;
ctx->cfg.robots = "index, nofollow";
ctx->cfg.root_title = "Git repository browser";
ctx->cfg.root_desc = "a fast webinterface for the git dscm";
ctx->cfg.script_name = CGIT_SCRIPT_NAME;
ctx->cfg.section = "";
@@ -571,13 +577,16 @@ static int generate_cached_repolist(const char *path, const char *cached_rc)
if (errno != EEXIST)
fprintf(stderr, "[cgit] Error opening %s: %s (%d)\n",
locked_rc, strerror(errno), errno);
return errno;
}
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);
if (rename(locked_rc, cached_rc))
fprintf(stderr, "[cgit] Error renaming %s to %s: %s (%d)\n",
locked_rc, cached_rc, strerror(errno), errno);
fclose(f);
return 0;
@@ -585,23 +594,31 @@ static int generate_cached_repolist(const char *path, const char *cached_rc)
static void process_cached_repolist(const char *path)
{
struct stat st;
char *cached_rc;
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));
if (stat(cached_rc, &st)) {
/* Nothing is cached, we need to scan without forking. And
* if we fail to generate a cached repolist, we need to
* invoke scan_tree manually.
*/
- 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;
}
parse_configfile(cached_rc, config_cb);
/* If the cached configfile hasn't expired, lets exit now */
diff --git a/cgit.h b/cgit.h
index e9e2718..4591f8c 100644
--- a/cgit.h
+++ b/cgit.h
@@ -163,12 +163,13 @@ struct cgit_config {
char *header;
char *index_header;
char *index_info;
char *logo;
char *logo_link;
char *module_link;
+ char *project_list;
char *robots;
char *root_title;
char *root_desc;
char *root_readme;
char *script_name;
char *section;
diff --git a/cgitrc.5.txt b/cgitrc.5.txt
index a853522..ec004d4 100644
--- a/cgitrc.5.txt
+++ b/cgitrc.5.txt
@@ -221,12 +221,17 @@ noplainemail::
Default value: "0".
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
`man git-diff`). Default value: "-1".
repo.group::
@@ -250,13 +255,16 @@ root-title::
Text printed as heading on the repository index page. Default value:
"Git Repository Browser".
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. Default value: none. See also: cache-scanrc-ttl,
+ project-list.
section::
The name of the current repository section - all repositories defined
after this option will inherit the current section name. Default value:
none.
diff --git a/scan-tree.c b/scan-tree.c
index 1e18f3c..9bf9b38 100644
--- a/scan-tree.c
+++ b/scan-tree.c
@@ -1,6 +1,15 @@
+/* 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"
#include "configfile.h"
#include "html.h"
#define MAX_PATH 4096
@@ -139,10 +148,38 @@ static void scan_path(const char *base, const char *path, repo_config_fn fn)
scan_path(base, buf, fn);
free(buf);
}
closedir(dir);
}
+#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)
{
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);