aboutsummaryrefslogtreecommitdiff
path: root/cgit.c
diff options
context:
space:
mode:
authorLars Hjemli <hjemli@gmail.com>2008-09-15 00:07:12 +0200
committerLars Hjemli <hjemli@gmail.com>2008-09-15 23:35:27 +0200
commit93397a765b9d9af11b7d10c114406e303ea4fb1c (patch)
treefa40c0c8df7549525123359bf817598ae7e9f43d /cgit.c
parente154edd8078020d6eba41b448afade0a68617f35 (diff)
downloadcgit-93397a765b9d9af11b7d10c114406e303ea4fb1c.tar.gz
cgit-93397a765b9d9af11b7d10c114406e303ea4fb1c.tar.bz2
cgit-93397a765b9d9af11b7d10c114406e303ea4fb1c.zip
Add support for --scan-tree=<path> option to cgit
This option makes cgit scan a directory tree looking for git repositories, generating suitable definitions for a cgitrc file on stdout. Signed-off-by: Lars Hjemli <hjemli@gmail.com>
Diffstat (limited to 'cgit.c')
-rw-r--r--cgit.c47
1 files changed, 44 insertions, 3 deletions
diff --git a/cgit.c b/cgit.c
index a47cad0..5a93fcd 100644
--- a/cgit.c
+++ b/cgit.c
@@ -12,6 +12,7 @@
#include "configfile.h"
#include "html.h"
#include "ui-shared.h"
+#include "scan-tree.h"
const char *cgit_version = CGIT_VERSION;
@@ -320,9 +321,39 @@ static void process_request(void *cbdata)
cgit_print_docend();
}
+int cmp_repos(const void *a, const void *b)
+{
+ const struct cgit_repo *ra = a, *rb = b;
+ return strcmp(ra->url, rb->url);
+}
+
+void print_repo(struct cgit_repo *repo)
+{
+ printf("repo.url=%s\n", repo->url);
+ printf("repo.name=%s\n", repo->name);
+ printf("repo.path=%s\n", repo->path);
+ if (repo->owner)
+ printf("repo.owner=%s\n", repo->owner);
+ if (repo->desc)
+ printf("repo.desc=%s\n", repo->desc);
+ if (repo->readme)
+ printf("repo.readme=%s\n", repo->readme);
+ printf("\n");
+}
+
+void print_repolist(struct cgit_repolist *list)
+{
+ int i;
+
+ for(i = 0; i < list->count; i++)
+ print_repo(&list->repos[i]);
+}
+
+
static void cgit_parse_args(int argc, const char **argv)
{
int i;
+ int scan = 0;
for (i = 1; i < argc; i++) {
if (!strncmp(argv[i], "--cache=", 8)) {
@@ -351,6 +382,16 @@ static void cgit_parse_args(int argc, const char **argv)
if (!strncmp(argv[i], "--ofs=", 6)) {
ctx.qry.ofs = atoi(argv[i]+6);
}
+ if (!strncmp(argv[i], "--scan-tree=", 12)) {
+ scan++;
+ scan_tree(argv[i] + 12);
+ }
+ }
+ if (scan) {
+ qsort(cgit_repolist.repos, cgit_repolist.count,
+ sizeof(struct cgit_repo), cmp_repos);
+ print_repolist(&cgit_repolist);
+ exit(0);
}
}
@@ -383,14 +424,14 @@ int main(int argc, const char **argv)
cgit_repolist.count = 0;
cgit_repolist.repos = NULL;
- parse_configfile(cgit_config_env ? cgit_config_env : CGIT_CONFIG,
- config_cb);
- ctx.repo = NULL;
if (getenv("SCRIPT_NAME"))
ctx.cfg.script_name = xstrdup(getenv("SCRIPT_NAME"));
if (getenv("QUERY_STRING"))
ctx.qry.raw = xstrdup(getenv("QUERY_STRING"));
cgit_parse_args(argc, argv);
+ parse_configfile(cgit_config_env ? cgit_config_env : CGIT_CONFIG,
+ config_cb);
+ ctx.repo = NULL;
http_parse_querystring(ctx.qry.raw, querystring_cb);
/* If virtual-root isn't specified in cgitrc and no url