aboutsummaryrefslogtreecommitdiffstats
path: root/scan-tree.c
diff options
context:
space:
mode:
authorGravatar Jason A. Donenfeld <Jason@zx2c4.com>2012-10-09 19:56:14 (JST)
committerGravatar Jason A. Donenfeld <Jason@zx2c4.com>2012-10-17 23:30:09 (JST)
commit521e10c884055c800078e6dada97ccf6c5193aad (patch)
treef4a8398b2d64b171de909d57893441830a280712 /scan-tree.c
parentc366bd6fa88fb7dbe1e42c84d56e2bda0b1682c5 (diff)
downloadcgit-521e10c884055c800078e6dada97ccf6c5193aad.zip
cgit-521e10c884055c800078e6dada97ccf6c5193aad.tar.gz
scan-tree: Unify gitweb.* and cgit.* settings into one config option.
After some back and forth with Jamie and René, it looks like the git config semantics are going to be like this: - gitweb.category maps to the cgit repo config key "section" - gitweb.description maps to the cgit repo config key "desc" - gitweb.owner maps to the cgit repo config key "owner" - cgit.* maps to all cgit repo config keys This option can be enabled with "enable-git-config=1", and replaces all previous "enable-gitweb-*" config keys. The order of operations is as follows: - git config settings are applied in the order that they exist in the git config file - if the owner is not set from git config, get the owner using the usual getpwuid call - if the description is not set from git config, look inside the static $path/description file - if section-from-path=1, override whatever previous settings were inside of git config using the section-from-path logic - parse $path/cgitrc for local repo.* settings, that override all previous settings
Diffstat (limited to 'scan-tree.c')
-rw-r--r--scan-tree.c48
1 files changed, 19 insertions, 29 deletions
diff --git a/scan-tree.c b/scan-tree.c
index 6d1941e..6ce8036 100644
--- a/scan-tree.c
+++ b/scan-tree.c
@@ -47,28 +47,26 @@ static int is_git_dir(const char *path)
47 47
48struct cgit_repo *repo; 48struct cgit_repo *repo;
49repo_config_fn config_fn; 49repo_config_fn config_fn;
50char *owner;
51char *desc;
52char *section;
53 50
54static void repo_config(const char *name, const char *value) 51static void repo_config(const char *name, const char *value)
55{ 52{
56 config_fn(repo, name, value); 53 config_fn(repo, name, value);
57} 54}
58 55
59static int gitweb_config(const char *key, const char *value, void *cb) 56static int gitconfig_config(const char *key, const char *value, void *cb)
60{ 57{
61 if (ctx.cfg.enable_gitweb_owner && !strcmp(key, "gitweb.owner")) 58 if (!strcmp(key, "gitweb.owner"))
62 owner = xstrdup(value); 59 config_fn(repo, "owner", value);
63 else if (ctx.cfg.enable_gitweb_desc && !strcmp(key, "gitweb.description")) 60 else if (!strcmp(key, "gitweb.description"))
64 desc = xstrdup(value); 61 config_fn(repo, "desc", value);
65 else if (ctx.cfg.enable_gitweb_section && !strcmp(key, "gitweb.category")) 62 else if (!strcmp(key, "gitweb.category"))
66 section = xstrdup(value); 63 config_fn(repo, "section", value);
64 else if (!prefixcmp(key, "cgit."))
65 config_fn(repo, key + 5, value);
66
67 return 0; 67 return 0;
68} 68}
69 69
70
71
72static char *xstrrchr(char *s, char *from, int c) 70static char *xstrrchr(char *s, char *from, int c)
73{ 71{
74 while (from >= s && *from != c) 72 while (from >= s && *from != c)
@@ -96,11 +94,6 @@ static void add_repo(const char *base, const char *path, repo_config_fn fn)
96 if (!stat(fmt("%s/noweb", path), &st)) 94 if (!stat(fmt("%s/noweb", path), &st))
97 return; 95 return;
98 96
99 owner = NULL;
100 desc = NULL;
101 section = NULL;
102 git_config_from_file(gitweb_config, fmt("%s/config", path), NULL);
103
104 if (base == path) 97 if (base == path)
105 rel = xstrdup(fmt("%s", path)); 98 rel = xstrdup(fmt("%s", path));
106 else 99 else
@@ -110,12 +103,15 @@ static void add_repo(const char *base, const char *path, repo_config_fn fn)
110 rel[strlen(rel) - 5] = '\0'; 103 rel[strlen(rel) - 5] = '\0';
111 104
112 repo = cgit_add_repo(rel); 105 repo = cgit_add_repo(rel);
106 config_fn = fn;
107 if (ctx.cfg.enable_git_config)
108 git_config_from_file(gitconfig_config, fmt("%s/config", path), NULL);
109
113 if (ctx.cfg.remove_suffix) 110 if (ctx.cfg.remove_suffix)
114 if ((p = strrchr(repo->url, '.')) && !strcmp(p, ".git")) 111 if ((p = strrchr(repo->url, '.')) && !strcmp(p, ".git"))
115 *p = '\0'; 112 *p = '\0';
116 repo->name = repo->url;
117 repo->path = xstrdup(path); 113 repo->path = xstrdup(path);
118 while (!owner) { 114 while (!repo->owner) {
119 if ((pwd = getpwuid(st.st_uid)) == NULL) { 115 if ((pwd = getpwuid(st.st_uid)) == NULL) {
120 fprintf(stderr, "Error reading owner-info for %s: %s (%d)\n", 116 fprintf(stderr, "Error reading owner-info for %s: %s (%d)\n",
121 path, strerror(errno), errno); 117 path, strerror(errno), errno);
@@ -124,13 +120,10 @@ static void add_repo(const char *base, const char *path, repo_config_fn fn)
124 if (pwd->pw_gecos) 120 if (pwd->pw_gecos)
125 if ((p = strchr(pwd->pw_gecos, ','))) 121 if ((p = strchr(pwd->pw_gecos, ',')))
126 *p = '\0'; 122 *p = '\0';
127 owner = xstrdup(pwd->pw_gecos ? pwd->pw_gecos : pwd->pw_name); 123 repo->owner = xstrdup(pwd->pw_gecos ? pwd->pw_gecos : pwd->pw_name);
128 } 124 }
129 repo->owner = owner;
130 125
131 if (desc) 126 if (repo->desc == cgit_default_repo_desc || !repo->desc) {
132 repo->desc = desc;
133 else {
134 p = fmt("%s/description", path); 127 p = fmt("%s/description", path);
135 if (!stat(p, &st)) 128 if (!stat(p, &st))
136 readfile(p, &repo->desc, &size); 129 readfile(p, &repo->desc, &size);
@@ -141,8 +134,6 @@ static void add_repo(const char *base, const char *path, repo_config_fn fn)
141 if (!stat(p, &st)) 134 if (!stat(p, &st))
142 repo->readme = "README.html"; 135 repo->readme = "README.html";
143 } 136 }
144 if (section)
145 repo->section = section;
146 if (ctx.cfg.section_from_path) { 137 if (ctx.cfg.section_from_path) {
147 n = ctx.cfg.section_from_path; 138 n = ctx.cfg.section_from_path;
148 if (n > 0) { 139 if (n > 0) {
@@ -167,10 +158,9 @@ static void add_repo(const char *base, const char *path, repo_config_fn fn)
167 } 158 }
168 159
169 p = fmt("%s/cgitrc", path); 160 p = fmt("%s/cgitrc", path);
170 if (!stat(p, &st)) { 161 if (!stat(p, &st))
171 config_fn = fn;
172 parse_configfile(xstrdup(p), &repo_config); 162 parse_configfile(xstrdup(p), &repo_config);
173 } 163
174 164
175 free(rel); 165 free(rel);
176} 166}