Skip to content

Commit 3516502

Browse files
zx2c4hjemli
authored andcommitted
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 <[email protected]> Signed-off-by: Lars Hjemli <[email protected]>
1 parent f914317 commit 3516502

File tree

5 files changed

+70
-8
lines changed

5 files changed

+70
-8
lines changed

cgit.c

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,14 @@ void config_cb(const char *name, const char *value)
181181
ctx.cfg.max_repo_count = atoi(value);
182182
else if (!strcmp(name, "max-commit-count"))
183183
ctx.cfg.max_commit_count = atoi(value);
184+
else if (!strcmp(name, "project-list"))
185+
ctx.cfg.project_list = xstrdup(expand_macros(value));
184186
else if (!strcmp(name, "scan-path"))
185187
if (!ctx.cfg.nocache && ctx.cfg.cache_size)
186188
process_cached_repolist(expand_macros(value));
189+
else if (ctx.cfg.project_list)
190+
scan_projects(expand_macros(value),
191+
ctx.cfg.project_list, repo_config);
187192
else
188193
scan_tree(expand_macros(value), repo_config);
189194
else if (!strcmp(name, "source-filter"))
@@ -295,6 +300,7 @@ static void prepare_context(struct cgit_context *ctx)
295300
ctx->cfg.max_blob_size = 0;
296301
ctx->cfg.max_stats = 0;
297302
ctx->cfg.module_link = "./?repo=%s&page=commit&id=%s";
303+
ctx->cfg.project_list = NULL;
298304
ctx->cfg.renamelimit = -1;
299305
ctx->cfg.robots = "index, nofollow";
300306
ctx->cfg.root_title = "Git repository browser";
@@ -574,7 +580,10 @@ static int generate_cached_repolist(const char *path, const char *cached_rc)
574580
return errno;
575581
}
576582
idx = cgit_repolist.count;
577-
scan_tree(path, repo_config);
583+
if (ctx.cfg.project_list)
584+
scan_projects(path, ctx.cfg.project_list, repo_config);
585+
else
586+
scan_tree(path, repo_config);
578587
print_repolist(f, &cgit_repolist, idx);
579588
if (rename(locked_rc, cached_rc))
580589
fprintf(stderr, "[cgit] Error renaming %s to %s: %s (%d)\n",
@@ -588,17 +597,25 @@ static void process_cached_repolist(const char *path)
588597
struct stat st;
589598
char *cached_rc;
590599
time_t age;
600+
unsigned long hash;
591601

592-
cached_rc = xstrdup(fmt("%s/rc-%8x", ctx.cfg.cache_root,
593-
hash_str(path)));
602+
hash = hash_str(path);
603+
if (ctx.cfg.project_list)
604+
hash += hash_str(ctx.cfg.project_list);
605+
cached_rc = xstrdup(fmt("%s/rc-%8x", ctx.cfg.cache_root, hash));
594606

595607
if (stat(cached_rc, &st)) {
596608
/* Nothing is cached, we need to scan without forking. And
597609
* if we fail to generate a cached repolist, we need to
598610
* invoke scan_tree manually.
599611
*/
600-
if (generate_cached_repolist(path, cached_rc))
601-
scan_tree(path, repo_config);
612+
if (generate_cached_repolist(path, cached_rc)) {
613+
if (ctx.cfg.project_list)
614+
scan_projects(path, ctx.cfg.project_list,
615+
repo_config);
616+
else
617+
scan_tree(path, repo_config);
618+
}
602619
return;
603620
}
604621

cgit.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ struct cgit_config {
166166
char *logo;
167167
char *logo_link;
168168
char *module_link;
169+
char *project_list;
169170
char *robots;
170171
char *root_title;
171172
char *root_desc;

cgitrc.5.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,11 @@ noheader::
224224
Flag which, when set to "1", will make cgit omit the standard header
225225
on all pages. Default value: none. See also: "embedded".
226226

227+
project-list::
228+
A list of subdirectories inside of scan-path, relative to it, that
229+
should loaded as git repositories. This must be defined prior to
230+
scan-path. Default value: none. See also: scan-path.
231+
227232
renamelimit::
228233
Maximum number of files to consider when detecting renames. The value
229234
"-1" uses the compiletime value in git (for further info, look at
@@ -253,7 +258,10 @@ root-title::
253258
scan-path::
254259
A path which will be scanned for repositories. If caching is enabled,
255260
the result will be cached as a cgitrc include-file in the cache
256-
directory. Default value: none. See also: cache-scanrc-ttl.
261+
directory. If project-list has been defined prior to scan-path,
262+
scan-path loads only the directories listed in the file pointed to by
263+
project-list. Default value: none. See also: cache-scanrc-ttl,
264+
project-list.
257265

258266
section::
259267
The name of the current repository section - all repositories defined

scan-tree.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
/* scan-tree.c
2+
*
3+
* Copyright (C) 2008-2009 Lars Hjemli
4+
* Copyright (C) 2010 Jason A. Donenfeld <[email protected]>
5+
*
6+
* Licensed under GNU General Public License v2
7+
* (see COPYING for full license text)
8+
*/
9+
110
#include "cgit.h"
211
#include "configfile.h"
312
#include "html.h"
@@ -142,6 +151,34 @@ static void scan_path(const char *base, const char *path, repo_config_fn fn)
142151
closedir(dir);
143152
}
144153

154+
#define lastc(s) s[strlen(s) - 1]
155+
156+
void 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+
145182
void scan_tree(const char *path, repo_config_fn fn)
146183
{
147184
scan_path(path, path, fn);

scan-tree.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
2-
1+
extern void scan_projects(const char *path, const char *projectsfile, repo_config_fn fn);
32
extern void scan_tree(const char *path, repo_config_fn fn);

0 commit comments

Comments
 (0)