summaryrefslogtreecommitdiffabout
path: root/scan-tree.c
authorJason A. Donenfeld <Jason@zx2c4.com>2010-07-29 15:52:29 (UTC)
committer Lars Hjemli <hjemli@gmail.com>2010-08-04 01:09:32 (UTC)
commit3516502aa0df95ecc241caa30161741f59e4e600 (patch) (unidiff)
tree345978808d18796444729f74eb139c8289bcb1c2 /scan-tree.c
parentf9143171267e39f66a02ad2ecb0da2e8cc7f4142 (diff)
downloadcgit-3516502aa0df95ecc241caa30161741f59e4e600.zip
cgit-3516502aa0df95ecc241caa30161741f59e4e600.tar.gz
cgit-3516502aa0df95ecc241caa30161741f59e4e600.tar.bz2
Add support for 'project-list' option
This option specifies the location of a projectlist file as used by gitweb - when 'scan-tree' is later specified, only the projects listed in the projectlist file will be added. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> Signed-off-by: Lars Hjemli <hjemli@gmail.com>
Diffstat (limited to 'scan-tree.c') (more/less context) (ignore whitespace changes)
-rw-r--r--scan-tree.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/scan-tree.c b/scan-tree.c
index 1e18f3c..9bf9b38 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"
@@ -142,6 +151,34 @@ static void scan_path(const char *base, const char *path, repo_config_fn fn)
142 closedir(dir); 151 closedir(dir);
143} 152}
144 153
154#define lastc(s) s[strlen(s) - 1]
155
156void scan_projects(const char *path, const char *projectsfile, repo_config_fn fn)
157{
158 char line[MAX_PATH * 2], *z;
159 FILE *projects;
160 int err;
161
162 projects = fopen(projectsfile, "r");
163 if (!projects) {
164 fprintf(stderr, "Error opening projectsfile %s: %s (%d)\n",
165 projectsfile, strerror(errno), errno);
166 }
167 while (fgets(line, sizeof(line), projects) != NULL) {
168 for (z = &lastc(line);
169 strlen(line) && strchr("\n\r", *z);
170 z = &lastc(line))
171 *z = '\0';
172 if (strlen(line))
173 scan_path(path, fmt("%s/%s", path, line), fn);
174 }
175 if ((err = ferror(projects))) {
176 fprintf(stderr, "Error reading from projectsfile %s: %s (%d)\n",
177 projectsfile, strerror(err), err);
178 }
179 fclose(projects);
180}
181
145void scan_tree(const char *path, repo_config_fn fn) 182void scan_tree(const char *path, repo_config_fn fn)
146{ 183{
147 scan_path(path, path, fn); 184 scan_path(path, path, fn);