summaryrefslogtreecommitdiffabout
path: root/scan-tree.c
Unidiff
Diffstat (limited to 'scan-tree.c') (more/less context) (ignore whitespace changes)
-rw-r--r--scan-tree.c33
1 files changed, 24 insertions, 9 deletions
diff --git a/scan-tree.c b/scan-tree.c
index a83a78c..e987824 100644
--- a/scan-tree.c
+++ b/scan-tree.c
@@ -38,67 +38,82 @@ static int is_git_dir(const char *path)
38 fprintf(stderr, "Error checking path %s: %s (%d)\n", 38 fprintf(stderr, "Error checking path %s: %s (%d)\n",
39 path, strerror(errno), errno); 39 path, strerror(errno), errno);
40 return 0; 40 return 0;
41 } 41 }
42 if (!S_ISREG(st.st_mode)) 42 if (!S_ISREG(st.st_mode))
43 return 0; 43 return 0;
44 44
45 return 1; 45 return 1;
46} 46}
47 47
48struct cgit_repo *repo; 48struct cgit_repo *repo;
49repo_config_fn config_fn; 49repo_config_fn config_fn;
50char *owner;
50 51
51static void repo_config(const char *name, const char *value) 52static void repo_config(const char *name, const char *value)
52{ 53{
53 config_fn(repo, name, value); 54 config_fn(repo, name, value);
54} 55}
55 56
57static int git_owner_config(const char *key, const char *value, void *cb)
58{
59 if (!strcmp(key, "gitweb.owner"))
60 owner = xstrdup(value);
61 return 0;
62}
63
56static void add_repo(const char *base, const char *path, repo_config_fn fn) 64static void add_repo(const char *base, const char *path, repo_config_fn fn)
57{ 65{
58 struct stat st; 66 struct stat st;
59 struct passwd *pwd; 67 struct passwd *pwd;
60 char *p; 68 char *p;
61 size_t size; 69 size_t size;
62 70
63 if (stat(path, &st)) { 71 if (stat(path, &st)) {
64 fprintf(stderr, "Error accessing %s: %s (%d)\n", 72 fprintf(stderr, "Error accessing %s: %s (%d)\n",
65 path, strerror(errno), errno); 73 path, strerror(errno), errno);
66 return; 74 return;
67 } 75 }
68 if (!stat(fmt("%s/noweb", path), &st)) 76 if (!stat(fmt("%s/noweb", path), &st))
69 return; 77 return;
70 if ((pwd = getpwuid(st.st_uid)) == NULL) { 78
71 fprintf(stderr, "Error reading owner-info for %s: %s (%d)\n", 79 owner = NULL;
72 path, strerror(errno), errno); 80 if (ctx.cfg.enable_gitweb_owner)
73 return; 81 git_config_from_file(git_owner_config, fmt("%s/config", path), NULL);
74 }
75 if (base == path) 82 if (base == path)
76 p = fmt("%s", path); 83 p = fmt("%s", path);
77 else 84 else
78 p = fmt("%s", path + strlen(base) + 1); 85 p = fmt("%s", path + strlen(base) + 1);
79 86
80 if (!strcmp(p + strlen(p) - 5, "/.git")) 87 if (!strcmp(p + strlen(p) - 5, "/.git"))
81 p[strlen(p) - 5] = '\0'; 88 p[strlen(p) - 5] = '\0';
82 89
83 repo = cgit_add_repo(xstrdup(p)); 90 repo = cgit_add_repo(xstrdup(p));
84 if (ctx.cfg.remove_suffix) 91 if (ctx.cfg.remove_suffix)
85 if ((p = strrchr(repo->url, '.')) && !strcmp(p, ".git")) 92 if ((p = strrchr(repo->url, '.')) && !strcmp(p, ".git"))
86 *p = '\0'; 93 *p = '\0';
87 repo->name = repo->url; 94 repo->name = repo->url;
88 repo->path = xstrdup(path); 95 repo->path = xstrdup(path);
89 p = (pwd && pwd->pw_gecos) ? strchr(pwd->pw_gecos, ',') : NULL; 96 while (!owner) {
90 if (p) 97 if ((pwd = getpwuid(st.st_uid)) == NULL) {
91 *p = '\0'; 98 fprintf(stderr, "Error reading owner-info for %s: %s (%d)\n",
92 repo->owner = (pwd ? xstrdup(pwd->pw_gecos ? pwd->pw_gecos : pwd->pw_name) : ""); 99 path, strerror(errno), errno);
100 break;
101 }
102 if (pwd->pw_gecos)
103 if ((p = strchr(pwd->pw_gecos, ',')))
104 *p = '\0';
105 owner = xstrdup(pwd->pw_gecos ? pwd->pw_gecos : pwd->pw_name);
106 }
107 repo->owner = owner;
93 108
94 p = fmt("%s/description", path); 109 p = fmt("%s/description", path);
95 if (!stat(p, &st)) 110 if (!stat(p, &st))
96 readfile(p, &repo->desc, &size); 111 readfile(p, &repo->desc, &size);
97 112
98 p = fmt("%s/README.html", path); 113 p = fmt("%s/README.html", path);
99 if (!stat(p, &st)) 114 if (!stat(p, &st))
100 repo->readme = "README.html"; 115 repo->readme = "README.html";
101 116
102 p = fmt("%s/cgitrc", path); 117 p = fmt("%s/cgitrc", path);
103 if (!stat(p, &st)) { 118 if (!stat(p, &st)) {
104 config_fn = fn; 119 config_fn = fn;