diff options
Diffstat (limited to 'scan-tree.c')
-rw-r--r-- | scan-tree.c | 73 |
1 files changed, 65 insertions, 8 deletions
diff --git a/scan-tree.c b/scan-tree.c index dbca797..e987824 100644 --- a/scan-tree.c +++ b/scan-tree.c | |||
@@ -1,3 +1,12 @@ | |||
1 | /* scan-tree.c | ||
2 | * | ||
3 | * Copyright (C) 2008-2009 Lars Hjemli | ||
4 | * Copyright (C) 2010 Jason A. Donenfeld <Jason@zx2c4.com> | ||
5 | * | ||
6 | * Licensed under GNU General Public License v2 | ||
7 | * (see COPYING for full license text) | ||
8 | */ | ||
9 | |||
1 | #include "cgit.h" | 10 | #include "cgit.h" |
2 | #include "configfile.h" | 11 | #include "configfile.h" |
3 | #include "html.h" | 12 | #include "html.h" |
@@ -38,12 +47,20 @@ static int is_git_dir(const char *path) | |||
38 | 47 | ||
39 | struct cgit_repo *repo; | 48 | struct cgit_repo *repo; |
40 | repo_config_fn config_fn; | 49 | repo_config_fn config_fn; |
50 | char *owner; | ||
41 | 51 | ||
42 | static void repo_config(const char *name, const char *value) | 52 | static void repo_config(const char *name, const char *value) |
43 | { | 53 | { |
44 | config_fn(repo, name, value); | 54 | config_fn(repo, name, value); |
45 | } | 55 | } |
46 | 56 | ||
57 | static int git_owner_config(const char *key, const char *value, void *cb) | ||
58 | { | ||
59 | if (!strcmp(key, "gitweb.owner")) | ||
60 | owner = xstrdup(value); | ||
61 | return 0; | ||
62 | } | ||
63 | |||
47 | static void add_repo(const char *base, const char *path, repo_config_fn fn) | 64 | static void add_repo(const char *base, const char *path, repo_config_fn fn) |
48 | { | 65 | { |
49 | struct stat st; | 66 | struct stat st; |
@@ -56,11 +73,12 @@ static void add_repo(const char *base, const char *path, repo_config_fn fn) | |||
56 | path, strerror(errno), errno); | 73 | path, strerror(errno), errno); |
57 | return; | 74 | return; |
58 | } | 75 | } |
59 | if ((pwd = getpwuid(st.st_uid)) == NULL) { | 76 | if (!stat(fmt("%s/noweb", path), &st)) |
60 | fprintf(stderr, "Error reading owner-info for %s: %s (%d)\n", | ||
61 | path, strerror(errno), errno); | ||
62 | return; | 77 | return; |
63 | } | 78 | |
79 | owner = NULL; | ||
80 | if (ctx.cfg.enable_gitweb_owner) | ||
81 | git_config_from_file(git_owner_config, fmt("%s/config", path), NULL); | ||
64 | if (base == path) | 82 | if (base == path) |
65 | p = fmt("%s", path); | 83 | p = fmt("%s", path); |
66 | else | 84 | else |
@@ -70,12 +88,23 @@ static void add_repo(const char *base, const char *path, repo_config_fn fn) | |||
70 | p[strlen(p) - 5] = '\0'; | 88 | p[strlen(p) - 5] = '\0'; |
71 | 89 | ||
72 | repo = cgit_add_repo(xstrdup(p)); | 90 | repo = cgit_add_repo(xstrdup(p)); |
91 | if (ctx.cfg.remove_suffix) | ||
92 | if ((p = strrchr(repo->url, '.')) && !strcmp(p, ".git")) | ||
93 | *p = '\0'; | ||
73 | repo->name = repo->url; | 94 | repo->name = repo->url; |
74 | repo->path = xstrdup(path); | 95 | repo->path = xstrdup(path); |
75 | p = (pwd && pwd->pw_gecos) ? strchr(pwd->pw_gecos, ',') : NULL; | 96 | while (!owner) { |
76 | if (p) | 97 | if ((pwd = getpwuid(st.st_uid)) == NULL) { |
77 | *p = '\0'; | 98 | fprintf(stderr, "Error reading owner-info for %s: %s (%d)\n", |
78 | repo->owner = (pwd ? xstrdup(pwd->pw_gecos ? pwd->pw_gecos : pwd->pw_name) : ""); | 99 | path, strerror(errno), errno); |
100 | break; | ||
101 | } | ||
102 | if (pwd->pw_gecos) | ||
103 | if ((p = strchr(pwd->pw_gecos, ','))) | ||
104 | *p = '\0'; | ||
105 | owner = xstrdup(pwd->pw_gecos ? pwd->pw_gecos : pwd->pw_name); | ||
106 | } | ||
107 | repo->owner = owner; | ||
79 | 108 | ||
80 | p = fmt("%s/description", path); | 109 | p = fmt("%s/description", path); |
81 | if (!stat(p, &st)) | 110 | if (!stat(p, &st)) |
@@ -140,6 +169,34 @@ static void scan_path(const char *base, const char *path, repo_config_fn fn) | |||
140 | closedir(dir); | 169 | closedir(dir); |
141 | } | 170 | } |
142 | 171 | ||
172 | #define lastc(s) s[strlen(s) - 1] | ||
173 | |||
174 | void scan_projects(const char *path, const char *projectsfile, repo_config_fn fn) | ||
175 | { | ||
176 | char line[MAX_PATH * 2], *z; | ||
177 | FILE *projects; | ||
178 | int err; | ||
179 | |||
180 | projects = fopen(projectsfile, "r"); | ||
181 | if (!projects) { | ||
182 | fprintf(stderr, "Error opening projectsfile %s: %s (%d)\n", | ||
183 | projectsfile, strerror(errno), errno); | ||
184 | } | ||
185 | while (fgets(line, sizeof(line), projects) != NULL) { | ||
186 | for (z = &lastc(line); | ||
187 | strlen(line) && strchr("\n\r", *z); | ||
188 | z = &lastc(line)) | ||
189 | *z = '\0'; | ||
190 | if (strlen(line)) | ||
191 | scan_path(path, fmt("%s/%s", path, line), fn); | ||
192 | } | ||
193 | if ((err = ferror(projects))) { | ||
194 | fprintf(stderr, "Error reading from projectsfile %s: %s (%d)\n", | ||
195 | projectsfile, strerror(err), err); | ||
196 | } | ||
197 | fclose(projects); | ||
198 | } | ||
199 | |||
143 | void scan_tree(const char *path, repo_config_fn fn) | 200 | void scan_tree(const char *path, repo_config_fn fn) |
144 | { | 201 | { |
145 | scan_path(path, path, fn); | 202 | scan_path(path, path, fn); |