diff options
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | cgit.c | 10 | ||||
-rw-r--r-- | cgit.h | 2 | ||||
-rw-r--r-- | cgitrc.5.txt | 12 | ||||
m--------- | git | 0 | ||||
-rw-r--r-- | scan-tree.c | 50 | ||||
-rw-r--r-- | shared.c | 2 | ||||
-rw-r--r-- | ui-summary.c | 42 |
8 files changed, 89 insertions, 31 deletions
@@ -5,7 +5,7 @@ CGIT_DATA_PATH = $(CGIT_SCRIPT_PATH) | |||
5 | CGIT_CONFIG = /etc/cgitrc | 5 | CGIT_CONFIG = /etc/cgitrc |
6 | CACHE_ROOT = /var/cache/cgit | 6 | CACHE_ROOT = /var/cache/cgit |
7 | SHA1_HEADER = <openssl/sha.h> | 7 | SHA1_HEADER = <openssl/sha.h> |
8 | GIT_VER = 1.7.2.2 | 8 | GIT_VER = 1.7.3 |
9 | GIT_URL = http://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.bz2 | 9 | GIT_URL = http://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.bz2 |
10 | INSTALL = install | 10 | INSTALL = install |
11 | 11 | ||
@@ -72,11 +72,7 @@ void repo_config(struct cgit_repo *repo, const char *name, const char *value) | |||
72 | else if (!strcmp(name, "section")) | 72 | else if (!strcmp(name, "section")) |
73 | repo->section = xstrdup(value); | 73 | repo->section = xstrdup(value); |
74 | else if (!strcmp(name, "readme") && value != NULL) { | 74 | else if (!strcmp(name, "readme") && value != NULL) { |
75 | char *colon; | 75 | repo->readme = xstrdup(value); |
76 | if (*value == '/' || ((colon = strchr(value, ':')) != NULL && colon != value && *(colon + 1) != '\0')) | ||
77 | repo->readme = xstrdup(value); | ||
78 | else | ||
79 | repo->readme = xstrdup(fmt("%s/%s", repo->path, value)); | ||
80 | } else if (ctx.cfg.enable_filter_overrides) { | 76 | } else if (ctx.cfg.enable_filter_overrides) { |
81 | if (!strcmp(name, "about-filter")) | 77 | if (!strcmp(name, "about-filter")) |
82 | repo->about_filter = new_filter(value, 0); | 78 | repo->about_filter = new_filter(value, 0); |
@@ -97,6 +93,8 @@ void config_cb(const char *name, const char *value) | |||
97 | ctx.repo->path = trim_end(value, '/'); | 93 | ctx.repo->path = trim_end(value, '/'); |
98 | else if (ctx.repo && !prefixcmp(name, "repo.")) | 94 | else if (ctx.repo && !prefixcmp(name, "repo.")) |
99 | repo_config(ctx.repo, name + 5, value); | 95 | repo_config(ctx.repo, name + 5, value); |
96 | else if (!strcmp(name, "readme")) | ||
97 | ctx.cfg.readme = xstrdup(value); | ||
100 | else if (!strcmp(name, "root-title")) | 98 | else if (!strcmp(name, "root-title")) |
101 | ctx.cfg.root_title = xstrdup(value); | 99 | ctx.cfg.root_title = xstrdup(value); |
102 | else if (!strcmp(name, "root-desc")) | 100 | else if (!strcmp(name, "root-desc")) |
@@ -195,6 +193,8 @@ void config_cb(const char *name, const char *value) | |||
195 | ctx.cfg.project_list, repo_config); | 193 | ctx.cfg.project_list, repo_config); |
196 | else | 194 | else |
197 | scan_tree(expand_macros(value), repo_config); | 195 | scan_tree(expand_macros(value), repo_config); |
196 | else if (!strcmp(name, "section-from-path")) | ||
197 | ctx.cfg.section_from_path = atoi(value); | ||
198 | else if (!strcmp(name, "source-filter")) | 198 | else if (!strcmp(name, "source-filter")) |
199 | ctx.cfg.source_filter = new_filter(value, 1); | 199 | ctx.cfg.source_filter = new_filter(value, 1); |
200 | else if (!strcmp(name, "summary-log")) | 200 | else if (!strcmp(name, "summary-log")) |
@@ -168,6 +168,7 @@ struct cgit_config { | |||
168 | char *logo_link; | 168 | char *logo_link; |
169 | char *module_link; | 169 | char *module_link; |
170 | char *project_list; | 170 | char *project_list; |
171 | char *readme; | ||
171 | char *robots; | 172 | char *robots; |
172 | char *root_title; | 173 | char *root_title; |
173 | char *root_desc; | 174 | char *root_desc; |
@@ -205,6 +206,7 @@ struct cgit_config { | |||
205 | int noheader; | 206 | int noheader; |
206 | int renamelimit; | 207 | int renamelimit; |
207 | int remove_suffix; | 208 | int remove_suffix; |
209 | int section_from_path; | ||
208 | int snapshots; | 210 | int snapshots; |
209 | int summary_branches; | 211 | int summary_branches; |
210 | int summary_log; | 212 | int summary_log; |
diff --git a/cgitrc.5.txt b/cgitrc.5.txt index c643fae..ce78d41 100644 --- a/cgitrc.5.txt +++ b/cgitrc.5.txt | |||
@@ -234,6 +234,10 @@ project-list:: | |||
234 | should loaded as git repositories. This must be defined prior to | 234 | should loaded as git repositories. This must be defined prior to |
235 | scan-path. Default value: none. See also: scan-path. | 235 | scan-path. Default value: none. See also: scan-path. |
236 | 236 | ||
237 | readme:: | ||
238 | Text which will be used as default value for "repo.readme". Default | ||
239 | value: none. | ||
240 | |||
237 | remove-suffix:: | 241 | remove-suffix:: |
238 | If set to "1" and scan-path is enabled, if any repositories are found | 242 | If set to "1" and scan-path is enabled, if any repositories are found |
239 | with a suffix of ".git", this suffix will be removed for the url and | 243 | with a suffix of ".git", this suffix will be removed for the url and |
@@ -278,6 +282,12 @@ section:: | |||
278 | after this option will inherit the current section name. Default value: | 282 | after this option will inherit the current section name. Default value: |
279 | none. | 283 | none. |
280 | 284 | ||
285 | section-from-path:: | ||
286 | A number which, if specified before scan-path, specifies how many | ||
287 | path elements from each repo path to use as a default section name. | ||
288 | If negative, cgit will discard the specified number of path elements | ||
289 | above the repo directory. Default value: 0. | ||
290 | |||
281 | side-by-side-diffs:: | 291 | side-by-side-diffs:: |
282 | If set to "1" shows side-by-side diffs instead of unidiffs per | 292 | If set to "1" shows side-by-side diffs instead of unidiffs per |
283 | default. Default value: "0". | 293 | default. Default value: "0". |
@@ -373,7 +383,7 @@ repo.readme:: | |||
373 | A path (relative to <repo.path>) which specifies a file to include | 383 | A path (relative to <repo.path>) which specifies a file to include |
374 | verbatim as the "About" page for this repo. You may also specify a | 384 | verbatim as the "About" page for this repo. You may also specify a |
375 | git refspec by head or by hash by prepending the refspec followed by | 385 | git refspec by head or by hash by prepending the refspec followed by |
376 | a colon. For example, "master:docs/readme.mkd" Default value: none. | 386 | a colon. For example, "master:docs/readme.mkd" Default value: <readme>. |
377 | 387 | ||
378 | repo.snapshots:: | 388 | repo.snapshots:: |
379 | A mask of allowed snapshot-formats for this repo, restricted by the | 389 | A mask of allowed snapshot-formats for this repo, restricted by the |
diff --git a/git b/git | |||
Subproject 8c67c392e1620fc3b749aa9e0b8da13bd84226f | Subproject 87b50542a08ac6caa083ddc376e674424e37940 | ||
diff --git a/scan-tree.c b/scan-tree.c index e987824..b5b50f3 100644 --- a/scan-tree.c +++ b/scan-tree.c | |||
@@ -61,11 +61,19 @@ static int git_owner_config(const char *key, const char *value, void *cb) | |||
61 | return 0; | 61 | return 0; |
62 | } | 62 | } |
63 | 63 | ||
64 | static char *xstrrchr(char *s, char *from, int c) | ||
65 | { | ||
66 | while (from >= s && *from != c) | ||
67 | from--; | ||
68 | return from < s ? NULL : from; | ||
69 | } | ||
70 | |||
64 | static void add_repo(const char *base, const char *path, repo_config_fn fn) | 71 | static void add_repo(const char *base, const char *path, repo_config_fn fn) |
65 | { | 72 | { |
66 | struct stat st; | 73 | struct stat st; |
67 | struct passwd *pwd; | 74 | struct passwd *pwd; |
68 | char *p; | 75 | char *rel, *p, *slash; |
76 | int n; | ||
69 | size_t size; | 77 | size_t size; |
70 | 78 | ||
71 | if (stat(path, &st)) { | 79 | if (stat(path, &st)) { |
@@ -80,14 +88,14 @@ static void add_repo(const char *base, const char *path, repo_config_fn fn) | |||
80 | if (ctx.cfg.enable_gitweb_owner) | 88 | if (ctx.cfg.enable_gitweb_owner) |
81 | git_config_from_file(git_owner_config, fmt("%s/config", path), NULL); | 89 | git_config_from_file(git_owner_config, fmt("%s/config", path), NULL); |
82 | if (base == path) | 90 | if (base == path) |
83 | p = fmt("%s", path); | 91 | rel = xstrdup(fmt("%s", path)); |
84 | else | 92 | else |
85 | p = fmt("%s", path + strlen(base) + 1); | 93 | rel = xstrdup(fmt("%s", path + strlen(base) + 1)); |
86 | 94 | ||
87 | if (!strcmp(p + strlen(p) - 5, "/.git")) | 95 | if (!strcmp(rel + strlen(rel) - 5, "/.git")) |
88 | p[strlen(p) - 5] = '\0'; | 96 | rel[strlen(rel) - 5] = '\0'; |
89 | 97 | ||
90 | repo = cgit_add_repo(xstrdup(p)); | 98 | repo = cgit_add_repo(rel); |
91 | if (ctx.cfg.remove_suffix) | 99 | if (ctx.cfg.remove_suffix) |
92 | if ((p = strrchr(repo->url, '.')) && !strcmp(p, ".git")) | 100 | if ((p = strrchr(repo->url, '.')) && !strcmp(p, ".git")) |
93 | *p = '\0'; | 101 | *p = '\0'; |
@@ -110,9 +118,33 @@ static void add_repo(const char *base, const char *path, repo_config_fn fn) | |||
110 | if (!stat(p, &st)) | 118 | if (!stat(p, &st)) |
111 | readfile(p, &repo->desc, &size); | 119 | readfile(p, &repo->desc, &size); |
112 | 120 | ||
113 | p = fmt("%s/README.html", path); | 121 | if (!repo->readme) { |
114 | if (!stat(p, &st)) | 122 | p = fmt("%s/README.html", path); |
115 | repo->readme = "README.html"; | 123 | if (!stat(p, &st)) |
124 | repo->readme = "README.html"; | ||
125 | } | ||
126 | if (ctx.cfg.section_from_path) { | ||
127 | n = ctx.cfg.section_from_path; | ||
128 | if (n > 0) { | ||
129 | slash = rel; | ||
130 | while (slash && n && (slash = strchr(slash, '/'))) | ||
131 | n--; | ||
132 | } else { | ||
133 | slash = rel + strlen(rel); | ||
134 | while (slash && n && (slash = xstrrchr(rel, slash, '/'))) | ||
135 | n++; | ||
136 | } | ||
137 | if (slash && !n) { | ||
138 | *slash = '\0'; | ||
139 | repo->section = xstrdup(rel); | ||
140 | *slash = '/'; | ||
141 | if (!prefixcmp(repo->name, repo->section)) { | ||
142 | repo->name += strlen(repo->section); | ||
143 | if (*repo->name == '/') | ||
144 | repo->name++; | ||
145 | } | ||
146 | } | ||
147 | } | ||
116 | 148 | ||
117 | p = fmt("%s/cgitrc", path); | 149 | p = fmt("%s/cgitrc", path); |
118 | if (!stat(p, &st)) { | 150 | if (!stat(p, &st)) { |
@@ -62,7 +62,7 @@ struct cgit_repo *cgit_add_repo(const char *url) | |||
62 | ret->enable_subject_links = ctx.cfg.enable_subject_links; | 62 | ret->enable_subject_links = ctx.cfg.enable_subject_links; |
63 | ret->max_stats = ctx.cfg.max_stats; | 63 | ret->max_stats = ctx.cfg.max_stats; |
64 | ret->module_link = ctx.cfg.module_link; | 64 | ret->module_link = ctx.cfg.module_link; |
65 | ret->readme = NULL; | 65 | ret->readme = ctx.cfg.readme; |
66 | ret->mtime = -1; | 66 | ret->mtime = -1; |
67 | ret->about_filter = ctx.cfg.about_filter; | 67 | ret->about_filter = ctx.cfg.about_filter; |
68 | ret->commit_filter = ctx.cfg.commit_filter; | 68 | ret->commit_filter = ctx.cfg.commit_filter; |
diff --git a/ui-summary.c b/ui-summary.c index 02f191e..b203bcc 100644 --- a/ui-summary.c +++ b/ui-summary.c | |||
@@ -70,33 +70,47 @@ void cgit_print_summary() | |||
70 | 70 | ||
71 | void cgit_print_repo_readme(char *path) | 71 | void cgit_print_repo_readme(char *path) |
72 | { | 72 | { |
73 | char *slash, *tmp, *colon, *ref = 0; | 73 | char *slash, *tmp, *colon, *ref; |
74 | 74 | ||
75 | if (!ctx.repo->readme) | 75 | if (!ctx.repo->readme || !(*ctx.repo->readme)) |
76 | return; | 76 | return; |
77 | 77 | ||
78 | ref = NULL; | ||
79 | |||
80 | /* Check if the readme is tracked in the git repo. */ | ||
81 | colon = strchr(ctx.repo->readme, ':'); | ||
82 | if (colon && strlen(colon) > 1) { | ||
83 | *colon = '\0'; | ||
84 | ref = ctx.repo->readme; | ||
85 | ctx.repo->readme = colon + 1; | ||
86 | if (!(*ctx.repo->readme)) | ||
87 | return; | ||
88 | } | ||
89 | |||
90 | /* Prepend repo path to relative readme path unless tracked. */ | ||
91 | if (!ref && *ctx.repo->readme != '/') | ||
92 | ctx.repo->readme = xstrdup(fmt("%s/%s", ctx.repo->path, | ||
93 | ctx.repo->readme)); | ||
94 | |||
95 | /* If a subpath is specified for the about page, make it relative | ||
96 | * to the directory containing the configured readme. | ||
97 | */ | ||
78 | if (path) { | 98 | if (path) { |
79 | slash = strrchr(ctx.repo->readme, '/'); | 99 | slash = strrchr(ctx.repo->readme, '/'); |
80 | if (!slash) { | 100 | if (!slash) { |
81 | slash = strchr(ctx.repo->readme, ':'); | 101 | if (!colon) |
82 | if (!slash) | ||
83 | return; | 102 | return; |
103 | slash = colon; | ||
84 | } | 104 | } |
85 | tmp = xmalloc(slash - ctx.repo->readme + 1 + strlen(path) + 1); | 105 | tmp = xmalloc(slash - ctx.repo->readme + 1 + strlen(path) + 1); |
86 | strncpy(tmp, ctx.repo->readme, slash - ctx.repo->readme + 1); | 106 | strncpy(tmp, ctx.repo->readme, slash - ctx.repo->readme + 1); |
87 | strcpy(tmp + (slash - ctx.repo->readme + 1), path); | 107 | strcpy(tmp + (slash - ctx.repo->readme + 1), path); |
88 | } else | 108 | } else |
89 | tmp = ctx.repo->readme; | 109 | tmp = ctx.repo->readme; |
90 | colon = strchr(tmp, ':'); | 110 | |
91 | if (colon && strlen(colon) > 1) { | 111 | /* Print the calculated readme, either from the git repo or from the |
92 | *colon = '\0'; | 112 | * filesystem, while applying the about-filter. |
93 | ref = tmp; | 113 | */ |
94 | tmp = colon + 1; | ||
95 | while ((*tmp == '/' || *tmp == ':') && *tmp != '\0') | ||
96 | ++tmp; | ||
97 | if (!(*tmp)) | ||
98 | return; | ||
99 | } | ||
100 | html("<div id='summary'>"); | 114 | html("<div id='summary'>"); |
101 | if (ctx.repo->about_filter) | 115 | if (ctx.repo->about_filter) |
102 | cgit_open_filter(ctx.repo->about_filter); | 116 | cgit_open_filter(ctx.repo->about_filter); |