-rw-r--r-- | scan-tree.c | 30 |
1 files changed, 22 insertions, 8 deletions
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 | } |