author | Lars Hjemli <hjemli@gmail.com> | 2009-09-13 20:01:52 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2009-09-13 20:01:52 (UTC) |
commit | 5f12e45fe3338095916a444ff106dd9fc9991d84 (patch) (unidiff) | |
tree | 26b04e10b2ea277c09620bcf119eaa8f79e2fb88 | |
parent | 45c49d6cf4b819385dfee620a81e3cb095ed5cd1 (diff) | |
parent | 6638f40868ccf7806a9668560d3608324704c2b7 (diff) | |
download | cgit-5f12e45fe3338095916a444ff106dd9fc9991d84.zip cgit-5f12e45fe3338095916a444ff106dd9fc9991d84.tar.gz cgit-5f12e45fe3338095916a444ff106dd9fc9991d84.tar.bz2 |
Merge branch 'fp/linenumbers'
-rw-r--r-- | cgit.c | 3 | ||||
-rw-r--r-- | cgit.css | 6 | ||||
-rw-r--r-- | cgit.h | 1 | ||||
-rw-r--r-- | cgitrc.5.txt | 4 | ||||
-rw-r--r-- | ui-tree.c | 35 |
5 files changed, 32 insertions, 17 deletions
@@ -73,32 +73,34 @@ void config_cb(const char *name, const char *value) | |||
73 | if (!ctx.cfg.virtual_root && (!strcmp(value, "/"))) | 73 | if (!ctx.cfg.virtual_root && (!strcmp(value, "/"))) |
74 | ctx.cfg.virtual_root = ""; | 74 | ctx.cfg.virtual_root = ""; |
75 | } else if (!strcmp(name, "nocache")) | 75 | } else if (!strcmp(name, "nocache")) |
76 | ctx.cfg.nocache = atoi(value); | 76 | ctx.cfg.nocache = atoi(value); |
77 | else if (!strcmp(name, "noplainemail")) | 77 | else if (!strcmp(name, "noplainemail")) |
78 | ctx.cfg.noplainemail = atoi(value); | 78 | ctx.cfg.noplainemail = atoi(value); |
79 | else if (!strcmp(name, "noheader")) | 79 | else if (!strcmp(name, "noheader")) |
80 | ctx.cfg.noheader = atoi(value); | 80 | ctx.cfg.noheader = atoi(value); |
81 | else if (!strcmp(name, "snapshots")) | 81 | else if (!strcmp(name, "snapshots")) |
82 | ctx.cfg.snapshots = cgit_parse_snapshots_mask(value); | 82 | ctx.cfg.snapshots = cgit_parse_snapshots_mask(value); |
83 | else if (!strcmp(name, "enable-index-links")) | 83 | else if (!strcmp(name, "enable-index-links")) |
84 | ctx.cfg.enable_index_links = atoi(value); | 84 | ctx.cfg.enable_index_links = atoi(value); |
85 | else if (!strcmp(name, "enable-log-filecount")) | 85 | else if (!strcmp(name, "enable-log-filecount")) |
86 | ctx.cfg.enable_log_filecount = atoi(value); | 86 | ctx.cfg.enable_log_filecount = atoi(value); |
87 | else if (!strcmp(name, "enable-log-linecount")) | 87 | else if (!strcmp(name, "enable-log-linecount")) |
88 | ctx.cfg.enable_log_linecount = atoi(value); | 88 | ctx.cfg.enable_log_linecount = atoi(value); |
89 | else if (!strcmp(name, "enable-tree-linenumbers")) | ||
90 | ctx.cfg.enable_tree_linenumbers = atoi(value); | ||
89 | else if (!strcmp(name, "max-stats")) | 91 | else if (!strcmp(name, "max-stats")) |
90 | ctx.cfg.max_stats = cgit_find_stats_period(value, NULL); | 92 | ctx.cfg.max_stats = cgit_find_stats_period(value, NULL); |
91 | else if (!strcmp(name, "cache-size")) | 93 | else if (!strcmp(name, "cache-size")) |
92 | ctx.cfg.cache_size = atoi(value); | 94 | ctx.cfg.cache_size = atoi(value); |
93 | else if (!strcmp(name, "cache-root")) | 95 | else if (!strcmp(name, "cache-root")) |
94 | ctx.cfg.cache_root = xstrdup(value); | 96 | ctx.cfg.cache_root = xstrdup(value); |
95 | else if (!strcmp(name, "cache-root-ttl")) | 97 | else if (!strcmp(name, "cache-root-ttl")) |
96 | ctx.cfg.cache_root_ttl = atoi(value); | 98 | ctx.cfg.cache_root_ttl = atoi(value); |
97 | else if (!strcmp(name, "cache-repo-ttl")) | 99 | else if (!strcmp(name, "cache-repo-ttl")) |
98 | ctx.cfg.cache_repo_ttl = atoi(value); | 100 | ctx.cfg.cache_repo_ttl = atoi(value); |
99 | else if (!strcmp(name, "cache-static-ttl")) | 101 | else if (!strcmp(name, "cache-static-ttl")) |
100 | ctx.cfg.cache_static_ttl = atoi(value); | 102 | ctx.cfg.cache_static_ttl = atoi(value); |
101 | else if (!strcmp(name, "cache-dynamic-ttl")) | 103 | else if (!strcmp(name, "cache-dynamic-ttl")) |
102 | ctx.cfg.cache_dynamic_ttl = atoi(value); | 104 | ctx.cfg.cache_dynamic_ttl = atoi(value); |
103 | else if (!strcmp(name, "about-filter")) | 105 | else if (!strcmp(name, "about-filter")) |
104 | ctx.cfg.about_filter = new_filter(value, 0); | 106 | ctx.cfg.about_filter = new_filter(value, 0); |
@@ -225,32 +227,33 @@ char *xstrdupn(const char *str) | |||
225 | 227 | ||
226 | static void prepare_context(struct cgit_context *ctx) | 228 | static void prepare_context(struct cgit_context *ctx) |
227 | { | 229 | { |
228 | memset(ctx, 0, sizeof(ctx)); | 230 | memset(ctx, 0, sizeof(ctx)); |
229 | ctx->cfg.agefile = "info/web/last-modified"; | 231 | ctx->cfg.agefile = "info/web/last-modified"; |
230 | ctx->cfg.nocache = 0; | 232 | ctx->cfg.nocache = 0; |
231 | ctx->cfg.cache_size = 0; | 233 | ctx->cfg.cache_size = 0; |
232 | ctx->cfg.cache_dynamic_ttl = 5; | 234 | ctx->cfg.cache_dynamic_ttl = 5; |
233 | ctx->cfg.cache_max_create_time = 5; | 235 | ctx->cfg.cache_max_create_time = 5; |
234 | ctx->cfg.cache_repo_ttl = 5; | 236 | ctx->cfg.cache_repo_ttl = 5; |
235 | ctx->cfg.cache_root = CGIT_CACHE_ROOT; | 237 | ctx->cfg.cache_root = CGIT_CACHE_ROOT; |
236 | ctx->cfg.cache_root_ttl = 5; | 238 | ctx->cfg.cache_root_ttl = 5; |
237 | ctx->cfg.cache_static_ttl = -1; | 239 | ctx->cfg.cache_static_ttl = -1; |
238 | ctx->cfg.css = "/cgit.css"; | 240 | ctx->cfg.css = "/cgit.css"; |
239 | ctx->cfg.logo = "/cgit.png"; | 241 | ctx->cfg.logo = "/cgit.png"; |
240 | ctx->cfg.local_time = 0; | 242 | ctx->cfg.local_time = 0; |
243 | ctx->cfg.enable_tree_linenumbers = 1; | ||
241 | ctx->cfg.max_repo_count = 50; | 244 | ctx->cfg.max_repo_count = 50; |
242 | ctx->cfg.max_commit_count = 50; | 245 | ctx->cfg.max_commit_count = 50; |
243 | ctx->cfg.max_lock_attempts = 5; | 246 | ctx->cfg.max_lock_attempts = 5; |
244 | ctx->cfg.max_msg_len = 80; | 247 | ctx->cfg.max_msg_len = 80; |
245 | ctx->cfg.max_repodesc_len = 80; | 248 | ctx->cfg.max_repodesc_len = 80; |
246 | ctx->cfg.max_stats = 0; | 249 | ctx->cfg.max_stats = 0; |
247 | ctx->cfg.module_link = "./?repo=%s&page=commit&id=%s"; | 250 | ctx->cfg.module_link = "./?repo=%s&page=commit&id=%s"; |
248 | ctx->cfg.renamelimit = -1; | 251 | ctx->cfg.renamelimit = -1; |
249 | ctx->cfg.robots = "index, nofollow"; | 252 | ctx->cfg.robots = "index, nofollow"; |
250 | ctx->cfg.root_title = "Git repository browser"; | 253 | ctx->cfg.root_title = "Git repository browser"; |
251 | ctx->cfg.root_desc = "a fast webinterface for the git dscm"; | 254 | ctx->cfg.root_desc = "a fast webinterface for the git dscm"; |
252 | ctx->cfg.script_name = CGIT_SCRIPT_NAME; | 255 | ctx->cfg.script_name = CGIT_SCRIPT_NAME; |
253 | ctx->cfg.summary_branches = 10; | 256 | ctx->cfg.summary_branches = 10; |
254 | ctx->cfg.summary_log = 10; | 257 | ctx->cfg.summary_log = 10; |
255 | ctx->cfg.summary_tags = 10; | 258 | ctx->cfg.summary_tags = 10; |
256 | ctx->env.cgit_config = xstrdupn(getenv("CGIT_CONFIG")); | 259 | ctx->env.cgit_config = xstrdupn(getenv("CGIT_CONFIG")); |
@@ -224,42 +224,42 @@ td.ls-size { | |||
224 | text-align: right; | 224 | text-align: right; |
225 | font-family: monospace; | 225 | font-family: monospace; |
226 | width: 10em; | 226 | width: 10em; |
227 | } | 227 | } |
228 | 228 | ||
229 | td.ls-mode { | 229 | td.ls-mode { |
230 | font-family: monospace; | 230 | font-family: monospace; |
231 | width: 10em; | 231 | width: 10em; |
232 | } | 232 | } |
233 | 233 | ||
234 | table.blob { | 234 | table.blob { |
235 | margin-top: 0.5em; | 235 | margin-top: 0.5em; |
236 | border-top: solid 1px black; | 236 | border-top: solid 1px black; |
237 | } | 237 | } |
238 | 238 | ||
239 | table.blob td.lines { | 239 | table.blob td.lines { |
240 | margin: 0; padding: 0; | 240 | margin: 0; padding: 0 0 0 0.5em; |
241 | vertical-align: top; | 241 | vertical-align: top; |
242 | color: black; | 242 | color: black; |
243 | } | 243 | } |
244 | 244 | ||
245 | table.blob td.linenumbers { | 245 | table.blob td.linenumbers { |
246 | margin: 0; padding: 0; | 246 | margin: 0; padding: 0 0.5em 0 0.5em; |
247 | vertical-align: top; | 247 | vertical-align: top; |
248 | text-align: right; | ||
248 | border-right: 1px solid gray; | 249 | border-right: 1px solid gray; |
249 | background-color: #eee; | ||
250 | } | 250 | } |
251 | 251 | ||
252 | table.blob pre { | 252 | table.blob pre { |
253 | padding: 0; margin: 0; | 253 | padding: 0; margin: 0; |
254 | } | 254 | } |
255 | 255 | ||
256 | table.blob a.no { | 256 | table.blob a.no { |
257 | color: gray; | 257 | color: gray; |
258 | text-align: right; | 258 | text-align: right; |
259 | text-decoration: none; | 259 | text-decoration: none; |
260 | } | 260 | } |
261 | 261 | ||
262 | table.blob a.no a:hover { | 262 | table.blob a.no a:hover { |
263 | color: black; | 263 | color: black; |
264 | } | 264 | } |
265 | 265 | ||
@@ -160,32 +160,33 @@ struct cgit_config { | |||
160 | char *robots; | 160 | char *robots; |
161 | char *root_title; | 161 | char *root_title; |
162 | char *root_desc; | 162 | char *root_desc; |
163 | char *root_readme; | 163 | char *root_readme; |
164 | char *script_name; | 164 | char *script_name; |
165 | char *virtual_root; | 165 | char *virtual_root; |
166 | int cache_size; | 166 | int cache_size; |
167 | int cache_dynamic_ttl; | 167 | int cache_dynamic_ttl; |
168 | int cache_max_create_time; | 168 | int cache_max_create_time; |
169 | int cache_repo_ttl; | 169 | int cache_repo_ttl; |
170 | int cache_root_ttl; | 170 | int cache_root_ttl; |
171 | int cache_static_ttl; | 171 | int cache_static_ttl; |
172 | int embedded; | 172 | int embedded; |
173 | int enable_index_links; | 173 | int enable_index_links; |
174 | int enable_log_filecount; | 174 | int enable_log_filecount; |
175 | int enable_log_linecount; | 175 | int enable_log_linecount; |
176 | int enable_tree_linenumbers; | ||
176 | int local_time; | 177 | int local_time; |
177 | int max_repo_count; | 178 | int max_repo_count; |
178 | int max_commit_count; | 179 | int max_commit_count; |
179 | int max_lock_attempts; | 180 | int max_lock_attempts; |
180 | int max_msg_len; | 181 | int max_msg_len; |
181 | int max_repodesc_len; | 182 | int max_repodesc_len; |
182 | int max_stats; | 183 | int max_stats; |
183 | int nocache; | 184 | int nocache; |
184 | int noplainemail; | 185 | int noplainemail; |
185 | int noheader; | 186 | int noheader; |
186 | int renamelimit; | 187 | int renamelimit; |
187 | int snapshots; | 188 | int snapshots; |
188 | int summary_branches; | 189 | int summary_branches; |
189 | int summary_log; | 190 | int summary_log; |
190 | int summary_tags; | 191 | int summary_tags; |
191 | struct string_list mimetypes; | 192 | struct string_list mimetypes; |
diff --git a/cgitrc.5.txt b/cgitrc.5.txt index 0d18290..3b16db9 100644 --- a/cgitrc.5.txt +++ b/cgitrc.5.txt | |||
@@ -86,32 +86,36 @@ embedded:: | |||
86 | 86 | ||
87 | enable-index-links:: | 87 | enable-index-links:: |
88 | Flag which, when set to "1", will make cgit generate extra links for | 88 | Flag which, when set to "1", will make cgit generate extra links for |
89 | each repo in the repository index (specifically, to the "summary", | 89 | each repo in the repository index (specifically, to the "summary", |
90 | "commit" and "tree" pages). Default value: "0". | 90 | "commit" and "tree" pages). Default value: "0". |
91 | 91 | ||
92 | enable-log-filecount:: | 92 | enable-log-filecount:: |
93 | Flag which, when set to "1", will make cgit print the number of | 93 | Flag which, when set to "1", will make cgit print the number of |
94 | modified files for each commit on the repository log page. Default | 94 | modified files for each commit on the repository log page. Default |
95 | value: "0". | 95 | value: "0". |
96 | 96 | ||
97 | enable-log-linecount:: | 97 | enable-log-linecount:: |
98 | Flag which, when set to "1", will make cgit print the number of added | 98 | Flag which, when set to "1", will make cgit print the number of added |
99 | and removed lines for each commit on the repository log page. Default | 99 | and removed lines for each commit on the repository log page. Default |
100 | value: "0". | 100 | value: "0". |
101 | 101 | ||
102 | enable-tree-linenumbers:: | ||
103 | Flag which, when set to "1", will make cgit generate linenumber links | ||
104 | for plaintext blobs printed in the tree view. Default value: "1". | ||
105 | |||
102 | favicon:: | 106 | favicon:: |
103 | Url used as link to a shortcut icon for cgit. If specified, it is | 107 | Url used as link to a shortcut icon for cgit. If specified, it is |
104 | suggested to use the value "/favicon.ico" since certain browsers will | 108 | suggested to use the value "/favicon.ico" since certain browsers will |
105 | ignore other values. Default value: none. | 109 | ignore other values. Default value: none. |
106 | 110 | ||
107 | footer:: | 111 | footer:: |
108 | The content of the file specified with this option will be included | 112 | The content of the file specified with this option will be included |
109 | verbatim at the bottom of all pages (i.e. it replaces the standard | 113 | verbatim at the bottom of all pages (i.e. it replaces the standard |
110 | "generated by..." message. Default value: none. | 114 | "generated by..." message. Default value: none. |
111 | 115 | ||
112 | head-include:: | 116 | head-include:: |
113 | The content of the file specified with this option will be included | 117 | The content of the file specified with this option will be included |
114 | verbatim in the html HEAD section on all pages. Default value: none. | 118 | verbatim in the html HEAD section on all pages. Default value: none. |
115 | 119 | ||
116 | header:: | 120 | header:: |
117 | The content of the file specified with this option will be included | 121 | The content of the file specified with this option will be included |
@@ -9,55 +9,62 @@ | |||
9 | #include <ctype.h> | 9 | #include <ctype.h> |
10 | #include "cgit.h" | 10 | #include "cgit.h" |
11 | #include "html.h" | 11 | #include "html.h" |
12 | #include "ui-shared.h" | 12 | #include "ui-shared.h" |
13 | 13 | ||
14 | char *curr_rev; | 14 | char *curr_rev; |
15 | char *match_path; | 15 | char *match_path; |
16 | int header = 0; | 16 | int header = 0; |
17 | 17 | ||
18 | static void print_text_buffer(const char *name, char *buf, unsigned long size) | 18 | static void print_text_buffer(const char *name, char *buf, unsigned long size) |
19 | { | 19 | { |
20 | unsigned long lineno, idx; | 20 | unsigned long lineno, idx; |
21 | const char *numberfmt = | 21 | const char *numberfmt = |
22 | "<a class='no' id='n%1$d' name='n%1$d' href='#n%1$d'>%1$d</a>\n"; | 22 | "<a class='no' id='n%1$d' name='n%1$d' href='#n%1$d'>%1$d</a>\n"; |
23 | 23 | ||
24 | html("<table summary='blob content' class='blob'>\n"); | 24 | html("<table summary='blob content' class='blob'>\n"); |
25 | |||
26 | if (ctx.cfg.enable_tree_linenumbers) { | ||
27 | html("<tr><td class='linenumbers'><pre>"); | ||
28 | idx = 0; | ||
29 | lineno = 0; | ||
30 | |||
31 | if (size) { | ||
32 | htmlf(numberfmt, ++lineno); | ||
33 | while(idx < size - 1) { // skip absolute last newline | ||
34 | if (buf[idx] == '\n') | ||
35 | htmlf(numberfmt, ++lineno); | ||
36 | idx++; | ||
37 | } | ||
38 | } | ||
39 | html("</pre></td>\n"); | ||
40 | } | ||
41 | else { | ||
42 | html("<tr>\n"); | ||
43 | } | ||
44 | |||
25 | if (ctx.repo->source_filter) { | 45 | if (ctx.repo->source_filter) { |
26 | html("<tr><td class='lines'><pre><code>"); | 46 | html("<td class='lines'><pre><code>"); |
27 | ctx.repo->source_filter->argv[1] = xstrdup(name); | 47 | ctx.repo->source_filter->argv[1] = xstrdup(name); |
28 | cgit_open_filter(ctx.repo->source_filter); | 48 | cgit_open_filter(ctx.repo->source_filter); |
29 | write(STDOUT_FILENO, buf, size); | 49 | write(STDOUT_FILENO, buf, size); |
30 | cgit_close_filter(ctx.repo->source_filter); | 50 | cgit_close_filter(ctx.repo->source_filter); |
31 | html("</code></pre></td></tr></table>\n"); | 51 | html("</code></pre></td></tr></table>\n"); |
32 | return; | 52 | return; |
33 | } | 53 | } |
34 | 54 | ||
35 | html("<tr><td class='linenumbers'><pre>"); | ||
36 | idx = 0; | ||
37 | lineno = 0; | ||
38 | |||
39 | if (size) { | ||
40 | htmlf(numberfmt, ++lineno); | ||
41 | while(idx < size - 1) { // skip absolute last newline | ||
42 | if (buf[idx] == '\n') | ||
43 | htmlf(numberfmt, ++lineno); | ||
44 | idx++; | ||
45 | } | ||
46 | } | ||
47 | html("</pre></td>\n"); | ||
48 | html("<td class='lines'><pre><code>"); | 55 | html("<td class='lines'><pre><code>"); |
49 | html_txt(buf); | 56 | html_txt(buf); |
50 | html("</code></pre></td></tr></table>\n"); | 57 | html("</code></pre></td></tr></table>\n"); |
51 | } | 58 | } |
52 | 59 | ||
53 | #define ROWLEN 32 | 60 | #define ROWLEN 32 |
54 | 61 | ||
55 | static void print_binary_buffer(char *buf, unsigned long size) | 62 | static void print_binary_buffer(char *buf, unsigned long size) |
56 | { | 63 | { |
57 | unsigned long ofs, idx; | 64 | unsigned long ofs, idx; |
58 | static char ascii[ROWLEN + 1]; | 65 | static char ascii[ROWLEN + 1]; |
59 | 66 | ||
60 | html("<table summary='blob content' class='bin-blob'>\n"); | 67 | html("<table summary='blob content' class='bin-blob'>\n"); |
61 | html("<tr><th>ofs</th><th>hex dump</th><th>ascii</th></tr>"); | 68 | html("<tr><th>ofs</th><th>hex dump</th><th>ascii</th></tr>"); |
62 | for (ofs = 0; ofs < size; ofs += ROWLEN, buf += ROWLEN) { | 69 | for (ofs = 0; ofs < size; ofs += ROWLEN, buf += ROWLEN) { |
63 | htmlf("<tr><td class='right'>%04x</td><td class='hex'>", ofs); | 70 | htmlf("<tr><td class='right'>%04x</td><td class='hex'>", ofs); |