-rw-r--r-- | cgit.css | 147 | ||||
-rw-r--r-- | cgit.png | bin | 5406 -> 1840 bytes | |||
-rw-r--r-- | ui-shared.c | 125 |
3 files changed, 97 insertions, 175 deletions
@@ -1,447 +1,406 @@ | |||
1 | body, table { | 1 | body, table { |
2 | padding: 0em; | 2 | padding: 0em; |
3 | margin: 0em; | 3 | margin: 0em; |
4 | } | 4 | } |
5 | 5 | ||
6 | body { | 6 | body { |
7 | font-family: sans; | 7 | font-family: sans; |
8 | font-size: 10pt; | 8 | font-size: 10pt; |
9 | color: #333; | 9 | color: #333; |
10 | background: white; | 10 | background: white; |
11 | padding: 4px; | 11 | padding: 4px; |
12 | } | 12 | } |
13 | 13 | ||
14 | a { | ||
15 | color: blue; | ||
16 | text-decoration: none; | ||
17 | } | ||
18 | |||
19 | a:hover { | ||
20 | text-decoration: underline; | ||
21 | } | ||
22 | |||
14 | table { | 23 | table { |
15 | border-collapse: collapse; | 24 | border-collapse: collapse; |
16 | } | 25 | } |
17 | 26 | ||
18 | h2 { | 27 | table#header { |
19 | font-size: 120%; | 28 | width: 100%; |
20 | font-weight: bold; | 29 | margin-bottom: 1em; |
21 | margin-top: 0em; | ||
22 | margin-bottom: 0.25em; | ||
23 | } | 30 | } |
24 | 31 | ||
25 | h3 { | 32 | table#header td.logo { |
26 | margin-top: 0em; | 33 | width: 96px; |
27 | font-size: 100%; | ||
28 | font-weight: normal; | ||
29 | } | 34 | } |
30 | 35 | ||
31 | h4 { | 36 | table#header td.main { |
32 | margin-top: 1.5em; | 37 | font-size: 200%; |
33 | margin-bottom: 0.1em; | ||
34 | font-size: 100%; | ||
35 | font-weight: bold; | ||
36 | } | 38 | } |
37 | 39 | ||
38 | a { | 40 | table#header td.sub { |
39 | color: #600; | 41 | color: #777; |
40 | text-decoration: none; | 42 | border-top: solid 1px #ccc; |
41 | } | 43 | } |
42 | 44 | ||
43 | a:hover { | 45 | table.tabs { |
44 | background-color: #ddd; | 46 | border-bottom: solid 2px #ccc; |
45 | text-decoration: none; | 47 | border-collapse: collapse; |
48 | margin-top: 2em; | ||
49 | margin-bottom: 1em; | ||
50 | width: 100%; | ||
51 | } | ||
52 | |||
53 | table.tabs td { | ||
54 | padding: 0px 0.5em; | ||
55 | } | ||
56 | |||
57 | table.tabs td a { | ||
58 | padding: 2px 1em; | ||
59 | color: #007; | ||
60 | } | ||
61 | |||
62 | table.tabs td a.active { | ||
63 | color: #000; | ||
64 | background-color: #ccc; | ||
46 | } | 65 | } |
47 | 66 | ||
67 | div.content { | ||
68 | margin: 0px; | ||
69 | padding: 1em; | ||
70 | } | ||
71 | |||
72 | |||
48 | table.list { | 73 | table.list { |
74 | width: 100%; | ||
49 | border: none; | 75 | border: none; |
50 | border-collapse: collapse; | 76 | border-collapse: collapse; |
51 | } | 77 | } |
52 | 78 | ||
53 | table.list tr { | 79 | table.list tr { |
54 | background: white; | 80 | background: white; |
55 | } | 81 | } |
56 | 82 | ||
57 | table.list tr:hover { | 83 | table.list tr:hover { |
58 | background: #f8f8f8; | 84 | background: #eee; |
59 | } | 85 | } |
60 | 86 | ||
61 | table.list tr.nohover:hover { | 87 | table.list tr.nohover:hover { |
62 | background: white; | 88 | background: white; |
63 | } | 89 | } |
64 | 90 | ||
65 | table.list th { | 91 | table.list th { |
66 | font-weight: bold; | 92 | font-weight: normal; |
67 | border-bottom: solid 1px #777; | 93 | border-bottom: solid 1px #ccc; |
68 | padding: 0.1em 0.5em 0.1em 0.5em; | 94 | padding: 0.1em 0.5em 0.1em 0.5em; |
69 | vertical-align: baseline; | 95 | vertical-align: baseline; |
70 | } | 96 | } |
71 | 97 | ||
72 | table.list td { | 98 | table.list td { |
73 | border: none; | 99 | border: none; |
74 | padding: 0.1em 0.5em 0.1em 0.5em; | 100 | padding: 0.1em 0.5em 0.1em 0.5em; |
75 | } | 101 | } |
76 | 102 | ||
77 | img { | 103 | table.list td a { |
78 | border: none; | 104 | color: black; |
79 | } | 105 | } |
80 | 106 | ||
81 | table#layout { | 107 | img { |
82 | border-collapse: collapse; | ||
83 | border: none; | 108 | border: none; |
84 | margin: 0px; | ||
85 | } | ||
86 | |||
87 | td#sidebar { | ||
88 | vertical-align: top; | ||
89 | width: 162px; | ||
90 | padding: 0px 0px 0px 0px; | ||
91 | margin: 0px; | ||
92 | } | ||
93 | |||
94 | td#sidebar table { | ||
95 | border-collapse: separate; | ||
96 | border-spacing: 0px; | ||
97 | margin: 0px; | ||
98 | padding: 0px; | ||
99 | background-color: #ccc; | ||
100 | } | ||
101 | |||
102 | td#sidebar table.sidebar td.sidebar { | ||
103 | padding: 4px; | ||
104 | border-top: solid 1px #eee; | ||
105 | border-left: solid 1px #eee; | ||
106 | border-right: solid 1px #aaa; | ||
107 | border-bottom: solid 1px #aaa; | ||
108 | } | ||
109 | |||
110 | div#logo { | ||
111 | margin: 0px; | ||
112 | padding: 4px 0px 4px 0px; | ||
113 | text-align: center; | ||
114 | background-color: #ccc; | ||
115 | border-top: solid 1px #eee; | ||
116 | border-left: solid 1px #eee; | ||
117 | border-right: solid 1px #aaa; | ||
118 | border-bottom: solid 1px #aaa; | ||
119 | } | ||
120 | |||
121 | td#sidebar h1 { | ||
122 | font-size: 10pt; | ||
123 | font-weight: bold; | ||
124 | margin: 8px 0px 0px 0px; | ||
125 | } | ||
126 | |||
127 | td#sidebar h1.first { | ||
128 | margin-top: 0px; | ||
129 | } | ||
130 | |||
131 | td#sidebar a.menu { | ||
132 | display: block; | ||
133 | background-color: #ccc; | ||
134 | padding: 0.1em 0.5em; | ||
135 | text-decoration: none; | ||
136 | } | ||
137 | |||
138 | td#sidebar a.menu:hover { | ||
139 | background-color: #bbb; | ||
140 | text-decoration: none; | ||
141 | } | ||
142 | |||
143 | td#sidebar select { | ||
144 | width: 100%; | ||
145 | margin: 2px 0px 0px 0px; | ||
146 | } | ||
147 | |||
148 | td#sidebar form { | ||
149 | text-align: right; | ||
150 | } | 109 | } |
151 | 110 | ||
152 | input#switch-btn { | 111 | input#switch-btn { |
153 | margin: 2px 0px 0px 0px; | 112 | margin: 2px 0px 0px 0px; |
154 | } | 113 | } |
155 | 114 | ||
156 | td#sidebar input.txt { | 115 | td#sidebar input.txt { |
157 | width: 100%; | 116 | width: 100%; |
158 | margin: 2px 0px 0px 0px; | 117 | margin: 2px 0px 0px 0px; |
159 | } | 118 | } |
160 | 119 | ||
161 | table#grid { | 120 | table#grid { |
162 | margin: 0px; | 121 | margin: 0px; |
163 | } | 122 | } |
164 | 123 | ||
165 | td#content { | 124 | td#content { |
166 | vertical-align: top; | 125 | vertical-align: top; |
167 | padding: 1em 2em 1em 1em; | 126 | padding: 1em 2em 1em 1em; |
168 | border: none; | 127 | border: none; |
169 | } | 128 | } |
170 | 129 | ||
171 | div#summary { | 130 | div#summary { |
172 | vertical-align: top; | 131 | vertical-align: top; |
173 | margin-bottom: 1em; | 132 | margin-bottom: 1em; |
174 | } | 133 | } |
175 | 134 | ||
176 | table#downloads { | 135 | table#downloads { |
177 | float: right; | 136 | float: right; |
178 | border-collapse: collapse; | 137 | border-collapse: collapse; |
179 | border: solid 1px #777; | 138 | border: solid 1px #777; |
180 | margin-left: 0.5em; | 139 | margin-left: 0.5em; |
181 | margin-bottom: 0.5em; | 140 | margin-bottom: 0.5em; |
182 | } | 141 | } |
183 | 142 | ||
184 | table#downloads th { | 143 | table#downloads th { |
185 | background-color: #ccc; | 144 | background-color: #ccc; |
186 | } | 145 | } |
187 | 146 | ||
188 | div#blob { | 147 | div#blob { |
189 | border: solid 1px black; | 148 | border: solid 1px black; |
190 | } | 149 | } |
191 | 150 | ||
192 | div.error { | 151 | div.error { |
193 | color: red; | 152 | color: red; |
194 | font-weight: bold; | 153 | font-weight: bold; |
195 | margin: 1em 2em; | 154 | margin: 1em 2em; |
196 | } | 155 | } |
197 | 156 | ||
198 | a.ls-blob, a.ls-dir, a.ls-mod { | 157 | a.ls-blob, a.ls-dir, a.ls-mod { |
199 | font-family: monospace; | 158 | font-family: monospace; |
200 | } | 159 | } |
201 | 160 | ||
202 | td.ls-size { | 161 | td.ls-size { |
203 | text-align: right; | 162 | text-align: right; |
204 | } | 163 | } |
205 | 164 | ||
206 | td.ls-size { | 165 | td.ls-size { |
207 | font-family: monospace; | 166 | font-family: monospace; |
208 | } | 167 | } |
209 | 168 | ||
210 | td.ls-mode { | 169 | td.ls-mode { |
211 | font-family: monospace; | 170 | font-family: monospace; |
212 | } | 171 | } |
213 | 172 | ||
214 | table.blob { | 173 | table.blob { |
215 | margin-top: 0.5em; | 174 | margin-top: 0.5em; |
216 | border-top: solid 1px black; | 175 | border-top: solid 1px black; |
217 | } | 176 | } |
218 | 177 | ||
219 | table.blob td.no { | 178 | table.blob td.no { |
220 | border-right: solid 1px black; | 179 | border-right: solid 1px black; |
221 | color: black; | 180 | color: black; |
222 | background-color: #eee; | 181 | background-color: #eee; |
223 | text-align: right; | 182 | text-align: right; |
224 | } | 183 | } |
225 | 184 | ||
226 | table.blob td.no a { | 185 | table.blob td.no a { |
227 | color: black; | 186 | color: black; |
228 | } | 187 | } |
229 | 188 | ||
230 | table.blob td.no a:hover { | 189 | table.blob td.no a:hover { |
231 | color: black; | 190 | color: black; |
232 | text-decoration: none; | 191 | text-decoration: none; |
233 | } | 192 | } |
234 | 193 | ||
235 | table.blob td.txt { | 194 | table.blob td.txt { |
236 | white-space: pre; | 195 | white-space: pre; |
237 | font-family: monospace; | 196 | font-family: monospace; |
238 | padding-left: 0.5em; | 197 | padding-left: 0.5em; |
239 | } | 198 | } |
240 | 199 | ||
241 | table.nowrap td { | 200 | table.nowrap td { |
242 | white-space: nowrap; | 201 | white-space: nowrap; |
243 | } | 202 | } |
244 | 203 | ||
245 | table.commit-info { | 204 | table.commit-info { |
246 | border-collapse: collapse; | 205 | border-collapse: collapse; |
247 | margin-top: 1.5em; | 206 | margin-top: 1.5em; |
248 | } | 207 | } |
249 | 208 | ||
250 | table.commit-info th { | 209 | table.commit-info th { |
251 | text-align: left; | 210 | text-align: left; |
252 | font-weight: normal; | 211 | font-weight: normal; |
253 | padding: 0.1em 1em 0.1em 0.1em; | 212 | padding: 0.1em 1em 0.1em 0.1em; |
254 | vertical-align: top; | 213 | vertical-align: top; |
255 | } | 214 | } |
256 | 215 | ||
257 | table.commit-info td { | 216 | table.commit-info td { |
258 | font-weight: normal; | 217 | font-weight: normal; |
259 | padding: 0.1em 1em 0.1em 0.1em; | 218 | padding: 0.1em 1em 0.1em 0.1em; |
260 | } | 219 | } |
261 | 220 | ||
262 | div.commit-subject { | 221 | div.commit-subject { |
263 | font-weight: bold; | 222 | font-weight: bold; |
264 | font-size: 125%; | 223 | font-size: 125%; |
265 | margin: 1.5em 0em 0.5em 0em; | 224 | margin: 1.5em 0em 0.5em 0em; |
266 | padding: 0em; | 225 | padding: 0em; |
267 | } | 226 | } |
268 | 227 | ||
269 | div.commit-msg { | 228 | div.commit-msg { |
270 | white-space: pre; | 229 | white-space: pre; |
271 | font-family: monospace; | 230 | font-family: monospace; |
272 | } | 231 | } |
273 | 232 | ||
274 | div.diffstat-header { | 233 | div.diffstat-header { |
275 | font-weight: bold; | 234 | font-weight: bold; |
276 | padding-top: 1.5em; | 235 | padding-top: 1.5em; |
277 | } | 236 | } |
278 | 237 | ||
279 | table.diffstat { | 238 | table.diffstat { |
280 | border-collapse: collapse; | 239 | border-collapse: collapse; |
281 | border: solid 1px #aaa; | 240 | border: solid 1px #aaa; |
282 | background-color: #eee; | 241 | background-color: #eee; |
283 | } | 242 | } |
284 | 243 | ||
285 | table.diffstat th { | 244 | table.diffstat th { |
286 | font-weight: normal; | 245 | font-weight: normal; |
287 | text-align: left; | 246 | text-align: left; |
288 | text-decoration: underline; | 247 | text-decoration: underline; |
289 | padding: 0.1em 1em 0.1em 0.1em; | 248 | padding: 0.1em 1em 0.1em 0.1em; |
290 | font-size: 100%; | 249 | font-size: 100%; |
291 | } | 250 | } |
292 | 251 | ||
293 | table.diffstat td { | 252 | table.diffstat td { |
294 | padding: 0.2em 0.2em 0.1em 0.1em; | 253 | padding: 0.2em 0.2em 0.1em 0.1em; |
295 | font-size: 100%; | 254 | font-size: 100%; |
296 | border: none; | 255 | border: none; |
297 | } | 256 | } |
298 | 257 | ||
299 | table.diffstat td.mode { | 258 | table.diffstat td.mode { |
300 | white-space: nowrap; | 259 | white-space: nowrap; |
301 | } | 260 | } |
302 | 261 | ||
303 | table.diffstat td span.modechange { | 262 | table.diffstat td span.modechange { |
304 | padding-left: 1em; | 263 | padding-left: 1em; |
305 | color: red; | 264 | color: red; |
306 | } | 265 | } |
307 | 266 | ||
308 | table.diffstat td.add a { | 267 | table.diffstat td.add a { |
309 | color: green; | 268 | color: green; |
310 | } | 269 | } |
311 | 270 | ||
312 | table.diffstat td.del a { | 271 | table.diffstat td.del a { |
313 | color: red; | 272 | color: red; |
314 | } | 273 | } |
315 | 274 | ||
316 | table.diffstat td.upd a { | 275 | table.diffstat td.upd a { |
317 | color: blue; | 276 | color: blue; |
318 | } | 277 | } |
319 | 278 | ||
320 | table.diffstat td.graph { | 279 | table.diffstat td.graph { |
321 | width: 500px; | 280 | width: 500px; |
322 | vertical-align: middle; | 281 | vertical-align: middle; |
323 | } | 282 | } |
324 | 283 | ||
325 | table.diffstat td.graph table { | 284 | table.diffstat td.graph table { |
326 | border: none; | 285 | border: none; |
327 | } | 286 | } |
328 | 287 | ||
329 | table.diffstat td.graph td { | 288 | table.diffstat td.graph td { |
330 | padding: 0px; | 289 | padding: 0px; |
331 | border: 0px; | 290 | border: 0px; |
332 | height: 7pt; | 291 | height: 7pt; |
333 | } | 292 | } |
334 | 293 | ||
335 | table.diffstat td.graph td.add { | 294 | table.diffstat td.graph td.add { |
336 | background-color: #5c5; | 295 | background-color: #5c5; |
337 | } | 296 | } |
338 | 297 | ||
339 | table.diffstat td.graph td.rem { | 298 | table.diffstat td.graph td.rem { |
340 | background-color: #c55; | 299 | background-color: #c55; |
341 | } | 300 | } |
342 | 301 | ||
343 | div.diffstat-summary { | 302 | div.diffstat-summary { |
344 | color: #888; | 303 | color: #888; |
345 | padding-top: 0.5em; | 304 | padding-top: 0.5em; |
346 | } | 305 | } |
347 | 306 | ||
348 | table.diff { | 307 | table.diff { |
349 | width: 100%; | 308 | width: 100%; |
350 | } | 309 | } |
351 | 310 | ||
352 | table.diff td { | 311 | table.diff td { |
353 | font-family: monospace; | 312 | font-family: monospace; |
354 | white-space: pre; | 313 | white-space: pre; |
355 | } | 314 | } |
356 | 315 | ||
357 | table.diff td div.head { | 316 | table.diff td div.head { |
358 | font-weight: bold; | 317 | font-weight: bold; |
359 | margin-top: 1em; | 318 | margin-top: 1em; |
360 | background-color: #eee; | 319 | color: black; |
361 | } | 320 | } |
362 | 321 | ||
363 | table.diff td div.hunk { | 322 | table.diff td div.hunk { |
364 | color: #009; | 323 | color: #009; |
365 | } | 324 | } |
366 | 325 | ||
367 | table.diff td div.add { | 326 | table.diff td div.add { |
368 | color: green; | 327 | color: green; |
369 | } | 328 | } |
370 | 329 | ||
371 | table.diff td div.del { | 330 | table.diff td div.del { |
372 | color: red; | 331 | color: red; |
373 | } | 332 | } |
374 | 333 | ||
375 | .sha1 { | 334 | .sha1 { |
376 | font-family: monospace; | 335 | font-family: monospace; |
377 | font-size: 90%; | 336 | font-size: 90%; |
378 | } | 337 | } |
379 | 338 | ||
380 | .left { | 339 | .left { |
381 | text-align: left; | 340 | text-align: left; |
382 | } | 341 | } |
383 | 342 | ||
384 | .right { | 343 | .right { |
385 | text-align: right; | 344 | text-align: right; |
386 | } | 345 | } |
387 | 346 | ||
388 | table.list td.repogroup { | 347 | table.list td.repogroup { |
389 | font-style: italic; | 348 | font-style: italic; |
390 | color: #888; | 349 | color: #888; |
391 | } | 350 | } |
392 | 351 | ||
393 | a.button { | 352 | a.button { |
394 | font-size: 80%; | 353 | font-size: 80%; |
395 | color: #aaa; | 354 | color: #aaa; |
396 | background-color: #eee; | 355 | background-color: #eee; |
397 | border: solid 1px #aaa; | 356 | border: solid 1px #aaa; |
398 | padding: 0em 0.5em; | 357 | padding: 0em 0.5em; |
399 | margin: 0.1em 0.25em; | 358 | margin: 0.1em 0.25em; |
400 | } | 359 | } |
401 | 360 | ||
402 | a.button:hover { | 361 | a.button:hover { |
403 | text-decoration: none; | 362 | text-decoration: none; |
404 | color: #333; | 363 | color: #333; |
405 | background-color: #ccc; | 364 | background-color: #ccc; |
406 | } | 365 | } |
407 | 366 | ||
408 | a.primary { | 367 | a.primary { |
409 | font-size: 100%; | 368 | font-size: 100%; |
410 | } | 369 | } |
411 | 370 | ||
412 | a.secondary { | 371 | a.secondary { |
413 | font-size: 90%; | 372 | font-size: 90%; |
414 | } | 373 | } |
415 | 374 | ||
416 | td.toplevel-repo { | 375 | td.toplevel-repo { |
417 | 376 | ||
418 | } | 377 | } |
419 | 378 | ||
420 | table.list td.sublevel-repo { | 379 | table.list td.sublevel-repo { |
421 | padding-left: 1.5em; | 380 | padding-left: 1.5em; |
422 | } | 381 | } |
423 | 382 | ||
424 | span.age-mins { | 383 | span.age-mins { |
425 | font-weight: bold; | 384 | font-weight: bold; |
426 | color: #080; | 385 | color: #080; |
427 | } | 386 | } |
428 | 387 | ||
429 | span.age-hours { | 388 | span.age-hours { |
430 | color: #080; | 389 | color: #080; |
431 | } | 390 | } |
432 | 391 | ||
433 | span.age-days { | 392 | span.age-days { |
434 | color: #040; | 393 | color: #040; |
435 | } | 394 | } |
436 | 395 | ||
437 | span.age-weeks { | 396 | span.age-weeks { |
438 | color: #444; | 397 | color: #444; |
439 | } | 398 | } |
440 | 399 | ||
441 | span.age-months { | 400 | span.age-months { |
442 | color: #888; | 401 | color: #888; |
443 | } | 402 | } |
444 | 403 | ||
445 | span.age-years { | 404 | span.age-years { |
446 | color: #bbb; | 405 | color: #bbb; |
447 | } | 406 | } |
Binary files differ | |||
diff --git a/ui-shared.c b/ui-shared.c index aa65988..7287956 100644 --- a/ui-shared.c +++ b/ui-shared.c | |||
@@ -1,201 +1,202 @@ | |||
1 | /* ui-shared.c: common web output functions | 1 | /* ui-shared.c: common web output functions |
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 | #include "cmd.h" | ||
10 | #include "html.h" | 11 | #include "html.h" |
11 | 12 | ||
12 | const char cgit_doctype[] = | 13 | const char cgit_doctype[] = |
13 | "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n" | 14 | "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n" |
14 | " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"; | 15 | " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"; |
15 | 16 | ||
16 | static char *http_date(time_t t) | 17 | static char *http_date(time_t t) |
17 | { | 18 | { |
18 | static char day[][4] = | 19 | static char day[][4] = |
19 | {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; | 20 | {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; |
20 | static char month[][4] = | 21 | static char month[][4] = |
21 | {"Jan", "Feb", "Mar", "Apr", "May", "Jun", | 22 | {"Jan", "Feb", "Mar", "Apr", "May", "Jun", |
22 | "Jul", "Aug", "Sep", "Oct", "Now", "Dec"}; | 23 | "Jul", "Aug", "Sep", "Oct", "Now", "Dec"}; |
23 | struct tm *tm = gmtime(&t); | 24 | struct tm *tm = gmtime(&t); |
24 | return fmt("%s, %02d %s %04d %02d:%02d:%02d GMT", day[tm->tm_wday], | 25 | return fmt("%s, %02d %s %04d %02d:%02d:%02d GMT", day[tm->tm_wday], |
25 | tm->tm_mday, month[tm->tm_mon], 1900+tm->tm_year, | 26 | tm->tm_mday, month[tm->tm_mon], 1900+tm->tm_year, |
26 | tm->tm_hour, tm->tm_min, tm->tm_sec); | 27 | tm->tm_hour, tm->tm_min, tm->tm_sec); |
27 | } | 28 | } |
28 | 29 | ||
29 | void cgit_print_error(char *msg) | 30 | void cgit_print_error(char *msg) |
30 | { | 31 | { |
31 | html("<div class='error'>"); | 32 | html("<div class='error'>"); |
32 | html_txt(msg); | 33 | html_txt(msg); |
33 | html("</div>\n"); | 34 | html("</div>\n"); |
34 | } | 35 | } |
35 | 36 | ||
36 | char *cgit_rooturl() | 37 | char *cgit_rooturl() |
37 | { | 38 | { |
38 | if (ctx.cfg.virtual_root) | 39 | if (ctx.cfg.virtual_root) |
39 | return fmt("%s/", ctx.cfg.virtual_root); | 40 | return fmt("%s/", ctx.cfg.virtual_root); |
40 | else | 41 | else |
41 | return ctx.cfg.script_name; | 42 | return ctx.cfg.script_name; |
42 | } | 43 | } |
43 | 44 | ||
44 | char *cgit_repourl(const char *reponame) | 45 | char *cgit_repourl(const char *reponame) |
45 | { | 46 | { |
46 | if (ctx.cfg.virtual_root) { | 47 | if (ctx.cfg.virtual_root) { |
47 | return fmt("%s/%s/", ctx.cfg.virtual_root, reponame); | 48 | return fmt("%s/%s/", ctx.cfg.virtual_root, reponame); |
48 | } else { | 49 | } else { |
49 | return fmt("?r=%s", reponame); | 50 | return fmt("?r=%s", reponame); |
50 | } | 51 | } |
51 | } | 52 | } |
52 | 53 | ||
53 | char *cgit_fileurl(const char *reponame, const char *pagename, | 54 | char *cgit_fileurl(const char *reponame, const char *pagename, |
54 | const char *filename, const char *query) | 55 | const char *filename, const char *query) |
55 | { | 56 | { |
56 | char *tmp; | 57 | char *tmp; |
57 | char *delim; | 58 | char *delim; |
58 | 59 | ||
59 | if (ctx.cfg.virtual_root) { | 60 | if (ctx.cfg.virtual_root) { |
60 | tmp = fmt("%s/%s/%s/%s", ctx.cfg.virtual_root, reponame, | 61 | tmp = fmt("%s/%s/%s/%s", ctx.cfg.virtual_root, reponame, |
61 | pagename, (filename ? filename:"")); | 62 | pagename, (filename ? filename:"")); |
62 | delim = "?"; | 63 | delim = "?"; |
63 | } else { | 64 | } else { |
64 | tmp = fmt("?url=%s/%s/%s", reponame, pagename, | 65 | tmp = fmt("?url=%s/%s/%s", reponame, pagename, |
65 | (filename ? filename : "")); | 66 | (filename ? filename : "")); |
66 | delim = "&"; | 67 | delim = "&"; |
67 | } | 68 | } |
68 | if (query) | 69 | if (query) |
69 | tmp = fmt("%s%s%s", tmp, delim, query); | 70 | tmp = fmt("%s%s%s", tmp, delim, query); |
70 | return tmp; | 71 | return tmp; |
71 | } | 72 | } |
72 | 73 | ||
73 | char *cgit_pageurl(const char *reponame, const char *pagename, | 74 | char *cgit_pageurl(const char *reponame, const char *pagename, |
74 | const char *query) | 75 | const char *query) |
75 | { | 76 | { |
76 | return cgit_fileurl(reponame,pagename,0,query); | 77 | return cgit_fileurl(reponame,pagename,0,query); |
77 | } | 78 | } |
78 | 79 | ||
79 | const char *cgit_repobasename(const char *reponame) | 80 | const char *cgit_repobasename(const char *reponame) |
80 | { | 81 | { |
81 | /* I assume we don't need to store more than one repo basename */ | 82 | /* I assume we don't need to store more than one repo basename */ |
82 | static char rvbuf[1024]; | 83 | static char rvbuf[1024]; |
83 | int p; | 84 | int p; |
84 | const char *rv; | 85 | const char *rv; |
85 | strncpy(rvbuf,reponame,sizeof(rvbuf)); | 86 | strncpy(rvbuf,reponame,sizeof(rvbuf)); |
86 | if(rvbuf[sizeof(rvbuf)-1]) | 87 | if(rvbuf[sizeof(rvbuf)-1]) |
87 | die("cgit_repobasename: truncated repository name '%s'", reponame); | 88 | die("cgit_repobasename: truncated repository name '%s'", reponame); |
88 | p = strlen(rvbuf)-1; | 89 | p = strlen(rvbuf)-1; |
89 | /* strip trailing slashes */ | 90 | /* strip trailing slashes */ |
90 | while(p && rvbuf[p]=='/') rvbuf[p--]=0; | 91 | while(p && rvbuf[p]=='/') rvbuf[p--]=0; |
91 | /* strip trailing .git */ | 92 | /* strip trailing .git */ |
92 | if(p>=3 && !strncmp(&rvbuf[p-3],".git",4)) { | 93 | if(p>=3 && !strncmp(&rvbuf[p-3],".git",4)) { |
93 | p -= 3; rvbuf[p--] = 0; | 94 | p -= 3; rvbuf[p--] = 0; |
94 | } | 95 | } |
95 | /* strip more trailing slashes if any */ | 96 | /* strip more trailing slashes if any */ |
96 | while( p && rvbuf[p]=='/') rvbuf[p--]=0; | 97 | while( p && rvbuf[p]=='/') rvbuf[p--]=0; |
97 | /* find last slash in the remaining string */ | 98 | /* find last slash in the remaining string */ |
98 | rv = strrchr(rvbuf,'/'); | 99 | rv = strrchr(rvbuf,'/'); |
99 | if(rv) | 100 | if(rv) |
100 | return ++rv; | 101 | return ++rv; |
101 | return rvbuf; | 102 | return rvbuf; |
102 | } | 103 | } |
103 | 104 | ||
104 | char *cgit_currurl() | 105 | char *cgit_currurl() |
105 | { | 106 | { |
106 | if (!ctx.cfg.virtual_root) | 107 | if (!ctx.cfg.virtual_root) |
107 | return ctx.cfg.script_name; | 108 | return ctx.cfg.script_name; |
108 | else if (ctx.qry.page) | 109 | else if (ctx.qry.page) |
109 | return fmt("%s/%s/%s/", ctx.cfg.virtual_root, ctx.qry.repo, ctx.qry.page); | 110 | return fmt("%s/%s/%s/", ctx.cfg.virtual_root, ctx.qry.repo, ctx.qry.page); |
110 | else if (ctx.qry.repo) | 111 | else if (ctx.qry.repo) |
111 | return fmt("%s/%s/", ctx.cfg.virtual_root, ctx.qry.repo); | 112 | return fmt("%s/%s/", ctx.cfg.virtual_root, ctx.qry.repo); |
112 | else | 113 | else |
113 | return fmt("%s/", ctx.cfg.virtual_root); | 114 | return fmt("%s/", ctx.cfg.virtual_root); |
114 | } | 115 | } |
115 | 116 | ||
116 | static char *repolink(char *title, char *class, char *page, char *head, | 117 | static char *repolink(char *title, char *class, char *page, char *head, |
117 | char *path) | 118 | char *path) |
118 | { | 119 | { |
119 | char *delim = "?"; | 120 | char *delim = "?"; |
120 | 121 | ||
121 | html("<a"); | 122 | html("<a"); |
122 | if (title) { | 123 | if (title) { |
123 | html(" title='"); | 124 | html(" title='"); |
124 | html_attr(title); | 125 | html_attr(title); |
125 | html("'"); | 126 | html("'"); |
126 | } | 127 | } |
127 | if (class) { | 128 | if (class) { |
128 | html(" class='"); | 129 | html(" class='"); |
129 | html_attr(class); | 130 | html_attr(class); |
130 | html("'"); | 131 | html("'"); |
131 | } | 132 | } |
132 | html(" href='"); | 133 | html(" href='"); |
133 | if (ctx.cfg.virtual_root) { | 134 | if (ctx.cfg.virtual_root) { |
134 | html_attr(ctx.cfg.virtual_root); | 135 | html_attr(ctx.cfg.virtual_root); |
135 | if (ctx.cfg.virtual_root[strlen(ctx.cfg.virtual_root) - 1] != '/') | 136 | if (ctx.cfg.virtual_root[strlen(ctx.cfg.virtual_root) - 1] != '/') |
136 | html("/"); | 137 | html("/"); |
137 | html_attr(ctx.repo->url); | 138 | html_attr(ctx.repo->url); |
138 | if (ctx.repo->url[strlen(ctx.repo->url) - 1] != '/') | 139 | if (ctx.repo->url[strlen(ctx.repo->url) - 1] != '/') |
139 | html("/"); | 140 | html("/"); |
140 | if (page) { | 141 | if (page) { |
141 | html(page); | 142 | html(page); |
142 | html("/"); | 143 | html("/"); |
143 | if (path) | 144 | if (path) |
144 | html_attr(path); | 145 | html_attr(path); |
145 | } | 146 | } |
146 | } else { | 147 | } else { |
147 | html(ctx.cfg.script_name); | 148 | html(ctx.cfg.script_name); |
148 | html("?url="); | 149 | html("?url="); |
149 | html_attr(ctx.repo->url); | 150 | html_attr(ctx.repo->url); |
150 | if (ctx.repo->url[strlen(ctx.repo->url) - 1] != '/') | 151 | if (ctx.repo->url[strlen(ctx.repo->url) - 1] != '/') |
151 | html("/"); | 152 | html("/"); |
152 | if (page) { | 153 | if (page) { |
153 | html(page); | 154 | html(page); |
154 | html("/"); | 155 | html("/"); |
155 | if (path) | 156 | if (path) |
156 | html_attr(path); | 157 | html_attr(path); |
157 | } | 158 | } |
158 | delim = "&"; | 159 | delim = "&"; |
159 | } | 160 | } |
160 | if (head && strcmp(head, ctx.repo->defbranch)) { | 161 | if (head && strcmp(head, ctx.repo->defbranch)) { |
161 | html(delim); | 162 | html(delim); |
162 | html("h="); | 163 | html("h="); |
163 | html_attr(head); | 164 | html_attr(head); |
164 | delim = "&"; | 165 | delim = "&"; |
165 | } | 166 | } |
166 | return fmt("%s", delim); | 167 | return fmt("%s", delim); |
167 | } | 168 | } |
168 | 169 | ||
169 | static void reporevlink(char *page, char *name, char *title, char *class, | 170 | static void reporevlink(char *page, char *name, char *title, char *class, |
170 | char *head, char *rev, char *path) | 171 | char *head, char *rev, char *path) |
171 | { | 172 | { |
172 | char *delim; | 173 | char *delim; |
173 | 174 | ||
174 | delim = repolink(title, class, page, head, path); | 175 | delim = repolink(title, class, page, head, path); |
175 | if (rev && strcmp(rev, ctx.qry.head)) { | 176 | if (rev && strcmp(rev, ctx.qry.head)) { |
176 | html(delim); | 177 | html(delim); |
177 | html("id="); | 178 | html("id="); |
178 | html_attr(rev); | 179 | html_attr(rev); |
179 | } | 180 | } |
180 | html("'>"); | 181 | html("'>"); |
181 | html_txt(name); | 182 | html_txt(name); |
182 | html("</a>"); | 183 | html("</a>"); |
183 | } | 184 | } |
184 | 185 | ||
185 | void cgit_tree_link(char *name, char *title, char *class, char *head, | 186 | void cgit_tree_link(char *name, char *title, char *class, char *head, |
186 | char *rev, char *path) | 187 | char *rev, char *path) |
187 | { | 188 | { |
188 | reporevlink("tree", name, title, class, head, rev, path); | 189 | reporevlink("tree", name, title, class, head, rev, path); |
189 | } | 190 | } |
190 | 191 | ||
191 | void cgit_log_link(char *name, char *title, char *class, char *head, | 192 | void cgit_log_link(char *name, char *title, char *class, char *head, |
192 | char *rev, char *path, int ofs, char *grep, char *pattern) | 193 | char *rev, char *path, int ofs, char *grep, char *pattern) |
193 | { | 194 | { |
194 | char *delim; | 195 | char *delim; |
195 | 196 | ||
196 | delim = repolink(title, class, "log", head, path); | 197 | delim = repolink(title, class, "log", head, path); |
197 | if (rev && strcmp(rev, ctx.qry.head)) { | 198 | if (rev && strcmp(rev, ctx.qry.head)) { |
198 | html(delim); | 199 | html(delim); |
199 | html("id="); | 200 | html("id="); |
200 | html_attr(rev); | 201 | html_attr(rev); |
201 | delim = "&"; | 202 | delim = "&"; |
@@ -276,316 +277,278 @@ void cgit_object_link(struct object *obj) | |||
276 | char *page, *arg, *url; | 277 | char *page, *arg, *url; |
277 | 278 | ||
278 | if (obj->type == OBJ_COMMIT) { | 279 | if (obj->type == OBJ_COMMIT) { |
279 | cgit_commit_link(fmt("commit %s", sha1_to_hex(obj->sha1)), NULL, NULL, | 280 | cgit_commit_link(fmt("commit %s", sha1_to_hex(obj->sha1)), NULL, NULL, |
280 | ctx.qry.head, sha1_to_hex(obj->sha1)); | 281 | ctx.qry.head, sha1_to_hex(obj->sha1)); |
281 | return; | 282 | return; |
282 | } else if (obj->type == OBJ_TREE) { | 283 | } else if (obj->type == OBJ_TREE) { |
283 | page = "tree"; | 284 | page = "tree"; |
284 | arg = "id"; | 285 | arg = "id"; |
285 | } else if (obj->type == OBJ_TAG) { | 286 | } else if (obj->type == OBJ_TAG) { |
286 | page = "tag"; | 287 | page = "tag"; |
287 | arg = "id"; | 288 | arg = "id"; |
288 | } else { | 289 | } else { |
289 | page = "blob"; | 290 | page = "blob"; |
290 | arg = "id"; | 291 | arg = "id"; |
291 | } | 292 | } |
292 | 293 | ||
293 | url = cgit_pageurl(ctx.qry.repo, page, | 294 | url = cgit_pageurl(ctx.qry.repo, page, |
294 | fmt("%s=%s", arg, sha1_to_hex(obj->sha1))); | 295 | fmt("%s=%s", arg, sha1_to_hex(obj->sha1))); |
295 | html_link_open(url, NULL, NULL); | 296 | html_link_open(url, NULL, NULL); |
296 | htmlf("%s %s", typename(obj->type), | 297 | htmlf("%s %s", typename(obj->type), |
297 | sha1_to_hex(obj->sha1)); | 298 | sha1_to_hex(obj->sha1)); |
298 | html_link_close(); | 299 | html_link_close(); |
299 | } | 300 | } |
300 | 301 | ||
301 | void cgit_print_date(time_t secs, char *format) | 302 | void cgit_print_date(time_t secs, char *format) |
302 | { | 303 | { |
303 | char buf[64]; | 304 | char buf[64]; |
304 | struct tm *time; | 305 | struct tm *time; |
305 | 306 | ||
306 | if (!secs) | 307 | if (!secs) |
307 | return; | 308 | return; |
308 | time = gmtime(&secs); | 309 | time = gmtime(&secs); |
309 | strftime(buf, sizeof(buf)-1, format, time); | 310 | strftime(buf, sizeof(buf)-1, format, time); |
310 | html_txt(buf); | 311 | html_txt(buf); |
311 | } | 312 | } |
312 | 313 | ||
313 | void cgit_print_age(time_t t, time_t max_relative, char *format) | 314 | void cgit_print_age(time_t t, time_t max_relative, char *format) |
314 | { | 315 | { |
315 | time_t now, secs; | 316 | time_t now, secs; |
316 | 317 | ||
317 | if (!t) | 318 | if (!t) |
318 | return; | 319 | return; |
319 | time(&now); | 320 | time(&now); |
320 | secs = now - t; | 321 | secs = now - t; |
321 | 322 | ||
322 | if (secs > max_relative && max_relative >= 0) { | 323 | if (secs > max_relative && max_relative >= 0) { |
323 | cgit_print_date(t, format); | 324 | cgit_print_date(t, format); |
324 | return; | 325 | return; |
325 | } | 326 | } |
326 | 327 | ||
327 | if (secs < TM_HOUR * 2) { | 328 | if (secs < TM_HOUR * 2) { |
328 | htmlf("<span class='age-mins'>%.0f min.</span>", | 329 | htmlf("<span class='age-mins'>%.0f min.</span>", |
329 | secs * 1.0 / TM_MIN); | 330 | secs * 1.0 / TM_MIN); |
330 | return; | 331 | return; |
331 | } | 332 | } |
332 | if (secs < TM_DAY * 2) { | 333 | if (secs < TM_DAY * 2) { |
333 | htmlf("<span class='age-hours'>%.0f hours</span>", | 334 | htmlf("<span class='age-hours'>%.0f hours</span>", |
334 | secs * 1.0 / TM_HOUR); | 335 | secs * 1.0 / TM_HOUR); |
335 | return; | 336 | return; |
336 | } | 337 | } |
337 | if (secs < TM_WEEK * 2) { | 338 | if (secs < TM_WEEK * 2) { |
338 | htmlf("<span class='age-days'>%.0f days</span>", | 339 | htmlf("<span class='age-days'>%.0f days</span>", |
339 | secs * 1.0 / TM_DAY); | 340 | secs * 1.0 / TM_DAY); |
340 | return; | 341 | return; |
341 | } | 342 | } |
342 | if (secs < TM_MONTH * 2) { | 343 | if (secs < TM_MONTH * 2) { |
343 | htmlf("<span class='age-weeks'>%.0f weeks</span>", | 344 | htmlf("<span class='age-weeks'>%.0f weeks</span>", |
344 | secs * 1.0 / TM_WEEK); | 345 | secs * 1.0 / TM_WEEK); |
345 | return; | 346 | return; |
346 | } | 347 | } |
347 | if (secs < TM_YEAR * 2) { | 348 | if (secs < TM_YEAR * 2) { |
348 | htmlf("<span class='age-months'>%.0f months</span>", | 349 | htmlf("<span class='age-months'>%.0f months</span>", |
349 | secs * 1.0 / TM_MONTH); | 350 | secs * 1.0 / TM_MONTH); |
350 | return; | 351 | return; |
351 | } | 352 | } |
352 | htmlf("<span class='age-years'>%.0f years</span>", | 353 | htmlf("<span class='age-years'>%.0f years</span>", |
353 | secs * 1.0 / TM_YEAR); | 354 | secs * 1.0 / TM_YEAR); |
354 | } | 355 | } |
355 | 356 | ||
356 | void cgit_print_http_headers(struct cgit_context *ctx) | 357 | void cgit_print_http_headers(struct cgit_context *ctx) |
357 | { | 358 | { |
358 | if (ctx->page.mimetype && ctx->page.charset) | 359 | if (ctx->page.mimetype && ctx->page.charset) |
359 | htmlf("Content-Type: %s; charset=%s\n", ctx->page.mimetype, | 360 | htmlf("Content-Type: %s; charset=%s\n", ctx->page.mimetype, |
360 | ctx->page.charset); | 361 | ctx->page.charset); |
361 | else if (ctx->page.mimetype) | 362 | else if (ctx->page.mimetype) |
362 | htmlf("Content-Type: %s\n", ctx->page.mimetype); | 363 | htmlf("Content-Type: %s\n", ctx->page.mimetype); |
363 | if (ctx->page.filename) | 364 | if (ctx->page.filename) |
364 | htmlf("Content-Disposition: inline; filename=\"%s\"\n", | 365 | htmlf("Content-Disposition: inline; filename=\"%s\"\n", |
365 | ctx->page.filename); | 366 | ctx->page.filename); |
366 | htmlf("Last-Modified: %s\n", http_date(ctx->page.modified)); | 367 | htmlf("Last-Modified: %s\n", http_date(ctx->page.modified)); |
367 | htmlf("Expires: %s\n", http_date(ctx->page.expires)); | 368 | htmlf("Expires: %s\n", http_date(ctx->page.expires)); |
368 | html("\n"); | 369 | html("\n"); |
369 | } | 370 | } |
370 | 371 | ||
371 | void cgit_print_docstart(struct cgit_context *ctx) | 372 | void cgit_print_docstart(struct cgit_context *ctx) |
372 | { | 373 | { |
373 | html(cgit_doctype); | 374 | html(cgit_doctype); |
374 | html("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n"); | 375 | html("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n"); |
375 | html("<head>\n"); | 376 | html("<head>\n"); |
376 | html("<title>"); | 377 | html("<title>"); |
377 | html_txt(ctx->page.title); | 378 | html_txt(ctx->page.title); |
378 | html("</title>\n"); | 379 | html("</title>\n"); |
379 | htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version); | 380 | htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version); |
380 | if (ctx->cfg.robots && *ctx->cfg.robots) | 381 | if (ctx->cfg.robots && *ctx->cfg.robots) |
381 | htmlf("<meta name='robots' content='%s'/>\n", ctx->cfg.robots); | 382 | htmlf("<meta name='robots' content='%s'/>\n", ctx->cfg.robots); |
382 | html("<link rel='stylesheet' type='text/css' href='"); | 383 | html("<link rel='stylesheet' type='text/css' href='"); |
383 | html_attr(ctx->cfg.css); | 384 | html_attr(ctx->cfg.css); |
384 | html("'/>\n"); | 385 | html("'/>\n"); |
385 | html("</head>\n"); | 386 | html("</head>\n"); |
386 | html("<body>\n"); | 387 | html("<body>\n"); |
387 | } | 388 | } |
388 | 389 | ||
389 | void cgit_print_docend() | 390 | void cgit_print_docend() |
390 | { | 391 | { |
391 | html("</td>\n</tr>\n</table>\n</body>\n</html>\n"); | 392 | html("</td>\n</tr>\n</table>\n</body>\n</html>\n"); |
392 | } | 393 | } |
393 | 394 | ||
394 | int print_branch_option(const char *refname, const unsigned char *sha1, | 395 | int print_branch_option(const char *refname, const unsigned char *sha1, |
395 | int flags, void *cb_data) | 396 | int flags, void *cb_data) |
396 | { | 397 | { |
397 | char *name = (char *)refname; | 398 | char *name = (char *)refname; |
398 | html_option(name, name, ctx.qry.head); | 399 | html_option(name, name, ctx.qry.head); |
399 | return 0; | 400 | return 0; |
400 | } | 401 | } |
401 | 402 | ||
402 | int print_archive_ref(const char *refname, const unsigned char *sha1, | 403 | int print_archive_ref(const char *refname, const unsigned char *sha1, |
403 | int flags, void *cb_data) | 404 | int flags, void *cb_data) |
404 | { | 405 | { |
405 | struct tag *tag; | 406 | struct tag *tag; |
406 | struct taginfo *info; | 407 | struct taginfo *info; |
407 | struct object *obj; | 408 | struct object *obj; |
408 | char buf[256], *url; | 409 | char buf[256], *url; |
409 | unsigned char fileid[20]; | 410 | unsigned char fileid[20]; |
410 | int *header = (int *)cb_data; | 411 | int *header = (int *)cb_data; |
411 | 412 | ||
412 | if (prefixcmp(refname, "refs/archives")) | 413 | if (prefixcmp(refname, "refs/archives")) |
413 | return 0; | 414 | return 0; |
414 | strncpy(buf, refname+14, sizeof(buf)); | 415 | strncpy(buf, refname+14, sizeof(buf)); |
415 | obj = parse_object(sha1); | 416 | obj = parse_object(sha1); |
416 | if (!obj) | 417 | if (!obj) |
417 | return 1; | 418 | return 1; |
418 | if (obj->type == OBJ_TAG) { | 419 | if (obj->type == OBJ_TAG) { |
419 | tag = lookup_tag(sha1); | 420 | tag = lookup_tag(sha1); |
420 | if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) | 421 | if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) |
421 | return 0; | 422 | return 0; |
422 | hashcpy(fileid, tag->tagged->sha1); | 423 | hashcpy(fileid, tag->tagged->sha1); |
423 | } else if (obj->type != OBJ_BLOB) { | 424 | } else if (obj->type != OBJ_BLOB) { |
424 | return 0; | 425 | return 0; |
425 | } else { | 426 | } else { |
426 | hashcpy(fileid, sha1); | 427 | hashcpy(fileid, sha1); |
427 | } | 428 | } |
428 | if (!*header) { | 429 | if (!*header) { |
429 | html("<h1>download</h1>\n"); | 430 | html("<h1>download</h1>\n"); |
430 | *header = 1; | 431 | *header = 1; |
431 | } | 432 | } |
432 | url = cgit_pageurl(ctx.qry.repo, "blob", | 433 | url = cgit_pageurl(ctx.qry.repo, "blob", |
433 | fmt("id=%s&path=%s", sha1_to_hex(fileid), | 434 | fmt("id=%s&path=%s", sha1_to_hex(fileid), |
434 | buf)); | 435 | buf)); |
435 | html_link_open(url, NULL, "menu"); | 436 | html_link_open(url, NULL, "menu"); |
436 | html_txt(strlpart(buf, 20)); | 437 | html_txt(strlpart(buf, 20)); |
437 | html_link_close(); | 438 | html_link_close(); |
438 | return 0; | 439 | return 0; |
439 | } | 440 | } |
440 | 441 | ||
441 | void add_hidden_formfields(int incl_head, int incl_search, char *page) | 442 | void add_hidden_formfields(int incl_head, int incl_search, char *page) |
442 | { | 443 | { |
443 | char *url; | 444 | char *url; |
444 | 445 | ||
445 | if (!ctx.cfg.virtual_root) { | 446 | if (!ctx.cfg.virtual_root) { |
446 | url = fmt("%s/%s", ctx.qry.repo, page); | 447 | url = fmt("%s/%s", ctx.qry.repo, page); |
447 | if (ctx.qry.path) | 448 | if (ctx.qry.path) |
448 | url = fmt("%s/%s", url, ctx.qry.path); | 449 | url = fmt("%s/%s", url, ctx.qry.path); |
449 | html_hidden("url", url); | 450 | html_hidden("url", url); |
450 | } | 451 | } |
451 | 452 | ||
452 | if (incl_head && strcmp(ctx.qry.head, ctx.repo->defbranch)) | 453 | if (incl_head && strcmp(ctx.qry.head, ctx.repo->defbranch)) |
453 | html_hidden("h", ctx.qry.head); | 454 | html_hidden("h", ctx.qry.head); |
454 | 455 | ||
455 | if (ctx.qry.sha1) | 456 | if (ctx.qry.sha1) |
456 | html_hidden("id", ctx.qry.sha1); | 457 | html_hidden("id", ctx.qry.sha1); |
457 | if (ctx.qry.sha2) | 458 | if (ctx.qry.sha2) |
458 | html_hidden("id2", ctx.qry.sha2); | 459 | html_hidden("id2", ctx.qry.sha2); |
459 | 460 | ||
460 | if (incl_search) { | 461 | if (incl_search) { |
461 | if (ctx.qry.grep) | 462 | if (ctx.qry.grep) |
462 | html_hidden("qt", ctx.qry.grep); | 463 | html_hidden("qt", ctx.qry.grep); |
463 | if (ctx.qry.search) | 464 | if (ctx.qry.search) |
464 | html_hidden("q", ctx.qry.search); | 465 | html_hidden("q", ctx.qry.search); |
465 | } | 466 | } |
466 | } | 467 | } |
467 | 468 | ||
469 | char *hc(struct cgit_cmd *cmd, const char *page) | ||
470 | { | ||
471 | return (strcmp(cmd->name, page) ? NULL : "active"); | ||
472 | } | ||
473 | |||
468 | void cgit_print_pageheader(struct cgit_context *ctx) | 474 | void cgit_print_pageheader(struct cgit_context *ctx) |
469 | { | 475 | { |
470 | static const char *default_info = "This is cgit, a fast webinterface for git repositories"; | 476 | struct cgit_cmd *cmd = cgit_get_cmd(ctx); |
471 | int header = 0; | ||
472 | char *url; | ||
473 | 477 | ||
474 | html("<table id='layout' summary=''>\n"); | 478 | html("<table id='header'>\n"); |
475 | html("<tr><td id='sidebar'>\n"); | 479 | html("<tr>\n"); |
476 | html("<table class='sidebar' cellspacing='0' summary=''>\n"); | 480 | html("<td class='logo' rowspan='2'><a href='"); |
477 | html("<tr><td class='sidebar'>\n<a href='"); | ||
478 | html_attr(cgit_rooturl()); | 481 | html_attr(cgit_rooturl()); |
479 | htmlf("'><img src='%s' alt='cgit'/></a>\n", | 482 | html("'><img src='"); |
480 | ctx->cfg.logo); | 483 | html_attr(ctx->cfg.logo); |
481 | html("</td></tr>\n<tr><td class='sidebar'>\n"); | 484 | html("'/></a></td>\n"); |
482 | if (ctx->repo) { | 485 | html("<td class='main'>"); |
483 | html("<h1 class='first'>"); | 486 | if (ctx->repo) |
484 | html_txt(strrpart(ctx->repo->name, 20)); | 487 | html_txt(ctx->repo->name); |
485 | html("</h1>\n"); | 488 | else |
489 | html_txt(ctx->cfg.root_title); | ||
490 | html("</td></tr>\n"); | ||
491 | html("<tr><td class='sub'>"); | ||
492 | if (ctx->repo) | ||
486 | html_txt(ctx->repo->desc); | 493 | html_txt(ctx->repo->desc); |
487 | if (ctx->repo->owner) { | 494 | else |
488 | html("<h1>owner</h1>\n"); | 495 | html_txt(ctx->cfg.index_info); |
489 | html_txt(ctx->repo->owner); | 496 | html("</td></tr>\n"); |
490 | } | 497 | html("</table>\n"); |
491 | html("<h1>navigate</h1>\n"); | 498 | |
492 | reporevlink(NULL, "summary", NULL, "menu", ctx->qry.head, | 499 | html("<table class='tabs'><tr><td>\n"); |
493 | NULL, NULL); | 500 | if (ctx->repo) { |
494 | cgit_log_link("log", NULL, "menu", ctx->qry.head, NULL, NULL, | 501 | reporevlink(NULL, "summary", NULL, hc(cmd, "summary"), |
495 | 0, NULL, NULL); | 502 | ctx->qry.head, NULL, NULL); |
496 | cgit_tree_link("tree", NULL, "menu", ctx->qry.head, | 503 | cgit_refs_link("refs", NULL, hc(cmd, "refs"), ctx->qry.head, |
497 | ctx->qry.sha1, NULL); | 504 | ctx->qry.sha1, NULL); |
498 | cgit_commit_link("commit", NULL, "menu", ctx->qry.head, | 505 | cgit_log_link("log", NULL, hc(cmd, "log"), ctx->qry.head, |
499 | ctx->qry.sha1); | 506 | NULL, NULL, 0, NULL, NULL); |
500 | cgit_diff_link("diff", NULL, "menu", ctx->qry.head, | 507 | cgit_tree_link("tree", NULL, hc(cmd, "tree"), ctx->qry.head, |
508 | ctx->qry.sha1, NULL); | ||
509 | cgit_commit_link("commit", NULL, hc(cmd, "commit"), | ||
510 | ctx->qry.head, ctx->qry.sha1); | ||
511 | cgit_diff_link("diff", NULL, hc(cmd, "diff"), ctx->qry.head, | ||
501 | ctx->qry.sha1, ctx->qry.sha2, NULL); | 512 | ctx->qry.sha1, ctx->qry.sha2, NULL); |
502 | cgit_patch_link("patch", NULL, "menu", ctx->qry.head, | 513 | cgit_patch_link("patch", NULL, hc(cmd, "patch"), ctx->qry.head, |
503 | ctx->qry.sha1); | 514 | ctx->qry.sha1); |
504 | |||
505 | for_each_ref(print_archive_ref, &header); | ||
506 | |||
507 | if (ctx->repo->clone_url || ctx->cfg.clone_prefix) { | ||
508 | html("<h1>clone</h1>\n"); | ||
509 | if (ctx->repo->clone_url) | ||
510 | url = ctx->repo->clone_url; | ||
511 | else | ||
512 | url = fmt("%s%s", ctx->cfg.clone_prefix, | ||
513 | ctx->repo->url); | ||
514 | html("<a class='menu' href='"); | ||
515 | html_attr(url); | ||
516 | html("' title='"); | ||
517 | html_attr(url); | ||
518 | html("'>\n"); | ||
519 | html_txt(strrpart(url, 20)); | ||
520 | html("</a>\n"); | ||
521 | } | ||
522 | |||
523 | html("<h1>branch</h1>\n"); | ||
524 | html("<form method='get' action=''>\n"); | ||
525 | add_hidden_formfields(0, 1, ctx->qry.page); | ||
526 | // html("<table summary='branch selector' class='grid'><tr><td id='branch-dropdown-cell'>"); | ||
527 | html("<select name='h' onchange='this.form.submit();'>\n"); | ||
528 | for_each_branch_ref(print_branch_option, ctx->qry.head); | ||
529 | html("</select>\n"); | ||
530 | // html("</td><td>"); | ||
531 | html("<noscript><input type='submit' id='switch-btn' value='switch'/></noscript>\n"); | ||
532 | // html("</td></tr></table>"); | ||
533 | html("</form>\n"); | ||
534 | |||
535 | html("<h1>search</h1>\n"); | ||
536 | html("<form method='get' action='"); | ||
537 | if (ctx->cfg.virtual_root) | ||
538 | html_attr(cgit_fileurl(ctx->qry.repo, "log", | ||
539 | ctx->qry.path, NULL)); | ||
540 | html("'>\n"); | ||
541 | add_hidden_formfields(1, 0, "log"); | ||
542 | html("<select name='qt'>\n"); | ||
543 | html_option("grep", "log msg", ctx->qry.grep); | ||
544 | html_option("author", "author", ctx->qry.grep); | ||
545 | html_option("committer", "committer", ctx->qry.grep); | ||
546 | html("</select>\n"); | ||
547 | html("<input class='txt' type='text' name='q' value='"); | ||
548 | html_attr(ctx->qry.search); | ||
549 | html("'/>\n"); | ||
550 | html("</form>\n"); | ||
551 | } else { | 515 | } else { |
552 | if (!ctx->cfg.index_info || html_include(ctx->cfg.index_info)) | 516 | html("<a class='active' href='"); |
553 | html(default_info); | 517 | html_attr(cgit_rooturl()); |
518 | html("'>index</a>\n"); | ||
554 | } | 519 | } |
555 | 520 | html("</td></tr></table>\n"); | |
556 | html("</td></tr></table></td>\n"); | 521 | html("<div class='content'>"); |
557 | |||
558 | html("<td id='content'>\n"); | ||
559 | } | 522 | } |
560 | 523 | ||
561 | void cgit_print_filemode(unsigned short mode) | 524 | void cgit_print_filemode(unsigned short mode) |
562 | { | 525 | { |
563 | if (S_ISDIR(mode)) | 526 | if (S_ISDIR(mode)) |
564 | html("d"); | 527 | html("d"); |
565 | else if (S_ISLNK(mode)) | 528 | else if (S_ISLNK(mode)) |
566 | html("l"); | 529 | html("l"); |
567 | else if (S_ISGITLINK(mode)) | 530 | else if (S_ISGITLINK(mode)) |
568 | html("m"); | 531 | html("m"); |
569 | else | 532 | else |
570 | html("-"); | 533 | html("-"); |
571 | html_fileperm(mode >> 6); | 534 | html_fileperm(mode >> 6); |
572 | html_fileperm(mode >> 3); | 535 | html_fileperm(mode >> 3); |
573 | html_fileperm(mode); | 536 | html_fileperm(mode); |
574 | } | 537 | } |
575 | 538 | ||
576 | void cgit_print_snapshot_links(const char *repo, const char *head, | 539 | void cgit_print_snapshot_links(const char *repo, const char *head, |
577 | const char *hex, int snapshots) | 540 | const char *hex, int snapshots) |
578 | { | 541 | { |
579 | const struct cgit_snapshot_format* f; | 542 | const struct cgit_snapshot_format* f; |
580 | char *filename; | 543 | char *filename; |
581 | 544 | ||
582 | for (f = cgit_snapshot_formats; f->suffix; f++) { | 545 | for (f = cgit_snapshot_formats; f->suffix; f++) { |
583 | if (!(snapshots & f->bit)) | 546 | if (!(snapshots & f->bit)) |
584 | continue; | 547 | continue; |
585 | filename = fmt("%s-%s%s", cgit_repobasename(repo), hex, | 548 | filename = fmt("%s-%s%s", cgit_repobasename(repo), hex, |
586 | f->suffix); | 549 | f->suffix); |
587 | cgit_snapshot_link(filename, NULL, NULL, (char *)head, | 550 | cgit_snapshot_link(filename, NULL, NULL, (char *)head, |
588 | (char *)hex, filename); | 551 | (char *)hex, filename); |
589 | html("<br/>"); | 552 | html("<br/>"); |
590 | } | 553 | } |
591 | } | 554 | } |