Diffstat (limited to 'scan-tree.c')
| -rw-r--r-- | scan-tree.c | 45 |
1 files changed, 18 insertions, 27 deletions
diff --git a/scan-tree.c b/scan-tree.c index dbca797..47f3988 100644 --- a/scan-tree.c +++ b/scan-tree.c @@ -1,5 +1,4 @@ #include "cgit.h" -#include "configfile.h" #include "html.h" #define MAX_PATH 4096 @@ -36,20 +35,25 @@ static int is_git_dir(const char *path) return 1; } -struct cgit_repo *repo; -repo_config_fn config_fn; - -static void repo_config(const char *name, const char *value) +char *readfile(const char *path) { - config_fn(repo, name, value); + FILE *f; + static char buf[MAX_PATH]; + + if (!(f = fopen(path, "r"))) + return NULL; + buf[0] = 0; + fgets(buf, MAX_PATH, f); + fclose(f); + return buf; } -static void add_repo(const char *base, const char *path, repo_config_fn fn) +static void add_repo(const char *base, const char *path) { + struct cgit_repo *repo; struct stat st; struct passwd *pwd; char *p; - size_t size; if (stat(path, &st)) { fprintf(stderr, "Error accessing %s: %s (%d)\n", @@ -72,27 +76,18 @@ static void add_repo(const char *base, const char *path, repo_config_fn fn) repo = cgit_add_repo(xstrdup(p)); repo->name = repo->url; 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) : ""); p = fmt("%s/description", path); if (!stat(p, &st)) - readfile(p, &repo->desc, &size); + repo->desc = xstrdup(readfile(p)); p = fmt("%s/README.html", path); if (!stat(p, &st)) 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, repo_config_fn fn) +static void scan_path(const char *base, const char *path) { DIR *dir; struct dirent *ent; @@ -100,11 +95,7 @@ static void scan_path(const char *base, const char *path, repo_config_fn fn) struct stat st; if (is_git_dir(path)) { - add_repo(base, path, fn); - return; - } - if (is_git_dir(fmt("%s/.git", path))) { - add_repo(base, fmt("%s/.git", path), fn); + add_repo(base, path); return; } dir = opendir(path); @@ -134,13 +125,13 @@ static void scan_path(const char *base, const char *path, repo_config_fn fn) continue; } if (S_ISDIR(st.st_mode)) - scan_path(base, buf, fn); + scan_path(base, buf); free(buf); } closedir(dir); } -void scan_tree(const char *path, repo_config_fn fn) +void scan_tree(const char *path) { - scan_path(path, path, fn); + scan_path(path, path); } |