summaryrefslogtreecommitdiffabout
authorLars Hjemli <hjemli@gmail.com>2010-08-04 01:10:29 (UTC)
committer Lars Hjemli <hjemli@gmail.com>2010-08-04 01:10:29 (UTC)
commitaec9c245e7eaf444c7ae1851e3eda3b30748950f (patch) (side-by-side diff)
tree04d5e945781441f2589ae8eb44bee8d5a2b17c2b
parente6c960c7c0f0d2e54b51cc43ef190df3ce52755e (diff)
parent119397b175874bd606952e93b7249ae4ffb9afbe (diff)
downloadcgit-aec9c245e7eaf444c7ae1851e3eda3b30748950f.zip
cgit-aec9c245e7eaf444c7ae1851e3eda3b30748950f.tar.gz
cgit-aec9c245e7eaf444c7ae1851e3eda3b30748950f.tar.bz2
Merge branch 'jd/gitolite'
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--cgit.c33
-rw-r--r--cgit.h3
-rw-r--r--cgitrc.5.txt21
-rw-r--r--scan-tree.c73
-rw-r--r--scan-tree.h3
5 files changed, 116 insertions, 17 deletions
diff --git a/cgit.c b/cgit.c
index c263872..eff5b7a 100644
--- a/cgit.c
+++ b/cgit.c
@@ -136,4 +136,6 @@ void config_cb(const char *name, const char *value)
else if (!strcmp(name, "enable-filter-overrides"))
ctx.cfg.enable_filter_overrides = atoi(value);
+ else if (!strcmp(name, "enable-gitweb-owner"))
+ ctx.cfg.enable_gitweb_owner = atoi(value);
else if (!strcmp(name, "enable-index-links"))
ctx.cfg.enable_index_links = atoi(value);
@@ -182,7 +184,12 @@ void config_cb(const char *name, const char *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);
@@ -201,4 +208,6 @@ void config_cb(const char *name, const char *value)
else if (!strcmp(name, "renamelimit"))
ctx.cfg.renamelimit = atoi(value);
+ else if (!strcmp(name, "remove-suffix"))
+ ctx.cfg.remove_suffix = atoi(value);
else if (!strcmp(name, "robots"))
ctx.cfg.robots = xstrdup(value);
@@ -287,4 +296,5 @@ static void prepare_context(struct cgit_context *ctx)
ctx->cfg.logo = "/cgit.png";
ctx->cfg.local_time = 0;
+ ctx->cfg.enable_gitweb_owner = 1;
ctx->cfg.enable_tree_linenumbers = 1;
ctx->cfg.max_repo_count = 50;
@@ -296,5 +306,7 @@ static void prepare_context(struct cgit_context *ctx)
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.remove_suffix = 0;
ctx->cfg.robots = "index, nofollow";
ctx->cfg.root_title = "Git repository browser";
@@ -575,5 +587,8 @@ 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);
if (rename(locked_rc, cached_rc))
@@ -589,7 +604,10 @@ static void process_cached_repolist(const char *path)
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)) {
@@ -598,6 +616,11 @@ static void process_cached_repolist(const char *path)
* 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;
}
diff --git a/cgit.h b/cgit.h
index 32d9d2b..4090cd4 100644
--- a/cgit.h
+++ b/cgit.h
@@ -168,4 +168,5 @@ struct cgit_config {
char *logo_link;
char *module_link;
+ char *project_list;
char *robots;
char *root_title;
@@ -184,4 +185,5 @@ struct cgit_config {
int embedded;
int enable_filter_overrides;
+ int enable_gitweb_owner;
int enable_index_links;
int enable_log_filecount;
@@ -203,4 +205,5 @@ struct cgit_config {
int noheader;
int renamelimit;
+ int remove_suffix;
int snapshots;
int summary_branches;
diff --git a/cgitrc.5.txt b/cgitrc.5.txt
index a853522..5d77973 100644
--- a/cgitrc.5.txt
+++ b/cgitrc.5.txt
@@ -96,4 +96,9 @@ enable-filter-overrides::
overridden in repository-specific cgitrc files. Default value: none.
+enable-gitweb-owner::
+ If set to "1" and scan-path is enabled, we first check each repository
+ for the git config value "gitweb.owner" to determine the owner.
+ Default value: "1". See also: scan-path.
+
enable-index-links::
Flag which, when set to "1", will make cgit generate extra links for
@@ -225,4 +230,14 @@ noheader::
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.
+
+remove-suffix::
+ If set to "1" and scan-path is enabled, if any repositories are found
+ with a suffix of ".git", this suffix will be removed for the url and
+ name. Default value: "0". See also: scan-path.
+
renamelimit::
Maximum number of files to consider when detecting renames. The value
@@ -254,5 +269,8 @@ 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::
@@ -531,2 +549,3 @@ AUTHOR
------
Lars Hjemli <hjemli@gmail.com>
+Jason A. Donenfeld <Jason@zx2c4.com>
diff --git a/scan-tree.c b/scan-tree.c
index 1e18f3c..e987824 100644
--- a/scan-tree.c
+++ b/scan-tree.c
@@ -1,2 +1,11 @@
+/* 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"
@@ -39,4 +48,5 @@ static int is_git_dir(const char *path)
struct cgit_repo *repo;
repo_config_fn config_fn;
+char *owner;
static void repo_config(const char *name, const char *value)
@@ -45,4 +55,11 @@ static void repo_config(const char *name, const char *value)
}
+static int git_owner_config(const char *key, const char *value, void *cb)
+{
+ if (!strcmp(key, "gitweb.owner"))
+ owner = xstrdup(value);
+ return 0;
+}
+
static void add_repo(const char *base, const char *path, repo_config_fn fn)
{
@@ -59,9 +76,8 @@ static void add_repo(const char *base, const char *path, repo_config_fn fn)
if (!stat(fmt("%s/noweb", path), &st))
return;
- if ((pwd = getpwuid(st.st_uid)) == NULL) {
- fprintf(stderr, "Error reading owner-info for %s: %s (%d)\n",
- path, strerror(errno), errno);
- return;
- }
+
+ owner = NULL;
+ if (ctx.cfg.enable_gitweb_owner)
+ git_config_from_file(git_owner_config, fmt("%s/config", path), NULL);
if (base == path)
p = fmt("%s", path);
@@ -73,10 +89,21 @@ static void add_repo(const char *base, const char *path, repo_config_fn fn)
repo = cgit_add_repo(xstrdup(p));
+ if (ctx.cfg.remove_suffix)
+ if ((p = strrchr(repo->url, '.')) && !strcmp(p, ".git"))
+ *p = '\0';
repo->name = repo->url;
repo->path = xstrdup(path);
- p = (pwd && pwd->pw_gecos) ? strchr(pwd->pw_gecos, ',') : NULL;
- if (p)
- *p = '\0';
- repo->owner = (pwd ? xstrdup(pwd->pw_gecos ? pwd->pw_gecos : pwd->pw_name) : "");
+ while (!owner) {
+ if ((pwd = getpwuid(st.st_uid)) == NULL) {
+ fprintf(stderr, "Error reading owner-info for %s: %s (%d)\n",
+ path, strerror(errno), errno);
+ break;
+ }
+ if (pwd->pw_gecos)
+ if ((p = strchr(pwd->pw_gecos, ',')))
+ *p = '\0';
+ owner = xstrdup(pwd->pw_gecos ? pwd->pw_gecos : pwd->pw_name);
+ }
+ repo->owner = owner;
p = fmt("%s/description", path);
@@ -143,4 +170,32 @@ 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);