author | Lars Hjemli <hjemli@gmail.com> | 2009-08-23 22:04:58 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2009-08-24 08:22:58 (UTC) |
commit | 74061ed5f03e72796450aa3b8ca1cf6ced5d59e2 (patch) (unidiff) | |
tree | 235ab2c29c027f19b00da815af3bf1d2856edc21 | |
parent | a1b3938f711c9b0e5eedad1678535e5779da82c1 (diff) | |
download | cgit-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>
-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
@@ -170,3 +170,3 @@ void config_cb(const char *name, const char *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")) |
@@ -478,3 +478,3 @@ static int generate_cached_repolist(const char *path, const char *cached_rc) | |||
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); |
@@ -502,3 +502,3 @@ static void process_cached_repolist(const char *path) | |||
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; |
@@ -561,3 +561,3 @@ static void cgit_parse_args(int argc, const char **argv) | |||
561 | scan++; | 561 | scan++; |
562 | scan_tree(argv[i] + 12); | 562 | scan_tree(argv[i] + 12, repo_config); |
563 | } | 563 | } |
@@ -81,2 +81,5 @@ struct cgit_repo { | |||
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 { |
diff --git a/cgitrc.5.txt b/cgitrc.5.txt index e99c9f7..df494aa 100644 --- a/cgitrc.5.txt +++ b/cgitrc.5.txt | |||
@@ -328,2 +328,11 @@ repo.url:: | |||
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 |
diff --git a/scan-tree.c b/scan-tree.c index 67f4550..dbca797 100644 --- a/scan-tree.c +++ b/scan-tree.c | |||
@@ -1,2 +1,3 @@ | |||
1 | #include "cgit.h" | 1 | #include "cgit.h" |
2 | #include "configfile.h" | ||
2 | #include "html.h" | 3 | #include "html.h" |
@@ -37,5 +38,12 @@ static int is_git_dir(const char *path) | |||
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; |
@@ -78,5 +86,11 @@ static void add_repo(const char *base, const char *path) | |||
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 | { |
@@ -88,3 +102,3 @@ static void scan_path(const char *base, const char *path) | |||
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; |
@@ -92,3 +106,3 @@ static void scan_path(const char *base, const char *path) | |||
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; |
@@ -122,3 +136,3 @@ static void scan_path(const char *base, const char *path) | |||
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); |
@@ -128,5 +142,5 @@ static void scan_path(const char *base, const char *path) | |||
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 | |||
@@ -2,2 +2,2 @@ | |||
2 | 2 | ||
3 | extern void scan_tree(const char *path); | 3 | extern void scan_tree(const char *path, repo_config_fn fn); |