summaryrefslogtreecommitdiffabout
path: root/scan-tree.c
Side-by-side diff
Diffstat (limited to 'scan-tree.c') (more/less context) (ignore whitespace changes)
-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,2 +1,3 @@
#include "cgit.h"
+#include "configfile.h"
#include "html.h"
@@ -37,18 +38,12 @@ static int is_git_dir(const char *path)
-char *readfile(const char *path)
-{
- FILE *f;
- static char buf[MAX_PATH];
+struct cgit_repo *repo;
+repo_config_fn config_fn;
- if (!(f = fopen(path, "r")))
- return NULL;
- buf[0] = 0;
- fgets(buf, MAX_PATH, f);
- fclose(f);
- return buf;
+static void repo_config(const char *name, const char *value)
+{
+ config_fn(repo, name, value);
}
-static void add_repo(const char *base, const char *path)
+static void add_repo(const char *base, const char *path, repo_config_fn fn)
{
- struct cgit_repo *repo;
struct stat st;
@@ -56,2 +51,3 @@ static void add_repo(const char *base, const char *path)
char *p;
+ size_t size;
@@ -78,2 +74,5 @@ static void add_repo(const char *base, const char *path)
repo->path = xstrdup(path);
+ p = (pwd && pwd->pw_gecos) ? strchr(pwd->pw_gecos, ',') : NULL;
+ if (p)
+ *p = '\0';
repo->owner = (pwd ? xstrdup(pwd->pw_gecos ? pwd->pw_gecos : pwd->pw_name) : "");
@@ -82,3 +81,3 @@ static void add_repo(const char *base, const char *path)
if (!stat(p, &st))
- repo->desc = xstrdup(readfile(p));
+ readfile(p, &repo->desc, &size);
@@ -87,5 +86,11 @@ static void add_repo(const char *base, const char *path)
repo->readme = "README.html";
+
+ p = fmt("%s/cgitrc", path);
+ if (!stat(p, &st)) {
+ config_fn = fn;
+ parse_configfile(xstrdup(p), &repo_config);
+ }
}
-static void scan_path(const char *base, const char *path)
+static void scan_path(const char *base, const char *path, repo_config_fn fn)
{
@@ -97,3 +102,7 @@ static void scan_path(const char *base, const char *path)
if (is_git_dir(path)) {
- add_repo(base, path);
+ add_repo(base, path, fn);
+ return;
+ }
+ if (is_git_dir(fmt("%s/.git", path))) {
+ add_repo(base, fmt("%s/.git", path), fn);
return;
@@ -127,3 +136,3 @@ static void scan_path(const char *base, const char *path)
if (S_ISDIR(st.st_mode))
- scan_path(base, buf);
+ scan_path(base, buf, fn);
free(buf);
@@ -133,5 +142,5 @@ static void scan_path(const char *base, const char *path)
-void scan_tree(const char *path)
+void scan_tree(const char *path, repo_config_fn fn)
{
- scan_path(path, path);
+ scan_path(path, path, fn);
}