author | Lars Hjemli <hjemli@gmail.com> | 2010-08-04 01:10:29 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2010-08-04 01:10:29 (UTC) |
commit | aec9c245e7eaf444c7ae1851e3eda3b30748950f (patch) (side-by-side diff) | |
tree | 04d5e945781441f2589ae8eb44bee8d5a2b17c2b | |
parent | e6c960c7c0f0d2e54b51cc43ef190df3ce52755e (diff) | |
parent | 119397b175874bd606952e93b7249ae4ffb9afbe (diff) | |
download | cgit-aec9c245e7eaf444c7ae1851e3eda3b30748950f.zip cgit-aec9c245e7eaf444c7ae1851e3eda3b30748950f.tar.gz cgit-aec9c245e7eaf444c7ae1851e3eda3b30748950f.tar.bz2 |
Merge branch 'jd/gitolite'
-rw-r--r-- | cgit.c | 33 | ||||
-rw-r--r-- | cgit.h | 3 | ||||
-rw-r--r-- | cgitrc.5.txt | 21 | ||||
-rw-r--r-- | scan-tree.c | 73 | ||||
-rw-r--r-- | scan-tree.h | 3 |
5 files changed, 116 insertions, 17 deletions
@@ -137,2 +137,4 @@ void config_cb(const char *name, const char *value) 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")) @@ -183,2 +185,4 @@ void config_cb(const char *name, const char *value) 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")) @@ -186,2 +190,5 @@ void config_cb(const char *name, const char *value) process_cached_repolist(expand_macros(value)); + else if (ctx.cfg.project_list) + scan_projects(expand_macros(value), + ctx.cfg.project_list, repo_config); else @@ -202,2 +209,4 @@ void config_cb(const char *name, const char *value) ctx.cfg.renamelimit = atoi(value); + else if (!strcmp(name, "remove-suffix")) + ctx.cfg.remove_suffix = atoi(value); else if (!strcmp(name, "robots")) @@ -288,2 +297,3 @@ static void prepare_context(struct cgit_context *ctx) ctx->cfg.local_time = 0; + ctx->cfg.enable_gitweb_owner = 1; ctx->cfg.enable_tree_linenumbers = 1; @@ -297,3 +307,5 @@ static void prepare_context(struct cgit_context *ctx) 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"; @@ -576,3 +588,6 @@ 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); @@ -590,5 +605,8 @@ static void process_cached_repolist(const char *path) 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)); @@ -599,4 +617,9 @@ static void process_cached_repolist(const char *path) */ - 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; @@ -169,2 +169,3 @@ struct cgit_config { char *module_link; + char *project_list; char *robots; @@ -185,2 +186,3 @@ struct cgit_config { int enable_filter_overrides; + int enable_gitweb_owner; int enable_index_links; @@ -204,2 +206,3 @@ struct cgit_config { int renamelimit; + int remove_suffix; int snapshots; diff --git a/cgitrc.5.txt b/cgitrc.5.txt index a853522..5d77973 100644 --- a/cgitrc.5.txt +++ b/cgitrc.5.txt @@ -97,2 +97,7 @@ enable-filter-overrides:: +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:: @@ -226,2 +231,12 @@ noheader:: +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:: @@ -255,3 +270,6 @@ scan-path:: 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. @@ -532 +550,2 @@ 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 +1,10 @@ +/* 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" @@ -40,2 +49,3 @@ struct cgit_repo *repo; repo_config_fn config_fn; +char *owner; @@ -46,2 +56,9 @@ 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) @@ -60,7 +77,6 @@ static void add_repo(const char *base, const char *path, repo_config_fn fn) 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) @@ -74,8 +90,19 @@ 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; @@ -144,2 +171,30 @@ 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); |