summaryrefslogtreecommitdiffabout
authorLars Hjemli <hjemli@gmail.com>2007-07-22 22:46:15 (UTC)
committer Lars Hjemli <hjemli@gmail.com>2007-07-22 22:47:18 (UTC)
commitf405d0bf75427c627778027e9900359335d6774e (patch) (unidiff)
tree2db75faf97df382edc7667cd8cd06e833361a937
parenteb45342e735818b3c68cbab9b61b23e79ae74418 (diff)
downloadcgit-f405d0bf75427c627778027e9900359335d6774e.zip
cgit-f405d0bf75427c627778027e9900359335d6774e.tar.gz
cgit-f405d0bf75427c627778027e9900359335d6774e.tar.bz2
Add support for line number in url fragment
With this change, urls like http://hjemli.net/git/cgit/tree/ui-tree.c#43 can be used to jump directly to the specified line number. Signed-off-by: Lars Hjemli <hjemli@gmail.com>
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--cgit.css9
-rw-r--r--ui-tree.c2
2 files changed, 10 insertions, 1 deletions
diff --git a/cgit.css b/cgit.css
index 43a40a3..54bbfcc 100644
--- a/cgit.css
+++ b/cgit.css
@@ -1,427 +1,436 @@
1body { 1body {
2 font-family: arial, sans-serif; 2 font-family: arial, sans-serif;
3 font-size: 11pt; 3 font-size: 11pt;
4 color: black; 4 color: black;
5 background: white; 5 background: white;
6} 6}
7 7
8body, table { 8body, table {
9 padding: 0em; 9 padding: 0em;
10 margin: 0em; 10 margin: 0em;
11} 11}
12 12
13table { 13table {
14 border-collapse: collapse; 14 border-collapse: collapse;
15} 15}
16 16
17h2 { 17h2 {
18 font-size: 120%; 18 font-size: 120%;
19 font-weight: bold; 19 font-weight: bold;
20 margin-top: 0em; 20 margin-top: 0em;
21 margin-bottom: 0.25em; 21 margin-bottom: 0.25em;
22} 22}
23 23
24h3 { 24h3 {
25 margin-top: 0em; 25 margin-top: 0em;
26 font-size: 100%; 26 font-size: 100%;
27 font-weight: normal; 27 font-weight: normal;
28} 28}
29 29
30h4 { 30h4 {
31 margin-top: 1.5em; 31 margin-top: 1.5em;
32 margin-bottom: 0.1em; 32 margin-bottom: 0.1em;
33 font-size: 100%; 33 font-size: 100%;
34 font-weight: bold; 34 font-weight: bold;
35} 35}
36 36
37a { 37a {
38 color: blue; 38 color: blue;
39 text-decoration: none; 39 text-decoration: none;
40} 40}
41 41
42a:hover { 42a:hover {
43 text-decoration: underline; 43 text-decoration: underline;
44} 44}
45 45
46table.list { 46table.list {
47 border: none; 47 border: none;
48 border-collapse: collapse; 48 border-collapse: collapse;
49} 49}
50 50
51table.list tr { 51table.list tr {
52 background: white; 52 background: white;
53} 53}
54 54
55table.list tr:hover { 55table.list tr:hover {
56 background: #eee; 56 background: #eee;
57} 57}
58 58
59table.list tr.nohover:hover { 59table.list tr.nohover:hover {
60 background: white; 60 background: white;
61} 61}
62 62
63table.list th { 63table.list th {
64 font-weight: bold; 64 font-weight: bold;
65 border-bottom: solid 1px #777; 65 border-bottom: solid 1px #777;
66 padding: 0.1em 0.5em 0.1em 0.5em; 66 padding: 0.1em 0.5em 0.1em 0.5em;
67 vertical-align: baseline; 67 vertical-align: baseline;
68} 68}
69 69
70table.list td { 70table.list td {
71 border: none; 71 border: none;
72 padding: 0.1em 0.5em 0.1em 0.5em; 72 padding: 0.1em 0.5em 0.1em 0.5em;
73} 73}
74 74
75img { 75img {
76 border: none; 76 border: none;
77} 77}
78 78
79table#layout { 79table#layout {
80 width: 100%; 80 width: 100%;
81 border-collapse: collapse; 81 border-collapse: collapse;
82 margin: 0px; 82 margin: 0px;
83} 83}
84 84
85td#header, td#logo { 85td#header, td#logo {
86 color: #666; 86 color: #666;
87 background-color: #ddd; 87 background-color: #ddd;
88 border-bottom: solid 1px #000; 88 border-bottom: solid 1px #000;
89} 89}
90 90
91td#header { 91td#header {
92 font-size: 150%; 92 font-size: 150%;
93 font-weight: bold; 93 font-weight: bold;
94 padding: 0.2em 0.5em; 94 padding: 0.2em 0.5em;
95 vertical-align: text-bottom; 95 vertical-align: text-bottom;
96} 96}
97 97
98td#header a { 98td#header a {
99 color: #666; 99 color: #666;
100} 100}
101 101
102td#header a:hoved { 102td#header a:hoved {
103 text-decoration: underline; 103 text-decoration: underline;
104} 104}
105 105
106td#logo { 106td#logo {
107 text-align: right; 107 text-align: right;
108 vertical-align: middle; 108 vertical-align: middle;
109 padding-right: 0.5em; 109 padding-right: 0.5em;
110} 110}
111 111
112td#crumb, td#search { 112td#crumb, td#search {
113 color: #ccc; 113 color: #ccc;
114 border-top: solid 3px #555; 114 border-top: solid 3px #555;
115 background-color: #666; 115 background-color: #666;
116 border-bottom: solid 1px #333; 116 border-bottom: solid 1px #333;
117 padding: 2px 1em; 117 padding: 2px 1em;
118} 118}
119 119
120td#crumb { 120td#crumb {
121 font-weight: bold; 121 font-weight: bold;
122} 122}
123 123
124td#crumb a { 124td#crumb a {
125 color: #ccc; 125 color: #ccc;
126 background-color: #666; 126 background-color: #666;
127 padding: 0em 0.5em 0em 0.5em; 127 padding: 0em 0.5em 0em 0.5em;
128} 128}
129 129
130td#crumb a:hover { 130td#crumb a:hover {
131 color: #666; 131 color: #666;
132 background-color: #ccc; 132 background-color: #ccc;
133 text-decoration: none; 133 text-decoration: none;
134} 134}
135 135
136td#search { 136td#search {
137 text-align: right; 137 text-align: right;
138 vertical-align: middle; 138 vertical-align: middle;
139 padding-right: 0.5em; 139 padding-right: 0.5em;
140} 140}
141 141
142td#search form { 142td#search form {
143 margin: 0px; 143 margin: 0px;
144 padding: 0px; 144 padding: 0px;
145} 145}
146 146
147td#search input { 147td#search input {
148 font-size: 9pt; 148 font-size: 9pt;
149 padding: 0px; 149 padding: 0px;
150 width: 10em; 150 width: 10em;
151 border: solid 1px #333; 151 border: solid 1px #333;
152 color: #333; 152 color: #333;
153 background-color: #fff; 153 background-color: #fff;
154} 154}
155 155
156div#summary { 156div#summary {
157 vertical-align: top; 157 vertical-align: top;
158 margin-bottom: 1em; 158 margin-bottom: 1em;
159} 159}
160 160
161table#downloads { 161table#downloads {
162 float: right; 162 float: right;
163 border-collapse: collapse; 163 border-collapse: collapse;
164 border: solid 1px #777; 164 border: solid 1px #777;
165 margin-left: 0.5em; 165 margin-left: 0.5em;
166 margin-bottom: 0.5em; 166 margin-bottom: 0.5em;
167} 167}
168 168
169table#downloads th { 169table#downloads th {
170 background-color: #ccc; 170 background-color: #ccc;
171} 171}
172 172
173td#content { 173td#content {
174 padding: 1em 0.5em; 174 padding: 1em 0.5em;
175} 175}
176 176
177div#blob { 177div#blob {
178 border: solid 1px black; 178 border: solid 1px black;
179} 179}
180 180
181div.error { 181div.error {
182 color: red; 182 color: red;
183 font-weight: bold; 183 font-weight: bold;
184 margin: 1em 2em; 184 margin: 1em 2em;
185} 185}
186 186
187a.ls-blob, a.ls-dir, a.ls-mod { 187a.ls-blob, a.ls-dir, a.ls-mod {
188 font-family: monospace; 188 font-family: monospace;
189} 189}
190 190
191td.ls-size { 191td.ls-size {
192 text-align: right; 192 text-align: right;
193} 193}
194 194
195td.ls-size { 195td.ls-size {
196 font-family: monospace; 196 font-family: monospace;
197} 197}
198 198
199td.ls-mode { 199td.ls-mode {
200 font-family: monospace; 200 font-family: monospace;
201} 201}
202 202
203table.blob { 203table.blob {
204 margin-top: 0.5em; 204 margin-top: 0.5em;
205 border-top: solid 1px black; 205 border-top: solid 1px black;
206} 206}
207 207
208table.blob td.no { 208table.blob td.no {
209 border-right: solid 1px black; 209 border-right: solid 1px black;
210 color: black; 210 color: black;
211 background-color: #eee; 211 background-color: #eee;
212 text-align: right; 212 text-align: right;
213} 213}
214 214
215table.blob td.no a {
216 color: black;
217}
218
219table.blob td.no a:hover {
220 color: black;
221 text-decoration: none;
222}
223
215table.blob td.txt { 224table.blob td.txt {
216 white-space: pre; 225 white-space: pre;
217 font-family: monospace; 226 font-family: monospace;
218 padding-left: 0.5em; 227 padding-left: 0.5em;
219} 228}
220 229
221table.nowrap td { 230table.nowrap td {
222 white-space: nowrap; 231 white-space: nowrap;
223} 232}
224 233
225table.commit-info { 234table.commit-info {
226 border-collapse: collapse; 235 border-collapse: collapse;
227 margin-top: 1.5em; 236 margin-top: 1.5em;
228} 237}
229 238
230table.commit-info th { 239table.commit-info th {
231 text-align: left; 240 text-align: left;
232 font-weight: normal; 241 font-weight: normal;
233 padding: 0.1em 1em 0.1em 0.1em; 242 padding: 0.1em 1em 0.1em 0.1em;
234 vertical-align: top; 243 vertical-align: top;
235} 244}
236 245
237table.commit-info td { 246table.commit-info td {
238 font-weight: normal; 247 font-weight: normal;
239 padding: 0.1em 1em 0.1em 0.1em; 248 padding: 0.1em 1em 0.1em 0.1em;
240} 249}
241 250
242div.commit-subject { 251div.commit-subject {
243 font-weight: bold; 252 font-weight: bold;
244 font-size: 125%; 253 font-size: 125%;
245 margin: 1.5em 0em 0.5em 0em; 254 margin: 1.5em 0em 0.5em 0em;
246 padding: 0em; 255 padding: 0em;
247} 256}
248 257
249div.commit-msg { 258div.commit-msg {
250 white-space: pre; 259 white-space: pre;
251 font-family: monospace; 260 font-family: monospace;
252} 261}
253 262
254div.diffstat-header { 263div.diffstat-header {
255 font-weight: bold; 264 font-weight: bold;
256 padding-top: 1.5em; 265 padding-top: 1.5em;
257} 266}
258 267
259table.diffstat { 268table.diffstat {
260 border-collapse: collapse; 269 border-collapse: collapse;
261 width: 100%; 270 width: 100%;
262 border: solid 1px #aaa; 271 border: solid 1px #aaa;
263 background-color: #eee; 272 background-color: #eee;
264} 273}
265 274
266table.diffstat tr:hover { 275table.diffstat tr:hover {
267 background-color: #ccc; 276 background-color: #ccc;
268} 277}
269 278
270table.diffstat th { 279table.diffstat th {
271 font-weight: normal; 280 font-weight: normal;
272 text-align: left; 281 text-align: left;
273 text-decoration: underline; 282 text-decoration: underline;
274 padding: 0.1em 1em 0.1em 0.1em; 283 padding: 0.1em 1em 0.1em 0.1em;
275 font-size: 100%; 284 font-size: 100%;
276} 285}
277 286
278table.diffstat td { 287table.diffstat td {
279 padding: 0.2em 0.2em 0.1em 0.1em; 288 padding: 0.2em 0.2em 0.1em 0.1em;
280 font-size: 100%; 289 font-size: 100%;
281 border: none; 290 border: none;
282} 291}
283 292
284table.diffstat td.mode { 293table.diffstat td.mode {
285 white-space: nowrap; 294 white-space: nowrap;
286} 295}
287 296
288table.diffstat td span.modechange { 297table.diffstat td span.modechange {
289 padding-left: 1em; 298 padding-left: 1em;
290 color: red; 299 color: red;
291} 300}
292 301
293table.diffstat td.add a { 302table.diffstat td.add a {
294 color: green; 303 color: green;
295} 304}
296 305
297table.diffstat td.del a { 306table.diffstat td.del a {
298 color: red; 307 color: red;
299} 308}
300 309
301table.diffstat td.upd a { 310table.diffstat td.upd a {
302 color: blue; 311 color: blue;
303} 312}
304 313
305table.diffstat td.graph { 314table.diffstat td.graph {
306 width: 75%; 315 width: 75%;
307 vertical-align: middle; 316 vertical-align: middle;
308} 317}
309 318
310table.diffstat td.graph table { 319table.diffstat td.graph table {
311 border: none; 320 border: none;
312} 321}
313 322
314table.diffstat td.graph td { 323table.diffstat td.graph td {
315 padding: 0px; 324 padding: 0px;
316 border: 0px; 325 border: 0px;
317 height: 7pt; 326 height: 7pt;
318} 327}
319 328
320table.diffstat td.graph td.add { 329table.diffstat td.graph td.add {
321 background-color: #5c5; 330 background-color: #5c5;
322} 331}
323 332
324table.diffstat td.graph td.rem { 333table.diffstat td.graph td.rem {
325 background-color: #c55; 334 background-color: #c55;
326} 335}
327 336
328div.diffstat-summary { 337div.diffstat-summary {
329 color: #888; 338 color: #888;
330 padding-top: 0.5em; 339 padding-top: 0.5em;
331} 340}
332 341
333table.diff td { 342table.diff td {
334 font-family: monospace; 343 font-family: monospace;
335 white-space: pre; 344 white-space: pre;
336} 345}
337 346
338table.diff td div.head { 347table.diff td div.head {
339 font-weight: bold; 348 font-weight: bold;
340 padding-top: 1em; 349 padding-top: 1em;
341} 350}
342 351
343table.diff td div.hunk { 352table.diff td div.hunk {
344 color: #009; 353 color: #009;
345} 354}
346 355
347table.diff td div.add { 356table.diff td div.add {
348 color: green; 357 color: green;
349} 358}
350 359
351table.diff td div.del { 360table.diff td div.del {
352 color: red; 361 color: red;
353} 362}
354 363
355.sha1 { 364.sha1 {
356 font-family: monospace; 365 font-family: monospace;
357 font-size: 90%; 366 font-size: 90%;
358} 367}
359 368
360.left { 369.left {
361 text-align: left; 370 text-align: left;
362} 371}
363 372
364.right { 373.right {
365 text-align: right; 374 text-align: right;
366} 375}
367 376
368table.list td.repogroup { 377table.list td.repogroup {
369 font-style: italic; 378 font-style: italic;
370 color: #888; 379 color: #888;
371} 380}
372 381
373a.button { 382a.button {
374 font-size: 80%; 383 font-size: 80%;
375 color: #aaa; 384 color: #aaa;
376 background-color: #eee; 385 background-color: #eee;
377 border: solid 1px #aaa; 386 border: solid 1px #aaa;
378 padding: 0em 0.5em; 387 padding: 0em 0.5em;
379 margin: 0.1em 0.25em; 388 margin: 0.1em 0.25em;
380} 389}
381 390
382a.button:hover { 391a.button:hover {
383 text-decoration: none; 392 text-decoration: none;
384 color: #333; 393 color: #333;
385 background-color: #ccc; 394 background-color: #ccc;
386} 395}
387 396
388a.primary { 397a.primary {
389 font-size: 100%; 398 font-size: 100%;
390} 399}
391 400
392a.secondary { 401a.secondary {
393 font-size: 90%; 402 font-size: 90%;
394} 403}
395 404
396td.toplevel-repo { 405td.toplevel-repo {
397 406
398} 407}
399 408
400table.list td.sublevel-repo { 409table.list td.sublevel-repo {
401 padding-left: 1.5em; 410 padding-left: 1.5em;
402} 411}
403 412
404span.age-mins { 413span.age-mins {
405 font-weight: bold; 414 font-weight: bold;
406 color: #080; 415 color: #080;
407} 416}
408 417
409span.age-hours { 418span.age-hours {
410 color: #080; 419 color: #080;
411} 420}
412 421
413span.age-days { 422span.age-days {
414 color: #040; 423 color: #040;
415} 424}
416 425
417span.age-weeks { 426span.age-weeks {
418 color: #444; 427 color: #444;
419} 428}
420 429
421span.age-months { 430span.age-months {
422 color: #888; 431 color: #888;
423} 432}
424 433
425span.age-years { 434span.age-years {
426 color: #bbb; 435 color: #bbb;
427} 436}
diff --git a/ui-tree.c b/ui-tree.c
index 75ce449..634132f 100644
--- a/ui-tree.c
+++ b/ui-tree.c
@@ -1,213 +1,213 @@
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 "cgit.h" 9#include "cgit.h"
10 10
11char *curr_rev; 11char *curr_rev;
12char *match_path; 12char *match_path;
13int header = 0; 13int header = 0;
14 14
15static void print_object(const unsigned char *sha1, char *path) 15static void print_object(const unsigned char *sha1, char *path)
16{ 16{
17 enum object_type type; 17 enum object_type type;
18 unsigned char *buf; 18 unsigned char *buf;
19 unsigned long size, lineno, start, idx; 19 unsigned long size, lineno, start, idx;
20 20
21 type = sha1_object_info(sha1, &size); 21 type = sha1_object_info(sha1, &size);
22 if (type == OBJ_BAD) { 22 if (type == OBJ_BAD) {
23 cgit_print_error(fmt("Bad object name: %s", 23 cgit_print_error(fmt("Bad object name: %s",
24 sha1_to_hex(sha1))); 24 sha1_to_hex(sha1)));
25 return; 25 return;
26 } 26 }
27 27
28 buf = read_sha1_file(sha1, &type, &size); 28 buf = read_sha1_file(sha1, &type, &size);
29 if (!buf) { 29 if (!buf) {
30 cgit_print_error(fmt("Error reading object %s", 30 cgit_print_error(fmt("Error reading object %s",
31 sha1_to_hex(sha1))); 31 sha1_to_hex(sha1)));
32 return; 32 return;
33 } 33 }
34 34
35 html(" blob: <a href='"); 35 html(" blob: <a href='");
36 html_attr(cgit_pageurl(cgit_query_repo, "blob", fmt("id=%s", sha1_to_hex(sha1)))); 36 html_attr(cgit_pageurl(cgit_query_repo, "blob", fmt("id=%s", sha1_to_hex(sha1))));
37 htmlf("'>%s</a>",sha1_to_hex(sha1)); 37 htmlf("'>%s</a>",sha1_to_hex(sha1));
38 38
39 html("<table class='blob'>\n"); 39 html("<table class='blob'>\n");
40 idx = 0; 40 idx = 0;
41 start = 0; 41 start = 0;
42 lineno = 0; 42 lineno = 0;
43 while(idx < size) { 43 while(idx < size) {
44 if (buf[idx] == '\n') { 44 if (buf[idx] == '\n') {
45 buf[idx] = '\0'; 45 buf[idx] = '\0';
46 htmlf("<tr><td class='no'>%d</td><td class='txt'>", 46 htmlf("<tr><td class='no'><a name='%d'>%1$d</a></td><td class='txt'>",
47 ++lineno); 47 ++lineno);
48 html_txt(buf + start); 48 html_txt(buf + start);
49 html("</td></tr>\n"); 49 html("</td></tr>\n");
50 start = idx + 1; 50 start = idx + 1;
51 } 51 }
52 idx++; 52 idx++;
53 } 53 }
54 html("</table>\n"); 54 html("</table>\n");
55} 55}
56 56
57 57
58static int ls_item(const unsigned char *sha1, const char *base, int baselen, 58static int ls_item(const unsigned char *sha1, const char *base, int baselen,
59 const char *pathname, unsigned int mode, int stage) 59 const char *pathname, unsigned int mode, int stage)
60{ 60{
61 char *name; 61 char *name;
62 char *fullpath; 62 char *fullpath;
63 enum object_type type; 63 enum object_type type;
64 unsigned long size = 0; 64 unsigned long size = 0;
65 65
66 name = xstrdup(pathname); 66 name = xstrdup(pathname);
67 fullpath = fmt("%s%s%s", cgit_query_path ? cgit_query_path : "", 67 fullpath = fmt("%s%s%s", cgit_query_path ? cgit_query_path : "",
68 cgit_query_path ? "/" : "", name); 68 cgit_query_path ? "/" : "", name);
69 69
70 type = sha1_object_info(sha1, &size); 70 type = sha1_object_info(sha1, &size);
71 if (type == OBJ_BAD && !S_ISDIRLNK(mode)) { 71 if (type == OBJ_BAD && !S_ISDIRLNK(mode)) {
72 htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>", 72 htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>",
73 name, 73 name,
74 sha1_to_hex(sha1)); 74 sha1_to_hex(sha1));
75 return 0; 75 return 0;
76 } 76 }
77 77
78 html("<tr><td class='ls-mode'>"); 78 html("<tr><td class='ls-mode'>");
79 html_filemode(mode); 79 html_filemode(mode);
80 html("</td><td>"); 80 html("</td><td>");
81 if (S_ISDIRLNK(mode)) { 81 if (S_ISDIRLNK(mode)) {
82 htmlf("<a class='ls-mod' href='"); 82 htmlf("<a class='ls-mod' href='");
83 html_attr(fmt(cgit_repo->module_link, 83 html_attr(fmt(cgit_repo->module_link,
84 name, 84 name,
85 sha1_to_hex(sha1))); 85 sha1_to_hex(sha1)));
86 html("'>"); 86 html("'>");
87 html_txt(name); 87 html_txt(name);
88 html("</a>"); 88 html("</a>");
89 } else if (S_ISDIR(mode)) { 89 } else if (S_ISDIR(mode)) {
90 cgit_tree_link(name, NULL, "ls-dir", cgit_query_head, 90 cgit_tree_link(name, NULL, "ls-dir", cgit_query_head,
91 curr_rev, fullpath); 91 curr_rev, fullpath);
92 } else { 92 } else {
93 cgit_tree_link(name, NULL, "ls-blob", cgit_query_head, 93 cgit_tree_link(name, NULL, "ls-blob", cgit_query_head,
94 curr_rev, fullpath); 94 curr_rev, fullpath);
95 } 95 }
96 htmlf("</td><td class='ls-size'>%li</td>", size); 96 htmlf("</td><td class='ls-size'>%li</td>", size);
97 97
98 html("<td>"); 98 html("<td>");
99 cgit_log_link("log", NULL, "button", cgit_query_head, curr_rev, 99 cgit_log_link("log", NULL, "button", cgit_query_head, curr_rev,
100 fullpath, 0); 100 fullpath, 0);
101 html("</td></tr>\n"); 101 html("</td></tr>\n");
102 free(name); 102 free(name);
103 return 0; 103 return 0;
104} 104}
105 105
106static void ls_head() 106static void ls_head()
107{ 107{
108 html("<table class='list'>\n"); 108 html("<table class='list'>\n");
109 html("<tr class='nohover'>"); 109 html("<tr class='nohover'>");
110 html("<th class='left'>Mode</th>"); 110 html("<th class='left'>Mode</th>");
111 html("<th class='left'>Name</th>"); 111 html("<th class='left'>Name</th>");
112 html("<th class='right'>Size</th>"); 112 html("<th class='right'>Size</th>");
113 html("<th/>"); 113 html("<th/>");
114 html("</tr>\n"); 114 html("</tr>\n");
115 header = 1; 115 header = 1;
116} 116}
117 117
118static void ls_tail() 118static void ls_tail()
119{ 119{
120 if (!header) 120 if (!header)
121 return; 121 return;
122 html("</table>\n"); 122 html("</table>\n");
123 header = 0; 123 header = 0;
124} 124}
125 125
126static void ls_tree(const unsigned char *sha1, char *path) 126static void ls_tree(const unsigned char *sha1, char *path)
127{ 127{
128 struct tree *tree; 128 struct tree *tree;
129 129
130 tree = parse_tree_indirect(sha1); 130 tree = parse_tree_indirect(sha1);
131 if (!tree) { 131 if (!tree) {
132 cgit_print_error(fmt("Not a tree object: %s", 132 cgit_print_error(fmt("Not a tree object: %s",
133 sha1_to_hex(sha1))); 133 sha1_to_hex(sha1)));
134 return; 134 return;
135 } 135 }
136 136
137 ls_head(); 137 ls_head();
138 read_tree_recursive(tree, "", 0, 1, NULL, ls_item); 138 read_tree_recursive(tree, "", 0, 1, NULL, ls_item);
139 ls_tail(); 139 ls_tail();
140} 140}
141 141
142 142
143static int walk_tree(const unsigned char *sha1, const char *base, int baselen, 143static int walk_tree(const unsigned char *sha1, const char *base, int baselen,
144 const char *pathname, unsigned mode, int stage) 144 const char *pathname, unsigned mode, int stage)
145{ 145{
146 static int state; 146 static int state;
147 static char buffer[PATH_MAX]; 147 static char buffer[PATH_MAX];
148 char *url; 148 char *url;
149 149
150 if (state == 0) { 150 if (state == 0) {
151 memcpy(buffer, base, baselen); 151 memcpy(buffer, base, baselen);
152 strcpy(buffer+baselen, pathname); 152 strcpy(buffer+baselen, pathname);
153 url = cgit_pageurl(cgit_query_repo, "tree", 153 url = cgit_pageurl(cgit_query_repo, "tree",
154 fmt("h=%s&amp;path=%s", curr_rev, buffer)); 154 fmt("h=%s&amp;path=%s", curr_rev, buffer));
155 html("/"); 155 html("/");
156 cgit_tree_link(xstrdup(pathname), NULL, NULL, cgit_query_head, 156 cgit_tree_link(xstrdup(pathname), NULL, NULL, cgit_query_head,
157 curr_rev, buffer); 157 curr_rev, buffer);
158 158
159 if (strcmp(match_path, buffer)) 159 if (strcmp(match_path, buffer))
160 return READ_TREE_RECURSIVE; 160 return READ_TREE_RECURSIVE;
161 161
162 if (S_ISDIR(mode)) { 162 if (S_ISDIR(mode)) {
163 state = 1; 163 state = 1;
164 ls_head(); 164 ls_head();
165 return READ_TREE_RECURSIVE; 165 return READ_TREE_RECURSIVE;
166 } else { 166 } else {
167 print_object(sha1, buffer); 167 print_object(sha1, buffer);
168 return 0; 168 return 0;
169 } 169 }
170 } 170 }
171 ls_item(sha1, base, baselen, pathname, mode, stage); 171 ls_item(sha1, base, baselen, pathname, mode, stage);
172 return 0; 172 return 0;
173} 173}
174 174
175 175
176/* 176/*
177 * Show a tree or a blob 177 * Show a tree or a blob
178 * rev: the commit pointing at the root tree object 178 * rev: the commit pointing at the root tree object
179 * path: path to tree or blob 179 * path: path to tree or blob
180 */ 180 */
181void cgit_print_tree(const char *rev, char *path) 181void cgit_print_tree(const char *rev, char *path)
182{ 182{
183 unsigned char sha1[20]; 183 unsigned char sha1[20];
184 struct commit *commit; 184 struct commit *commit;
185 const char *paths[] = {path, NULL}; 185 const char *paths[] = {path, NULL};
186 186
187 if (!rev) 187 if (!rev)
188 rev = cgit_query_head; 188 rev = cgit_query_head;
189 189
190 curr_rev = xstrdup(rev); 190 curr_rev = xstrdup(rev);
191 if (get_sha1(rev, sha1)) { 191 if (get_sha1(rev, sha1)) {
192 cgit_print_error(fmt("Invalid revision name: %s", rev)); 192 cgit_print_error(fmt("Invalid revision name: %s", rev));
193 return; 193 return;
194 } 194 }
195 commit = lookup_commit_reference(sha1); 195 commit = lookup_commit_reference(sha1);
196 if (!commit || parse_commit(commit)) { 196 if (!commit || parse_commit(commit)) {
197 cgit_print_error(fmt("Invalid commit reference: %s", rev)); 197 cgit_print_error(fmt("Invalid commit reference: %s", rev));
198 return; 198 return;
199 } 199 }
200 200
201 html("path: <a href='"); 201 html("path: <a href='");
202 html_attr(cgit_pageurl(cgit_query_repo, "tree", fmt("h=%s", rev))); 202 html_attr(cgit_pageurl(cgit_query_repo, "tree", fmt("h=%s", rev)));
203 html("'>root</a>"); 203 html("'>root</a>");
204 204
205 if (path == NULL) { 205 if (path == NULL) {
206 ls_tree(commit->tree->object.sha1, NULL); 206 ls_tree(commit->tree->object.sha1, NULL);
207 return; 207 return;
208 } 208 }
209 209
210 match_path = path; 210 match_path = path;
211 read_tree_recursive(commit->tree, NULL, 0, 0, paths, walk_tree); 211 read_tree_recursive(commit->tree, NULL, 0, 0, paths, walk_tree);
212 ls_tail(); 212 ls_tail();
213} 213}