summaryrefslogtreecommitdiffabout
authorLars Hjemli <hjemli@gmail.com>2009-08-23 22:04:58 (UTC)
committer Lars Hjemli <hjemli@gmail.com>2009-08-24 08:22:58 (UTC)
commit74061ed5f03e72796450aa3b8ca1cf6ced5d59e2 (patch) (unidiff)
tree235ab2c29c027f19b00da815af3bf1d2856edc21
parenta1b3938f711c9b0e5eedad1678535e5779da82c1 (diff)
downloadcgit-74061ed5f03e72796450aa3b8ca1cf6ced5d59e2.zip
cgit-74061ed5f03e72796450aa3b8ca1cf6ced5d59e2.tar.gz
cgit-74061ed5f03e72796450aa3b8ca1cf6ced5d59e2.tar.bz2
Add support for repo-local cgitrc file
When recursively scanning a directory tree looking for git repositories, cgit will now parse cgitrc files found within such repositories. The repo-specific config files can include any repo-specific options except 'repo.url' and 'repo.path'. Also, in such config files the 'repo.' prefix can not be used, i.e. the valid options then becomes: * name * clone-url * desc * ower * defbranch * snapshots * enable-log-filecount * enable-log-linecount * max-stats * module-link * section * about-filter * commit-filter * source-filter * readme Signed-off-by: Lars Hjemli <hjemli@gmail.com>
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--cgit.c8
-rw-r--r--cgit.h3
-rw-r--r--cgitrc.5.txt9
-rw-r--r--scan-tree.c30
-rw-r--r--scan-tree.h2
5 files changed, 39 insertions, 13 deletions
diff --git a/cgit.c b/cgit.c
index 90ae124..e281aa9 100644
--- a/cgit.c
+++ b/cgit.c
@@ -165,13 +165,13 @@ void config_cb(const char *name, const char *value)
165 else if (!strcmp(name, "max-commit-count")) 165 else if (!strcmp(name, "max-commit-count"))
166 ctx.cfg.max_commit_count = atoi(value); 166 ctx.cfg.max_commit_count = atoi(value);
167 else if (!strcmp(name, "scan-path")) 167 else if (!strcmp(name, "scan-path"))
168 if (!ctx.cfg.nocache && ctx.cfg.cache_size) 168 if (!ctx.cfg.nocache && ctx.cfg.cache_size)
169 process_cached_repolist(value); 169 process_cached_repolist(value);
170 else 170 else
171 scan_tree(value); 171 scan_tree(value, repo_config);
172 else if (!strcmp(name, "source-filter")) 172 else if (!strcmp(name, "source-filter"))
173 ctx.cfg.source_filter = new_filter(value, 1); 173 ctx.cfg.source_filter = new_filter(value, 1);
174 else if (!strcmp(name, "summary-log")) 174 else if (!strcmp(name, "summary-log"))
175 ctx.cfg.summary_log = atoi(value); 175 ctx.cfg.summary_log = atoi(value);
176 else if (!strcmp(name, "summary-branches")) 176 else if (!strcmp(name, "summary-branches"))
177 ctx.cfg.summary_branches = atoi(value); 177 ctx.cfg.summary_branches = atoi(value);
@@ -473,13 +473,13 @@ static int generate_cached_repolist(const char *path, const char *cached_rc)
473 if (errno != EEXIST) 473 if (errno != EEXIST)
474 fprintf(stderr, "[cgit] Error opening %s: %s (%d)\n", 474 fprintf(stderr, "[cgit] Error opening %s: %s (%d)\n",
475 locked_rc, strerror(errno), errno); 475 locked_rc, strerror(errno), errno);
476 return errno; 476 return errno;
477 } 477 }
478 idx = cgit_repolist.count; 478 idx = cgit_repolist.count;
479 scan_tree(path); 479 scan_tree(path, repo_config);
480 print_repolist(f, &cgit_repolist, idx); 480 print_repolist(f, &cgit_repolist, idx);
481 if (rename(locked_rc, cached_rc)) 481 if (rename(locked_rc, cached_rc))
482 fprintf(stderr, "[cgit] Error renaming %s to %s: %s (%d)\n", 482 fprintf(stderr, "[cgit] Error renaming %s to %s: %s (%d)\n",
483 locked_rc, cached_rc, strerror(errno), errno); 483 locked_rc, cached_rc, strerror(errno), errno);
484 fclose(f); 484 fclose(f);
485 return 0; 485 return 0;
@@ -497,13 +497,13 @@ static void process_cached_repolist(const char *path)
497 if (stat(cached_rc, &st)) { 497 if (stat(cached_rc, &st)) {
498 /* Nothing is cached, we need to scan without forking. And 498 /* Nothing is cached, we need to scan without forking. And
499 * if we fail to generate a cached repolist, we need to 499 * if we fail to generate a cached repolist, we need to
500 * invoke scan_tree manually. 500 * invoke scan_tree manually.
501 */ 501 */
502 if (generate_cached_repolist(path, cached_rc)) 502 if (generate_cached_repolist(path, cached_rc))
503 scan_tree(path); 503 scan_tree(path, repo_config);
504 return; 504 return;
505 } 505 }
506 506
507 parse_configfile(cached_rc, config_cb); 507 parse_configfile(cached_rc, config_cb);
508 508
509 /* If the cached configfile hasn't expired, lets exit now */ 509 /* If the cached configfile hasn't expired, lets exit now */
@@ -556,13 +556,13 @@ static void cgit_parse_args(int argc, const char **argv)
556 if (!strncmp(argv[i], "--ofs=", 6)) { 556 if (!strncmp(argv[i], "--ofs=", 6)) {
557 ctx.qry.ofs = atoi(argv[i]+6); 557 ctx.qry.ofs = atoi(argv[i]+6);
558 } 558 }
559 if (!strncmp(argv[i], "--scan-tree=", 12) || 559 if (!strncmp(argv[i], "--scan-tree=", 12) ||
560 !strncmp(argv[i], "--scan-path=", 12)) { 560 !strncmp(argv[i], "--scan-path=", 12)) {
561 scan++; 561 scan++;
562 scan_tree(argv[i] + 12); 562 scan_tree(argv[i] + 12, repo_config);
563 } 563 }
564 } 564 }
565 if (scan) { 565 if (scan) {
566 qsort(cgit_repolist.repos, cgit_repolist.count, 566 qsort(cgit_repolist.repos, cgit_repolist.count,
567 sizeof(struct cgit_repo), cmp_repos); 567 sizeof(struct cgit_repo), cmp_repos);
568 print_repolist(stdout, &cgit_repolist, 0); 568 print_repolist(stdout, &cgit_repolist, 0);
diff --git a/cgit.h b/cgit.h
index fc7c7d5..3359be9 100644
--- a/cgit.h
+++ b/cgit.h
@@ -76,12 +76,15 @@ struct cgit_repo {
76 time_t mtime; 76 time_t mtime;
77 struct cgit_filter *about_filter; 77 struct cgit_filter *about_filter;
78 struct cgit_filter *commit_filter; 78 struct cgit_filter *commit_filter;
79 struct cgit_filter *source_filter; 79 struct cgit_filter *source_filter;
80}; 80};
81 81
82typedef void (*repo_config_fn)(struct cgit_repo *repo, const char *name,
83 const char *value);
84
82struct cgit_repolist { 85struct cgit_repolist {
83 int length; 86 int length;
84 int count; 87 int count;
85 struct cgit_repo *repos; 88 struct cgit_repo *repos;
86}; 89};
87 90
diff --git a/cgitrc.5.txt b/cgitrc.5.txt
index e99c9f7..df494aa 100644
--- a/cgitrc.5.txt
+++ b/cgitrc.5.txt
@@ -323,12 +323,21 @@ repo.source-filter::
323 323
324repo.url:: 324repo.url::
325 The relative url used to access the repository. This must be the first 325 The relative url used to access the repository. This must be the first
326 setting specified for each repo. Default value: none. 326 setting specified for each repo. Default value: none.
327 327
328 328
329REPOSITORY-SPECIFIC CGITRC FILE
330-------------------------------
331When the option 'scan-path' is used to auto-discover git repositories, cgit
332will try to parse the file 'cgitrc' within any found repository. Such a repo-
333specific config file may contain any of the repo-specific options described
334above, except 'repo.url' and 'repo.path'. Also, in a repo-specific config
335file, the 'repo.' prefix is dropped from the config option names.
336
337
329EXAMPLE CGITRC FILE 338EXAMPLE CGITRC FILE
330------------------- 339-------------------
331 340
332.... 341....
333# Enable caching of up to 1000 output entriess 342# Enable caching of up to 1000 output entriess
334cache-size=1000 343cache-size=1000
diff --git a/scan-tree.c b/scan-tree.c
index 67f4550..dbca797 100644
--- a/scan-tree.c
+++ b/scan-tree.c
@@ -1,7 +1,8 @@
1#include "cgit.h" 1#include "cgit.h"
2#include "configfile.h"
2#include "html.h" 3#include "html.h"
3 4
4#define MAX_PATH 4096 5#define MAX_PATH 4096
5 6
6/* return 1 if path contains a objects/ directory and a HEAD file */ 7/* return 1 if path contains a objects/ directory and a HEAD file */
7static int is_git_dir(const char *path) 8static int is_git_dir(const char *path)
@@ -32,15 +33,22 @@ static int is_git_dir(const char *path)
32 if (!S_ISREG(st.st_mode)) 33 if (!S_ISREG(st.st_mode))
33 return 0; 34 return 0;
34 35
35 return 1; 36 return 1;
36} 37}
37 38
38static void add_repo(const char *base, const char *path) 39struct cgit_repo *repo;
40repo_config_fn config_fn;
41
42static void repo_config(const char *name, const char *value)
43{
44 config_fn(repo, name, value);
45}
46
47static void add_repo(const char *base, const char *path, repo_config_fn fn)
39{ 48{
40 struct cgit_repo *repo;
41 struct stat st; 49 struct stat st;
42 struct passwd *pwd; 50 struct passwd *pwd;
43 char *p; 51 char *p;
44 size_t size; 52 size_t size;
45 53
46 if (stat(path, &st)) { 54 if (stat(path, &st)) {
@@ -73,27 +81,33 @@ static void add_repo(const char *base, const char *path)
73 if (!stat(p, &st)) 81 if (!stat(p, &st))
74 readfile(p, &repo->desc, &size); 82 readfile(p, &repo->desc, &size);
75 83
76 p = fmt("%s/README.html", path); 84 p = fmt("%s/README.html", path);
77 if (!stat(p, &st)) 85 if (!stat(p, &st))
78 repo->readme = "README.html"; 86 repo->readme = "README.html";
87
88 p = fmt("%s/cgitrc", path);
89 if (!stat(p, &st)) {
90 config_fn = fn;
91 parse_configfile(xstrdup(p), &repo_config);
92 }
79} 93}
80 94
81static void scan_path(const char *base, const char *path) 95static void scan_path(const char *base, const char *path, repo_config_fn fn)
82{ 96{
83 DIR *dir; 97 DIR *dir;
84 struct dirent *ent; 98 struct dirent *ent;
85 char *buf; 99 char *buf;
86 struct stat st; 100 struct stat st;
87 101
88 if (is_git_dir(path)) { 102 if (is_git_dir(path)) {
89 add_repo(base, path); 103 add_repo(base, path, fn);
90 return; 104 return;
91 } 105 }
92 if (is_git_dir(fmt("%s/.git", path))) { 106 if (is_git_dir(fmt("%s/.git", path))) {
93 add_repo(base, fmt("%s/.git", path)); 107 add_repo(base, fmt("%s/.git", path), fn);
94 return; 108 return;
95 } 109 }
96 dir = opendir(path); 110 dir = opendir(path);
97 if (!dir) { 111 if (!dir) {
98 fprintf(stderr, "Error opening directory %s: %s (%d)\n", 112 fprintf(stderr, "Error opening directory %s: %s (%d)\n",
99 path, strerror(errno), errno); 113 path, strerror(errno), errno);
@@ -117,16 +131,16 @@ static void scan_path(const char *base, const char *path)
117 fprintf(stderr, "Error checking path %s: %s (%d)\n", 131 fprintf(stderr, "Error checking path %s: %s (%d)\n",
118 buf, strerror(errno), errno); 132 buf, strerror(errno), errno);
119 free(buf); 133 free(buf);
120 continue; 134 continue;
121 } 135 }
122 if (S_ISDIR(st.st_mode)) 136 if (S_ISDIR(st.st_mode))
123 scan_path(base, buf); 137 scan_path(base, buf, fn);
124 free(buf); 138 free(buf);
125 } 139 }
126 closedir(dir); 140 closedir(dir);
127} 141}
128 142
129void scan_tree(const char *path) 143void scan_tree(const char *path, repo_config_fn fn)
130{ 144{
131 scan_path(path, path); 145 scan_path(path, path, fn);
132} 146}
diff --git a/scan-tree.h b/scan-tree.h
index b103b16..11539f4 100644
--- a/scan-tree.h
+++ b/scan-tree.h
@@ -1,3 +1,3 @@
1 1
2 2
3extern void scan_tree(const char *path); 3extern void scan_tree(const char *path, repo_config_fn fn);