diff options
-rw-r--r-- | cgit.c | 8 | ||||
-rw-r--r-- | cgit.h | 3 | ||||
-rw-r--r-- | cgitrc.5.txt | 9 | ||||
-rw-r--r-- | scan-tree.c | 30 | ||||
-rw-r--r-- | scan-tree.h | 2 |
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 | |||
@@ -168,7 +168,7 @@ void config_cb(const char *name, const char *value) | |||
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")) |
@@ -476,7 +476,7 @@ static int generate_cached_repolist(const char *path, const char *cached_rc) | |||
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", |
@@ -500,7 +500,7 @@ static void process_cached_repolist(const char *path) | |||
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 | ||
@@ -559,7 +559,7 @@ static void cgit_parse_args(int argc, const char **argv) | |||
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) { |
diff --git a/cgit.h b/cgit.h index fc7c7d5..3359be9 100644 --- a/cgit.h +++ b/cgit.h | |||
@@ -79,6 +79,9 @@ struct cgit_repo { | |||
79 | struct cgit_filter *source_filter; | 79 | struct cgit_filter *source_filter; |
80 | }; | 80 | }; |
81 | 81 | ||
82 | typedef void (*repo_config_fn)(struct cgit_repo *repo, const char *name, | ||
83 | const char *value); | ||
84 | |||
82 | struct cgit_repolist { | 85 | struct cgit_repolist { |
83 | int length; | 86 | int length; |
84 | int count; | 87 | int count; |
diff --git a/cgitrc.5.txt b/cgitrc.5.txt index e99c9f7..df494aa 100644 --- a/cgitrc.5.txt +++ b/cgitrc.5.txt | |||
@@ -326,6 +326,15 @@ repo.url:: | |||
326 | setting specified for each repo. Default value: none. | 326 | setting specified for each repo. Default value: none. |
327 | 327 | ||
328 | 328 | ||
329 | REPOSITORY-SPECIFIC CGITRC FILE | ||
330 | ------------------------------- | ||
331 | When the option 'scan-path' is used to auto-discover git repositories, cgit | ||
332 | will try to parse the file 'cgitrc' within any found repository. Such a repo- | ||
333 | specific config file may contain any of the repo-specific options described | ||
334 | above, except 'repo.url' and 'repo.path'. Also, in a repo-specific config | ||
335 | file, the 'repo.' prefix is dropped from the config option names. | ||
336 | |||
337 | |||
329 | EXAMPLE CGITRC FILE | 338 | EXAMPLE CGITRC FILE |
330 | ------------------- | 339 | ------------------- |
331 | 340 | ||
diff --git a/scan-tree.c b/scan-tree.c index 67f4550..dbca797 100644 --- a/scan-tree.c +++ b/scan-tree.c | |||
@@ -1,4 +1,5 @@ | |||
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 |
@@ -35,9 +36,16 @@ static int is_git_dir(const char *path) | |||
35 | return 1; | 36 | return 1; |
36 | } | 37 | } |
37 | 38 | ||
38 | static void add_repo(const char *base, const char *path) | 39 | struct cgit_repo *repo; |
40 | repo_config_fn config_fn; | ||
41 | |||
42 | static void repo_config(const char *name, const char *value) | ||
43 | { | ||
44 | config_fn(repo, name, value); | ||
45 | } | ||
46 | |||
47 | static 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; |
@@ -76,9 +84,15 @@ static void add_repo(const char *base, const char *path) | |||
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 | ||
81 | static void scan_path(const char *base, const char *path) | 95 | static 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; |
@@ -86,11 +100,11 @@ static void scan_path(const char *base, const char *path) | |||
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); |
@@ -120,13 +134,13 @@ static void scan_path(const char *base, const char *path) | |||
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 | ||
129 | void scan_tree(const char *path) | 143 | void 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 | ||
3 | extern void scan_tree(const char *path); | 3 | extern void scan_tree(const char *path, repo_config_fn fn); |