summaryrefslogtreecommitdiffabout
authorFlorian Pritz <bluewind@xssn.at>2009-08-09 20:42:45 (UTC)
committer Lars Hjemli <hjemli@gmail.com>2009-08-21 12:17:49 (UTC)
commitd67cc7f9d556650438e421cdcda37bc52710bffd (patch) (unidiff)
treedf131c58de7c712550f124f8fb15aef303ff6054
parent03389d6e67bfda5cb3ff1504db815f09715ec6f4 (diff)
downloadcgit-d67cc7f9d556650438e421cdcda37bc52710bffd.zip
cgit-d67cc7f9d556650438e421cdcda37bc52710bffd.tar.gz
cgit-d67cc7f9d556650438e421cdcda37bc52710bffd.tar.bz2
Add 'linenumbers' config option
Signed-off-by: Florian Pritz <bluewind@xssn.at> Signed-off-by: Lars Hjemli <hjemli@gmail.com>
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--cgit.c2
-rw-r--r--cgit.h1
-rw-r--r--cgitrc.5.txt4
-rw-r--r--ui-tree.c27
4 files changed, 23 insertions, 11 deletions
diff --git a/cgit.c b/cgit.c
index b0e1c44..a4788cb 100644
--- a/cgit.c
+++ b/cgit.c
@@ -37,64 +37,66 @@ struct cgit_filter *new_filter(const char *cmd, int extra_args)
37 f->argv = xmalloc((2 + extra_args) * sizeof(char *)); 37 f->argv = xmalloc((2 + extra_args) * sizeof(char *));
38 f->argv[0] = f->cmd; 38 f->argv[0] = f->cmd;
39 f->argv[1] = NULL; 39 f->argv[1] = NULL;
40 return f; 40 return f;
41} 41}
42 42
43void config_cb(const char *name, const char *value) 43void config_cb(const char *name, const char *value)
44{ 44{
45 if (!strcmp(name, "root-title")) 45 if (!strcmp(name, "root-title"))
46 ctx.cfg.root_title = xstrdup(value); 46 ctx.cfg.root_title = xstrdup(value);
47 else if (!strcmp(name, "root-desc")) 47 else if (!strcmp(name, "root-desc"))
48 ctx.cfg.root_desc = xstrdup(value); 48 ctx.cfg.root_desc = xstrdup(value);
49 else if (!strcmp(name, "root-readme")) 49 else if (!strcmp(name, "root-readme"))
50 ctx.cfg.root_readme = xstrdup(value); 50 ctx.cfg.root_readme = xstrdup(value);
51 else if (!strcmp(name, "css")) 51 else if (!strcmp(name, "css"))
52 ctx.cfg.css = xstrdup(value); 52 ctx.cfg.css = xstrdup(value);
53 else if (!strcmp(name, "favicon")) 53 else if (!strcmp(name, "favicon"))
54 ctx.cfg.favicon = xstrdup(value); 54 ctx.cfg.favicon = xstrdup(value);
55 else if (!strcmp(name, "footer")) 55 else if (!strcmp(name, "footer"))
56 ctx.cfg.footer = xstrdup(value); 56 ctx.cfg.footer = xstrdup(value);
57 else if (!strcmp(name, "head-include")) 57 else if (!strcmp(name, "head-include"))
58 ctx.cfg.head_include = xstrdup(value); 58 ctx.cfg.head_include = xstrdup(value);
59 else if (!strcmp(name, "header")) 59 else if (!strcmp(name, "header"))
60 ctx.cfg.header = xstrdup(value); 60 ctx.cfg.header = xstrdup(value);
61 else if (!strcmp(name, "logo")) 61 else if (!strcmp(name, "logo"))
62 ctx.cfg.logo = xstrdup(value); 62 ctx.cfg.logo = xstrdup(value);
63 else if (!strcmp(name, "index-header")) 63 else if (!strcmp(name, "index-header"))
64 ctx.cfg.index_header = xstrdup(value); 64 ctx.cfg.index_header = xstrdup(value);
65 else if (!strcmp(name, "index-info")) 65 else if (!strcmp(name, "index-info"))
66 ctx.cfg.index_info = xstrdup(value); 66 ctx.cfg.index_info = xstrdup(value);
67 else if (!strcmp(name, "logo-link")) 67 else if (!strcmp(name, "logo-link"))
68 ctx.cfg.logo_link = xstrdup(value); 68 ctx.cfg.logo_link = xstrdup(value);
69 else if (!strcmp(name, "linenumbers"))
70 ctx.cfg.linenumbers = atoi(value);
69 else if (!strcmp(name, "module-link")) 71 else if (!strcmp(name, "module-link"))
70 ctx.cfg.module_link = xstrdup(value); 72 ctx.cfg.module_link = xstrdup(value);
71 else if (!strcmp(name, "virtual-root")) { 73 else if (!strcmp(name, "virtual-root")) {
72 ctx.cfg.virtual_root = trim_end(value, '/'); 74 ctx.cfg.virtual_root = trim_end(value, '/');
73 if (!ctx.cfg.virtual_root && (!strcmp(value, "/"))) 75 if (!ctx.cfg.virtual_root && (!strcmp(value, "/")))
74 ctx.cfg.virtual_root = ""; 76 ctx.cfg.virtual_root = "";
75 } else if (!strcmp(name, "nocache")) 77 } else if (!strcmp(name, "nocache"))
76 ctx.cfg.nocache = atoi(value); 78 ctx.cfg.nocache = atoi(value);
77 else if (!strcmp(name, "noplainemail")) 79 else if (!strcmp(name, "noplainemail"))
78 ctx.cfg.noplainemail = atoi(value); 80 ctx.cfg.noplainemail = atoi(value);
79 else if (!strcmp(name, "noheader")) 81 else if (!strcmp(name, "noheader"))
80 ctx.cfg.noheader = atoi(value); 82 ctx.cfg.noheader = atoi(value);
81 else if (!strcmp(name, "snapshots")) 83 else if (!strcmp(name, "snapshots"))
82 ctx.cfg.snapshots = cgit_parse_snapshots_mask(value); 84 ctx.cfg.snapshots = cgit_parse_snapshots_mask(value);
83 else if (!strcmp(name, "enable-index-links")) 85 else if (!strcmp(name, "enable-index-links"))
84 ctx.cfg.enable_index_links = atoi(value); 86 ctx.cfg.enable_index_links = atoi(value);
85 else if (!strcmp(name, "enable-log-filecount")) 87 else if (!strcmp(name, "enable-log-filecount"))
86 ctx.cfg.enable_log_filecount = atoi(value); 88 ctx.cfg.enable_log_filecount = atoi(value);
87 else if (!strcmp(name, "enable-log-linecount")) 89 else if (!strcmp(name, "enable-log-linecount"))
88 ctx.cfg.enable_log_linecount = atoi(value); 90 ctx.cfg.enable_log_linecount = 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);
diff --git a/cgit.h b/cgit.h
index adb8da4..2fdc531 100644
--- a/cgit.h
+++ b/cgit.h
@@ -145,64 +145,65 @@ struct cgit_query {
145struct cgit_config { 145struct cgit_config {
146 char *agefile; 146 char *agefile;
147 char *cache_root; 147 char *cache_root;
148 char *clone_prefix; 148 char *clone_prefix;
149 char *css; 149 char *css;
150 char *favicon; 150 char *favicon;
151 char *footer; 151 char *footer;
152 char *head_include; 152 char *head_include;
153 char *header; 153 char *header;
154 char *index_header; 154 char *index_header;
155 char *index_info; 155 char *index_info;
156 char *logo; 156 char *logo;
157 char *logo_link; 157 char *logo_link;
158 char *module_link; 158 char *module_link;
159 char *repo_group; 159 char *repo_group;
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 local_time; 176 int local_time;
177 int linenumbers;
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;
192 struct cgit_filter *about_filter; 193 struct cgit_filter *about_filter;
193 struct cgit_filter *commit_filter; 194 struct cgit_filter *commit_filter;
194 struct cgit_filter *source_filter; 195 struct cgit_filter *source_filter;
195}; 196};
196 197
197struct cgit_page { 198struct cgit_page {
198 time_t modified; 199 time_t modified;
199 time_t expires; 200 time_t expires;
200 size_t size; 201 size_t size;
201 char *mimetype; 202 char *mimetype;
202 char *charset; 203 char *charset;
203 char *filename; 204 char *filename;
204 char *etag; 205 char *etag;
205 char *title; 206 char *title;
206 int status; 207 int status;
207 char *statusmsg; 208 char *statusmsg;
208}; 209};
diff --git a/cgitrc.5.txt b/cgitrc.5.txt
index 3c35b02..a762ccc 100644
--- a/cgitrc.5.txt
+++ b/cgitrc.5.txt
@@ -117,64 +117,68 @@ header::
117 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
118 verbatim at the top of all pages. Default value: none. 118 verbatim at the top of all pages. Default value: none.
119 119
120include:: 120include::
121 Name of a configfile to include before the rest of the current config- 121 Name of a configfile to include before the rest of the current config-
122 file is parsed. Default value: none. 122 file is parsed. Default value: none.
123 123
124index-header:: 124index-header::
125 The content of the file specified with this option will be included 125 The content of the file specified with this option will be included
126 verbatim above the repository index. This setting is deprecated, and 126 verbatim above the repository index. This setting is deprecated, and
127 will not be supported by cgit-1.0 (use root-readme instead). Default 127 will not be supported by cgit-1.0 (use root-readme instead). Default
128 value: none. 128 value: none.
129 129
130index-info:: 130index-info::
131 The content of the file specified with this option will be included 131 The content of the file specified with this option will be included
132 verbatim below the heading on the repository index page. This setting 132 verbatim below the heading on the repository index page. This setting
133 is deprecated, and will not be supported by cgit-1.0 (use root-desc 133 is deprecated, and will not be supported by cgit-1.0 (use root-desc
134 instead). Default value: none. 134 instead). Default value: none.
135 135
136local-time:: 136local-time::
137 Flag which, if set to "1", makes cgit print commit and tag times in the 137 Flag which, if set to "1", makes cgit print commit and tag times in the
138 servers timezone. Default value: "0". 138 servers timezone. Default value: "0".
139 139
140logo:: 140logo::
141 Url which specifies the source of an image which will be used as a logo 141 Url which specifies the source of an image which will be used as a logo
142 on all cgit pages. Default value: "/cgit.png". 142 on all cgit pages. Default value: "/cgit.png".
143 143
144logo-link:: 144logo-link::
145 Url loaded when clicking on the cgit logo image. If unspecified the 145 Url loaded when clicking on the cgit logo image. If unspecified the
146 calculated url of the repository index page will be used. Default 146 calculated url of the repository index page will be used. Default
147 value: none. 147 value: none.
148 148
149linenumbers::
150 If set to "1" lines in tree view will have numbers.
151 Default value: "0".
152
149max-commit-count:: 153max-commit-count::
150 Specifies the number of entries to list per page in "log" view. Default 154 Specifies the number of entries to list per page in "log" view. Default
151 value: "50". 155 value: "50".
152 156
153max-message-length:: 157max-message-length::
154 Specifies the maximum number of commit message characters to display in 158 Specifies the maximum number of commit message characters to display in
155 "log" view. Default value: "80". 159 "log" view. Default value: "80".
156 160
157max-repo-count:: 161max-repo-count::
158 Specifies the number of entries to list per page on therepository 162 Specifies the number of entries to list per page on therepository
159 index page. Default value: "50". 163 index page. Default value: "50".
160 164
161max-repodesc-length:: 165max-repodesc-length::
162 Specifies the maximum number of repo description characters to display 166 Specifies the maximum number of repo description characters to display
163 on the repository index page. Default value: "80". 167 on the repository index page. Default value: "80".
164 168
165max-stats:: 169max-stats::
166 Set the default maximum statistics period. Valid values are "week", 170 Set the default maximum statistics period. Valid values are "week",
167 "month", "quarter" and "year". If unspecified, statistics are 171 "month", "quarter" and "year". If unspecified, statistics are
168 disabled. Default value: none. See also: "repo.max-stats". 172 disabled. Default value: none. See also: "repo.max-stats".
169 173
170mimetype.<ext>:: 174mimetype.<ext>::
171 Set the mimetype for the specified filename extension. This is used 175 Set the mimetype for the specified filename extension. This is used
172 by the `plain` command when returning blob content. 176 by the `plain` command when returning blob content.
173 177
174module-link:: 178module-link::
175 Text which will be used as the formatstring for a hyperlink when a 179 Text which will be used as the formatstring for a hyperlink when a
176 submodule is printed in a directory listing. The arguments for the 180 submodule is printed in a directory listing. The arguments for the
177 formatstring are the path and SHA1 of the submodule commit. Default 181 formatstring are the path and SHA1 of the submodule commit. Default
178 value: "./?repo=%s&page=commit&id=%s" 182 value: "./?repo=%s&page=commit&id=%s"
179 183
180nocache:: 184nocache::
diff --git a/ui-tree.c b/ui-tree.c
index 7bf2ad2..f64e6e0 100644
--- a/ui-tree.c
+++ b/ui-tree.c
@@ -1,70 +1,75 @@
1/* ui-tree.c: functions for tree output 1/* ui-tree.c: functions for tree output
2 * 2 *
3 * Copyright (C) 2006 Lars Hjemli 3 * Copyright (C) 2006 Lars Hjemli
4 * 4 *
5 * Licensed under GNU General Public License v2 5 * Licensed under GNU General Public License v2
6 * (see COPYING for full license text) 6 * (see COPYING for full license text)
7 */ 7 */
8 8
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
14char *curr_rev; 14char *curr_rev;
15char *match_path; 15char *match_path;
16int header = 0; 16int header = 0;
17 17
18static void print_text_buffer(const char *name, char *buf, unsigned long size) 18static 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 25
26 html("<tr><td class='linenumbers'><pre>"); 26 if (ctx.cfg.linenumbers) {
27 idx = 0; 27 html("<tr><td class='linenumbers'><pre>");
28 lineno = 0; 28 idx = 0;
29 29 lineno = 0;
30 if (size) { 30
31 htmlf(numberfmt, ++lineno); 31 if (size) {
32 while(idx < size - 1) { // skip absolute last newline 32 htmlf(numberfmt, ++lineno);
33 if (buf[idx] == '\n') 33 while(idx < size - 1) { // skip absolute last newline
34 htmlf(numberfmt, ++lineno); 34 if (buf[idx] == '\n')
35 idx++; 35 htmlf(numberfmt, ++lineno);
36 idx++;
37 }
36 } 38 }
39 html("</pre></td>\n");
40 }
41 else {
42 html("<tr>\n");
37 } 43 }
38 html("</pre></td>\n");
39 44
40 if (ctx.repo->source_filter) { 45 if (ctx.repo->source_filter) {
41 html("<td class='lines'><pre><code>"); 46 html("<td class='lines'><pre><code>");
42 ctx.repo->source_filter->argv[1] = xstrdup(name); 47 ctx.repo->source_filter->argv[1] = xstrdup(name);
43 cgit_open_filter(ctx.repo->source_filter); 48 cgit_open_filter(ctx.repo->source_filter);
44 write(STDOUT_FILENO, buf, size); 49 write(STDOUT_FILENO, buf, size);
45 cgit_close_filter(ctx.repo->source_filter); 50 cgit_close_filter(ctx.repo->source_filter);
46 html("</code></pre></td></tr></table>\n"); 51 html("</code></pre></td></tr></table>\n");
47 return; 52 return;
48 } 53 }
49 54
50 html("<td class='lines'><pre><code>"); 55 html("<td class='lines'><pre><code>");
51 html_txt(buf); 56 html_txt(buf);
52 html("</code></pre></td></tr></table>\n"); 57 html("</code></pre></td></tr></table>\n");
53} 58}
54 59
55#define ROWLEN 32 60#define ROWLEN 32
56 61
57static void print_binary_buffer(char *buf, unsigned long size) 62static void print_binary_buffer(char *buf, unsigned long size)
58{ 63{
59 unsigned long ofs, idx; 64 unsigned long ofs, idx;
60 static char ascii[ROWLEN + 1]; 65 static char ascii[ROWLEN + 1];
61 66
62 html("<table summary='blob content' class='bin-blob'>\n"); 67 html("<table summary='blob content' class='bin-blob'>\n");
63 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>");
64 for (ofs = 0; ofs < size; ofs += ROWLEN, buf += ROWLEN) { 69 for (ofs = 0; ofs < size; ofs += ROWLEN, buf += ROWLEN) {
65 htmlf("<tr><td class='right'>%04x</td><td class='hex'>", ofs); 70 htmlf("<tr><td class='right'>%04x</td><td class='hex'>", ofs);
66 for (idx = 0; idx < ROWLEN && ofs + idx < size; idx++) 71 for (idx = 0; idx < ROWLEN && ofs + idx < size; idx++)
67 htmlf("%*s%02x", 72 htmlf("%*s%02x",
68 idx == 16 ? 4 : 1, "", 73 idx == 16 ? 4 : 1, "",
69 buf[idx] & 0xff); 74 buf[idx] & 0xff);
70 html(" </td><td class='hex'>"); 75 html(" </td><td class='hex'>");