aboutsummaryrefslogtreecommitdiffstats
path: root/scan-tree.c
diff options
context:
space:
mode:
Diffstat (limited to 'scan-tree.c')
-rw-r--r--scan-tree.c45
1 files changed, 27 insertions, 18 deletions
diff --git a/scan-tree.c b/scan-tree.c
index 47f3988..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,25 +36,20 @@ static int is_git_dir(const char *path)
35 return 1; 36 return 1;
36} 37}
37 38
38char *readfile(const char *path) 39struct cgit_repo *repo;
39{ 40repo_config_fn config_fn;
40 FILE *f;
41 static char buf[MAX_PATH];
42 41
43 if (!(f = fopen(path, "r"))) 42static void repo_config(const char *name, const char *value)
44 return NULL; 43{
45 buf[0] = 0; 44 config_fn(repo, name, value);
46 fgets(buf, MAX_PATH, f);
47 fclose(f);
48 return buf;
49} 45}
50 46
51static void add_repo(const char *base, const char *path) 47static void add_repo(const char *base, const char *path, repo_config_fn fn)
52{ 48{
53 struct cgit_repo *repo;
54 struct stat st; 49 struct stat st;
55 struct passwd *pwd; 50 struct passwd *pwd;
56 char *p; 51 char *p;
52 size_t size;
57 53
58 if (stat(path, &st)) { 54 if (stat(path, &st)) {
59 fprintf(stderr, "Error accessing %s: %s (%d)\n", 55 fprintf(stderr, "Error accessing %s: %s (%d)\n",
@@ -76,18 +72,27 @@ static void add_repo(const char *base, const char *path)
76 repo = cgit_add_repo(xstrdup(p)); 72 repo = cgit_add_repo(xstrdup(p));
77 repo->name = repo->url; 73 repo->name = repo->url;
78 repo->path = xstrdup(path); 74 repo->path = xstrdup(path);
75 p = (pwd && pwd->pw_gecos) ? strchr(pwd->pw_gecos, ',') : NULL;
76 if (p)
77 *p = '\0';
79 repo->owner = (pwd ? xstrdup(pwd->pw_gecos ? pwd->pw_gecos : pwd->pw_name) : ""); 78 repo->owner = (pwd ? xstrdup(pwd->pw_gecos ? pwd->pw_gecos : pwd->pw_name) : "");
80 79
81 p = fmt("%s/description", path); 80 p = fmt("%s/description", path);
82 if (!stat(p, &st)) 81 if (!stat(p, &st))
83 repo->desc = xstrdup(readfile(p)); 82 readfile(p, &repo->desc, &size);
84 83
85 p = fmt("%s/README.html", path); 84 p = fmt("%s/README.html", path);
86 if (!stat(p, &st)) 85 if (!stat(p, &st))
87 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 }
88} 93}
89 94
90static void scan_path(const char *base, const char *path) 95static void scan_path(const char *base, const char *path, repo_config_fn fn)
91{ 96{
92 DIR *dir; 97 DIR *dir;
93 struct dirent *ent; 98 struct dirent *ent;
@@ -95,7 +100,11 @@ static void scan_path(const char *base, const char *path)
95 struct stat st; 100 struct stat st;
96 101
97 if (is_git_dir(path)) { 102 if (is_git_dir(path)) {
98 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);
99 return; 108 return;
100 } 109 }
101 dir = opendir(path); 110 dir = opendir(path);
@@ -125,13 +134,13 @@ static void scan_path(const char *base, const char *path)
125 continue; 134 continue;
126 } 135 }
127 if (S_ISDIR(st.st_mode)) 136 if (S_ISDIR(st.st_mode))
128 scan_path(base, buf); 137 scan_path(base, buf, fn);
129 free(buf); 138 free(buf);
130 } 139 }
131 closedir(dir); 140 closedir(dir);
132} 141}
133 142
134void scan_tree(const char *path) 143void scan_tree(const char *path, repo_config_fn fn)
135{ 144{
136 scan_path(path, path); 145 scan_path(path, path, fn);
137} 146}