-rw-r--r-- | cgit.c | 4 | ||||
-rw-r--r-- | cgit.h | 2 | ||||
-rw-r--r-- | cgitrc.5.txt | 10 | ||||
-rw-r--r-- | scan-tree.c | 2 | ||||
-rw-r--r-- | shared.c | 9 | ||||
-rw-r--r-- | ui-commit.c | 12 | ||||
-rw-r--r-- | ui-plain.c | 68 |
7 files changed, 95 insertions, 12 deletions
@@ -59,12 +59,14 @@ void repo_config(struct cgit_repo *repo, const char *name, const char *value) | |||
59 | else if (!strcmp(name, "enable-log-filecount")) | 59 | else if (!strcmp(name, "enable-log-filecount")) |
60 | repo->enable_log_filecount = ctx.cfg.enable_log_filecount * atoi(value); | 60 | repo->enable_log_filecount = ctx.cfg.enable_log_filecount * atoi(value); |
61 | else if (!strcmp(name, "enable-log-linecount")) | 61 | else if (!strcmp(name, "enable-log-linecount")) |
62 | repo->enable_log_linecount = ctx.cfg.enable_log_linecount * atoi(value); | 62 | repo->enable_log_linecount = ctx.cfg.enable_log_linecount * atoi(value); |
63 | else if (!strcmp(name, "enable-remote-branches")) | 63 | else if (!strcmp(name, "enable-remote-branches")) |
64 | repo->enable_remote_branches = atoi(value); | 64 | repo->enable_remote_branches = atoi(value); |
65 | else if (!strcmp(name, "enable-subject-links")) | ||
66 | repo->enable_subject_links = atoi(value); | ||
65 | else if (!strcmp(name, "max-stats")) | 67 | else if (!strcmp(name, "max-stats")) |
66 | repo->max_stats = cgit_find_stats_period(value, NULL); | 68 | repo->max_stats = cgit_find_stats_period(value, NULL); |
67 | else if (!strcmp(name, "module-link")) | 69 | else if (!strcmp(name, "module-link")) |
68 | repo->module_link= xstrdup(value); | 70 | repo->module_link= xstrdup(value); |
69 | else if (!strcmp(name, "section")) | 71 | else if (!strcmp(name, "section")) |
70 | repo->section = xstrdup(value); | 72 | repo->section = xstrdup(value); |
@@ -138,12 +140,14 @@ void config_cb(const char *name, const char *value) | |||
138 | else if (!strcmp(name, "enable-log-filecount")) | 140 | else if (!strcmp(name, "enable-log-filecount")) |
139 | ctx.cfg.enable_log_filecount = atoi(value); | 141 | ctx.cfg.enable_log_filecount = atoi(value); |
140 | else if (!strcmp(name, "enable-log-linecount")) | 142 | else if (!strcmp(name, "enable-log-linecount")) |
141 | ctx.cfg.enable_log_linecount = atoi(value); | 143 | ctx.cfg.enable_log_linecount = atoi(value); |
142 | else if (!strcmp(name, "enable-remote-branches")) | 144 | else if (!strcmp(name, "enable-remote-branches")) |
143 | ctx.cfg.enable_remote_branches = atoi(value); | 145 | ctx.cfg.enable_remote_branches = atoi(value); |
146 | else if (!strcmp(name, "enable-subject-links")) | ||
147 | ctx.cfg.enable_subject_links = atoi(value); | ||
144 | else if (!strcmp(name, "enable-tree-linenumbers")) | 148 | else if (!strcmp(name, "enable-tree-linenumbers")) |
145 | ctx.cfg.enable_tree_linenumbers = atoi(value); | 149 | ctx.cfg.enable_tree_linenumbers = atoi(value); |
146 | else if (!strcmp(name, "max-stats")) | 150 | else if (!strcmp(name, "max-stats")) |
147 | ctx.cfg.max_stats = cgit_find_stats_period(value, NULL); | 151 | ctx.cfg.max_stats = cgit_find_stats_period(value, NULL); |
148 | else if (!strcmp(name, "cache-size")) | 152 | else if (!strcmp(name, "cache-size")) |
149 | ctx.cfg.cache_size = atoi(value); | 153 | ctx.cfg.cache_size = atoi(value); |
@@ -70,12 +70,13 @@ struct cgit_repo { | |||
70 | char *section; | 70 | char *section; |
71 | char *clone_url; | 71 | char *clone_url; |
72 | int snapshots; | 72 | int snapshots; |
73 | int enable_log_filecount; | 73 | int enable_log_filecount; |
74 | int enable_log_linecount; | 74 | int enable_log_linecount; |
75 | int enable_remote_branches; | 75 | int enable_remote_branches; |
76 | int enable_subject_links; | ||
76 | int max_stats; | 77 | int max_stats; |
77 | time_t mtime; | 78 | time_t mtime; |
78 | struct cgit_filter *about_filter; | 79 | struct cgit_filter *about_filter; |
79 | struct cgit_filter *commit_filter; | 80 | struct cgit_filter *commit_filter; |
80 | struct cgit_filter *source_filter; | 81 | struct cgit_filter *source_filter; |
81 | }; | 82 | }; |
@@ -179,12 +180,13 @@ struct cgit_config { | |||
179 | int embedded; | 180 | int embedded; |
180 | int enable_filter_overrides; | 181 | int enable_filter_overrides; |
181 | int enable_index_links; | 182 | int enable_index_links; |
182 | int enable_log_filecount; | 183 | int enable_log_filecount; |
183 | int enable_log_linecount; | 184 | int enable_log_linecount; |
184 | int enable_remote_branches; | 185 | int enable_remote_branches; |
186 | int enable_subject_links; | ||
185 | int enable_tree_linenumbers; | 187 | int enable_tree_linenumbers; |
186 | int local_time; | 188 | int local_time; |
187 | int max_atom_items; | 189 | int max_atom_items; |
188 | int max_repo_count; | 190 | int max_repo_count; |
189 | int max_commit_count; | 191 | int max_commit_count; |
190 | int max_lock_attempts; | 192 | int max_lock_attempts; |
diff --git a/cgitrc.5.txt b/cgitrc.5.txt index 6cdfd03..5c24381 100644 --- a/cgitrc.5.txt +++ b/cgitrc.5.txt | |||
@@ -112,12 +112,18 @@ enable-log-linecount:: | |||
112 | 112 | ||
113 | enable-remote-branches:: | 113 | enable-remote-branches:: |
114 | Flag which, when set to "1", will make cgit display remote branches | 114 | Flag which, when set to "1", will make cgit display remote branches |
115 | in the summary and refs views. Default value: "0". See also: | 115 | in the summary and refs views. Default value: "0". See also: |
116 | "repo.enable-remote-branches". | 116 | "repo.enable-remote-branches". |
117 | 117 | ||
118 | enable-subject-links:: | ||
119 | Flag which, when set to "1", will make cgit use the subject of the | ||
120 | parent commit as link text when generating links to parent commits | ||
121 | in commit view. Default value: "0". See also: | ||
122 | "repo.enable-subject-links". | ||
123 | |||
118 | enable-tree-linenumbers:: | 124 | enable-tree-linenumbers:: |
119 | Flag which, when set to "1", will make cgit generate linenumber links | 125 | Flag which, when set to "1", will make cgit generate linenumber links |
120 | for plaintext blobs printed in the tree view. Default value: "1". | 126 | for plaintext blobs printed in the tree view. Default value: "1". |
121 | 127 | ||
122 | favicon:: | 128 | favicon:: |
123 | Url used as link to a shortcut icon for cgit. If specified, it is | 129 | Url used as link to a shortcut icon for cgit. If specified, it is |
@@ -322,12 +328,16 @@ repo.enable-log-linecount:: | |||
322 | `enable-log-linecount'. Default value: none. | 328 | `enable-log-linecount'. Default value: none. |
323 | 329 | ||
324 | repo.enable-remote-branches:: | 330 | repo.enable-remote-branches:: |
325 | Flag which, when set to "1", will make cgit display remote branches | 331 | Flag which, when set to "1", will make cgit display remote branches |
326 | in the summary and refs views. Default value: <enable-remote-branches>. | 332 | in the summary and refs views. Default value: <enable-remote-branches>. |
327 | 333 | ||
334 | repo.enable-subject-links:: | ||
335 | A flag which can be used to override the global setting | ||
336 | `enable-subject-links'. Default value: none. | ||
337 | |||
328 | repo.max-stats:: | 338 | repo.max-stats:: |
329 | Override the default maximum statistics period. Valid values are equal | 339 | Override the default maximum statistics period. Valid values are equal |
330 | to the values specified for the global "max-stats" setting. Default | 340 | to the values specified for the global "max-stats" setting. Default |
331 | value: none. | 341 | value: none. |
332 | 342 | ||
333 | repo.name:: | 343 | repo.name:: |
diff --git a/scan-tree.c b/scan-tree.c index dbca797..1e18f3c 100644 --- a/scan-tree.c +++ b/scan-tree.c | |||
@@ -53,12 +53,14 @@ static void add_repo(const char *base, const char *path, repo_config_fn fn) | |||
53 | 53 | ||
54 | if (stat(path, &st)) { | 54 | if (stat(path, &st)) { |
55 | fprintf(stderr, "Error accessing %s: %s (%d)\n", | 55 | fprintf(stderr, "Error accessing %s: %s (%d)\n", |
56 | path, strerror(errno), errno); | 56 | path, strerror(errno), errno); |
57 | return; | 57 | return; |
58 | } | 58 | } |
59 | if (!stat(fmt("%s/noweb", path), &st)) | ||
60 | return; | ||
59 | if ((pwd = getpwuid(st.st_uid)) == NULL) { | 61 | if ((pwd = getpwuid(st.st_uid)) == NULL) { |
60 | fprintf(stderr, "Error reading owner-info for %s: %s (%d)\n", | 62 | fprintf(stderr, "Error reading owner-info for %s: %s (%d)\n", |
61 | path, strerror(errno), errno); | 63 | path, strerror(errno), errno); |
62 | return; | 64 | return; |
63 | } | 65 | } |
64 | if (base == path) | 66 | if (base == path) |
@@ -57,12 +57,13 @@ struct cgit_repo *cgit_add_repo(const char *url) | |||
57 | ret->section = ctx.cfg.section; | 57 | ret->section = ctx.cfg.section; |
58 | ret->defbranch = "master"; | 58 | ret->defbranch = "master"; |
59 | ret->snapshots = ctx.cfg.snapshots; | 59 | ret->snapshots = ctx.cfg.snapshots; |
60 | ret->enable_log_filecount = ctx.cfg.enable_log_filecount; | 60 | ret->enable_log_filecount = ctx.cfg.enable_log_filecount; |
61 | ret->enable_log_linecount = ctx.cfg.enable_log_linecount; | 61 | ret->enable_log_linecount = ctx.cfg.enable_log_linecount; |
62 | ret->enable_remote_branches = ctx.cfg.enable_remote_branches; | 62 | ret->enable_remote_branches = ctx.cfg.enable_remote_branches; |
63 | ret->enable_subject_links = ctx.cfg.enable_subject_links; | ||
63 | ret->max_stats = ctx.cfg.max_stats; | 64 | ret->max_stats = ctx.cfg.max_stats; |
64 | ret->module_link = ctx.cfg.module_link; | 65 | ret->module_link = ctx.cfg.module_link; |
65 | ret->readme = NULL; | 66 | ret->readme = NULL; |
66 | ret->mtime = -1; | 67 | ret->mtime = -1; |
67 | ret->about_filter = ctx.cfg.about_filter; | 68 | ret->about_filter = ctx.cfg.about_filter; |
68 | ret->commit_filter = ctx.cfg.commit_filter; | 69 | ret->commit_filter = ctx.cfg.commit_filter; |
@@ -276,24 +277,32 @@ int cgit_diff_files(const unsigned char *old_sha1, | |||
276 | *old_size = file1.size; | 277 | *old_size = file1.size; |
277 | *new_size = file2.size; | 278 | *new_size = file2.size; |
278 | 279 | ||
279 | if ((file1.ptr && buffer_is_binary(file1.ptr, file1.size)) || | 280 | if ((file1.ptr && buffer_is_binary(file1.ptr, file1.size)) || |
280 | (file2.ptr && buffer_is_binary(file2.ptr, file2.size))) { | 281 | (file2.ptr && buffer_is_binary(file2.ptr, file2.size))) { |
281 | *binary = 1; | 282 | *binary = 1; |
283 | if (file1.size) | ||
284 | free(file1.ptr); | ||
285 | if (file2.size) | ||
286 | free(file2.ptr); | ||
282 | return 0; | 287 | return 0; |
283 | } | 288 | } |
284 | 289 | ||
285 | memset(&diff_params, 0, sizeof(diff_params)); | 290 | memset(&diff_params, 0, sizeof(diff_params)); |
286 | memset(&emit_params, 0, sizeof(emit_params)); | 291 | memset(&emit_params, 0, sizeof(emit_params)); |
287 | memset(&emit_cb, 0, sizeof(emit_cb)); | 292 | memset(&emit_cb, 0, sizeof(emit_cb)); |
288 | diff_params.flags = XDF_NEED_MINIMAL; | 293 | diff_params.flags = XDF_NEED_MINIMAL; |
289 | emit_params.ctxlen = 3; | 294 | emit_params.ctxlen = 3; |
290 | emit_params.flags = XDL_EMIT_FUNCNAMES; | 295 | emit_params.flags = XDL_EMIT_FUNCNAMES; |
291 | emit_cb.outf = filediff_cb; | 296 | emit_cb.outf = filediff_cb; |
292 | emit_cb.priv = fn; | 297 | emit_cb.priv = fn; |
293 | xdl_diff(&file1, &file2, &diff_params, &emit_params, &emit_cb); | 298 | xdl_diff(&file1, &file2, &diff_params, &emit_params, &emit_cb); |
299 | if (file1.size) | ||
300 | free(file1.ptr); | ||
301 | if (file2.size) | ||
302 | free(file2.ptr); | ||
294 | return 0; | 303 | return 0; |
295 | } | 304 | } |
296 | 305 | ||
297 | void cgit_diff_tree(const unsigned char *old_sha1, | 306 | void cgit_diff_tree(const unsigned char *old_sha1, |
298 | const unsigned char *new_sha1, | 307 | const unsigned char *new_sha1, |
299 | filepair_fn fn, const char *prefix) | 308 | filepair_fn fn, const char *prefix) |
diff --git a/ui-commit.c b/ui-commit.c index b5e3c01..41313b9 100644 --- a/ui-commit.c +++ b/ui-commit.c | |||
@@ -12,16 +12,16 @@ | |||
12 | #include "ui-diff.h" | 12 | #include "ui-diff.h" |
13 | #include "ui-log.h" | 13 | #include "ui-log.h" |
14 | 14 | ||
15 | void cgit_print_commit(char *hex) | 15 | void cgit_print_commit(char *hex) |
16 | { | 16 | { |
17 | struct commit *commit, *parent; | 17 | struct commit *commit, *parent; |
18 | struct commitinfo *info; | 18 | struct commitinfo *info, *parent_info; |
19 | struct commit_list *p; | 19 | struct commit_list *p; |
20 | unsigned char sha1[20]; | 20 | unsigned char sha1[20]; |
21 | char *tmp; | 21 | char *tmp, *tmp2; |
22 | int parents = 0; | 22 | int parents = 0; |
23 | 23 | ||
24 | if (!hex) | 24 | if (!hex) |
25 | hex = ctx.qry.head; | 25 | hex = ctx.qry.head; |
26 | 26 | ||
27 | if (get_sha1(hex, sha1)) { | 27 | if (get_sha1(hex, sha1)) { |
@@ -79,14 +79,18 @@ void cgit_print_commit(char *hex) | |||
79 | cgit_print_error("Error reading parent commit"); | 79 | cgit_print_error("Error reading parent commit"); |
80 | html("</td></tr>"); | 80 | html("</td></tr>"); |
81 | continue; | 81 | continue; |
82 | } | 82 | } |
83 | html("<tr><th>parent</th>" | 83 | html("<tr><th>parent</th>" |
84 | "<td colspan='2' class='sha1'>"); | 84 | "<td colspan='2' class='sha1'>"); |
85 | cgit_commit_link(sha1_to_hex(p->item->object.sha1), NULL, NULL, | 85 | tmp = tmp2 = sha1_to_hex(p->item->object.sha1); |
86 | ctx.qry.head, sha1_to_hex(p->item->object.sha1), 0); | 86 | if (ctx.repo->enable_subject_links) { |
87 | parent_info = cgit_parse_commit(parent); | ||
88 | tmp2 = parent_info->subject; | ||
89 | } | ||
90 | cgit_commit_link(tmp2, NULL, NULL, ctx.qry.head, tmp, 0); | ||
87 | html(" ("); | 91 | html(" ("); |
88 | cgit_diff_link("diff", NULL, NULL, ctx.qry.head, hex, | 92 | cgit_diff_link("diff", NULL, NULL, ctx.qry.head, hex, |
89 | sha1_to_hex(p->item->object.sha1), NULL, 0); | 93 | sha1_to_hex(p->item->object.sha1), NULL, 0); |
90 | html(")</td></tr>"); | 94 | html(")</td></tr>"); |
91 | parents++; | 95 | parents++; |
92 | } | 96 | } |
@@ -7,14 +7,13 @@ | |||
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include "cgit.h" | 9 | #include "cgit.h" |
10 | #include "html.h" | 10 | #include "html.h" |
11 | #include "ui-shared.h" | 11 | #include "ui-shared.h" |
12 | 12 | ||
13 | char *curr_rev; | 13 | int match_baselen; |
14 | char *match_path; | ||
15 | int match; | 14 | int match; |
16 | 15 | ||
17 | static void print_object(const unsigned char *sha1, const char *path) | 16 | static void print_object(const unsigned char *sha1, const char *path) |
18 | { | 17 | { |
19 | enum object_type type; | 18 | enum object_type type; |
20 | char *buf, *ext; | 19 | char *buf, *ext; |
@@ -50,23 +49,69 @@ static void print_object(const unsigned char *sha1, const char *path) | |||
50 | ctx.page.etag = sha1_to_hex(sha1); | 49 | ctx.page.etag = sha1_to_hex(sha1); |
51 | cgit_print_http_headers(&ctx); | 50 | cgit_print_http_headers(&ctx); |
52 | html_raw(buf, size); | 51 | html_raw(buf, size); |
53 | match = 1; | 52 | match = 1; |
54 | } | 53 | } |
55 | 54 | ||
55 | static void print_dir(const unsigned char *sha1, const char *path, | ||
56 | const char *base) | ||
57 | { | ||
58 | char *fullpath; | ||
59 | if (path[0] || base[0]) | ||
60 | fullpath = fmt("/%s%s/", base, path); | ||
61 | else | ||
62 | fullpath = "/"; | ||
63 | ctx.page.etag = sha1_to_hex(sha1); | ||
64 | cgit_print_http_headers(&ctx); | ||
65 | htmlf("<html><head><title>%s</title></head>\n<body>\n" | ||
66 | " <h2>%s</h2>\n <ul>\n", fullpath, fullpath); | ||
67 | if (path[0] || base[0]) | ||
68 | html(" <li><a href=\"../\">../</a></li>\n"); | ||
69 | match = 2; | ||
70 | } | ||
71 | |||
72 | static void print_dir_entry(const unsigned char *sha1, const char *path, | ||
73 | unsigned mode) | ||
74 | { | ||
75 | const char *sep = ""; | ||
76 | if (S_ISDIR(mode)) | ||
77 | sep = "/"; | ||
78 | htmlf(" <li><a href=\"%s%s\">%s%s</a></li>\n", path, sep, path, sep); | ||
79 | match = 2; | ||
80 | } | ||
81 | |||
82 | static void print_dir_tail(void) | ||
83 | { | ||
84 | html(" </ul>\n</body></html>\n"); | ||
85 | } | ||
86 | |||
56 | static int walk_tree(const unsigned char *sha1, const char *base, int baselen, | 87 | static int walk_tree(const unsigned char *sha1, const char *base, int baselen, |
57 | const char *pathname, unsigned mode, int stage, | 88 | const char *pathname, unsigned mode, int stage, |
58 | void *cbdata) | 89 | void *cbdata) |
59 | { | 90 | { |
60 | if (S_ISDIR(mode)) | 91 | if (baselen == match_baselen) { |
92 | if (S_ISREG(mode)) | ||
93 | print_object(sha1, pathname); | ||
94 | else if (S_ISDIR(mode)) { | ||
95 | print_dir(sha1, pathname, base); | ||
96 | return READ_TREE_RECURSIVE; | ||
97 | } | ||
98 | } | ||
99 | else if (baselen > match_baselen) | ||
100 | print_dir_entry(sha1, pathname, mode); | ||
101 | else if (S_ISDIR(mode)) | ||
61 | return READ_TREE_RECURSIVE; | 102 | return READ_TREE_RECURSIVE; |
62 | 103 | ||
63 | if (S_ISREG(mode) && !strncmp(base, match_path, baselen) && | 104 | return 0; |
64 | !strcmp(pathname, match_path + baselen)) | 105 | } |
65 | print_object(sha1, pathname); | ||
66 | 106 | ||
107 | static int basedir_len(const char *path) | ||
108 | { | ||
109 | char *p = strrchr(path, '/'); | ||
110 | if (p) | ||
111 | return p - path + 1; | ||
67 | return 0; | 112 | return 0; |
68 | } | 113 | } |
69 | 114 | ||
70 | void cgit_print_plain(struct cgit_context *ctx) | 115 | void cgit_print_plain(struct cgit_context *ctx) |
71 | { | 116 | { |
72 | const char *rev = ctx->qry.sha1; | 117 | const char *rev = ctx->qry.sha1; |
@@ -74,21 +119,28 @@ void cgit_print_plain(struct cgit_context *ctx) | |||
74 | struct commit *commit; | 119 | struct commit *commit; |
75 | const char *paths[] = {ctx->qry.path, NULL}; | 120 | const char *paths[] = {ctx->qry.path, NULL}; |
76 | 121 | ||
77 | if (!rev) | 122 | if (!rev) |
78 | rev = ctx->qry.head; | 123 | rev = ctx->qry.head; |
79 | 124 | ||
80 | curr_rev = xstrdup(rev); | ||
81 | if (get_sha1(rev, sha1)) { | 125 | if (get_sha1(rev, sha1)) { |
82 | html_status(404, "Not found", 0); | 126 | html_status(404, "Not found", 0); |
83 | return; | 127 | return; |
84 | } | 128 | } |
85 | commit = lookup_commit_reference(sha1); | 129 | commit = lookup_commit_reference(sha1); |
86 | if (!commit || parse_commit(commit)) { | 130 | if (!commit || parse_commit(commit)) { |
87 | html_status(404, "Not found", 0); | 131 | html_status(404, "Not found", 0); |
88 | return; | 132 | return; |
89 | } | 133 | } |
90 | match_path = ctx->qry.path; | 134 | if (!paths[0]) { |
135 | paths[0] = ""; | ||
136 | match_baselen = -1; | ||
137 | print_dir(commit->tree->object.sha1, "", ""); | ||
138 | } | ||
139 | else | ||
140 | match_baselen = basedir_len(paths[0]); | ||
91 | read_tree_recursive(commit->tree, "", 0, 0, paths, walk_tree, NULL); | 141 | read_tree_recursive(commit->tree, "", 0, 0, paths, walk_tree, NULL); |
92 | if (!match) | 142 | if (!match) |
93 | html_status(404, "Not found", 0); | 143 | html_status(404, "Not found", 0); |
144 | else if (match == 2) | ||
145 | print_dir_tail(); | ||
94 | } | 146 | } |