summaryrefslogtreecommitdiffabout
path: root/scan-tree.c
Unidiff
Diffstat (limited to 'scan-tree.c') (more/less context) (show whitespace changes)
-rw-r--r--scan-tree.c32
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,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)
39{
40 struct cgit_repo *repo; 39 struct 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)
48{
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,23 +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);
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);
93 if (!dir) { 111 if (!dir) {
94 fprintf(stderr, "Error opening directory %s: %s (%d)\n", 112 fprintf(stderr, "Error opening directory %s: %s (%d)\n",
95 path, strerror(errno), errno); 113 path, strerror(errno), errno);
@@ -113,16 +131,16 @@ static void scan_path(const char *base, const char *path)
113 fprintf(stderr, "Error checking path %s: %s (%d)\n", 131 fprintf(stderr, "Error checking path %s: %s (%d)\n",
114 buf, strerror(errno), errno); 132 buf, strerror(errno), errno);
115 free(buf); 133 free(buf);
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
125void scan_tree(const char *path) 143void scan_tree(const char *path, repo_config_fn fn)
126{ 144{
127 scan_path(path, path); 145 scan_path(path, path, fn);
128} 146}