diff options
author | Lars Hjemli <hjemli@gmail.com> | 2009-09-14 05:02:07 (JST) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2009-09-14 05:02:07 (JST) |
commit | 92f6940975f6771f3a08d497c02575ee5bdc79da (patch) | |
tree | c1c538b24e50be3bf63356acf246cda76b91c519 /scan-tree.c | |
parent | 5f12e45fe3338095916a444ff106dd9fc9991d84 (diff) | |
parent | ee554849ac7209fa8f7486327ec9f3b370e4c876 (diff) | |
download | cgit-92f6940975f6771f3a08d497c02575ee5bdc79da.zip cgit-92f6940975f6771f3a08d497c02575ee5bdc79da.tar.gz |
Merge branch 'lh/repo-scan'
Diffstat (limited to 'scan-tree.c')
-rw-r--r-- | scan-tree.c | 32 |
1 files changed, 25 insertions, 7 deletions
diff --git a/scan-tree.c b/scan-tree.c index 4da21a4..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,7 +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); |
104 | return; | ||
105 | } | ||
106 | if (is_git_dir(fmt("%s/.git", path))) { | ||
107 | add_repo(base, fmt("%s/.git", path), fn); | ||
90 | return; | 108 | return; |
91 | } | 109 | } |
92 | dir = opendir(path); | 110 | dir = opendir(path); |
@@ -116,13 +134,13 @@ static void scan_path(const char *base, const char *path) | |||
116 | continue; | 134 | continue; |
117 | } | 135 | } |
118 | if (S_ISDIR(st.st_mode)) | 136 | if (S_ISDIR(st.st_mode)) |
119 | scan_path(base, buf); | 137 | scan_path(base, buf, fn); |
120 | free(buf); | 138 | free(buf); |
121 | } | 139 | } |
122 | closedir(dir); | 140 | closedir(dir); |
123 | } | 141 | } |
124 | 142 | ||
125 | void scan_tree(const char *path) | 143 | void scan_tree(const char *path, repo_config_fn fn) |
126 | { | 144 | { |
127 | scan_path(path, path); | 145 | scan_path(path, path, fn); |
128 | } | 146 | } |