ui-shared.c (view raw)
1/* ui-shared.c: common web output functions
2 *
3 * Copyright (C) 2006 Lars Hjemli
4 *
5 * Licensed under GNU General Public License v2
6 * (see COPYING for full license text)
7 */
8
9#include "cgit.h"
10#include "cmd.h"
11#include "html.h"
12
13const char cgit_doctype[] =
14"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n"
15" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
16
17static char *http_date(time_t t)
18{
19 static char day[][4] =
20 {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
21 static char month[][4] =
22 {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
23 "Jul", "Aug", "Sep", "Oct", "Now", "Dec"};
24 struct tm *tm = gmtime(&t);
25 return fmt("%s, %02d %s %04d %02d:%02d:%02d GMT", day[tm->tm_wday],
26 tm->tm_mday, month[tm->tm_mon], 1900+tm->tm_year,
27 tm->tm_hour, tm->tm_min, tm->tm_sec);
28}
29
30void cgit_print_error(char *msg)
31{
32 html("<div class='error'>");
33 html_txt(msg);
34 html("</div>\n");
35}
36
37char *cgit_httpscheme()
38{
39 char *https;
40
41 https = getenv("HTTPS");
42 if (https != NULL && strcmp(https, "on") == 0)
43 return "https://";
44 else
45 return "http://";
46}
47
48char *cgit_hosturl()
49{
50 char *host, *port;
51
52 host = getenv("HTTP_HOST");
53 if (host) {
54 host = xstrdup(host);
55 } else {
56 host = getenv("SERVER_NAME");
57 if (!host)
58 return NULL;
59 port = getenv("SERVER_PORT");
60 if (port && atoi(port) != 80)
61 host = xstrdup(fmt("%s:%d", host, atoi(port)));
62 else
63 host = xstrdup(host);
64 }
65 return host;
66}
67
68char *cgit_rooturl()
69{
70 if (ctx.cfg.virtual_root)
71 return fmt("%s/", ctx.cfg.virtual_root);
72 else
73 return ctx.cfg.script_name;
74}
75
76char *cgit_repourl(const char *reponame)
77{
78 if (ctx.cfg.virtual_root) {
79 return fmt("%s/%s/", ctx.cfg.virtual_root, reponame);
80 } else {
81 return fmt("?r=%s", reponame);
82 }
83}
84
85char *cgit_fileurl(const char *reponame, const char *pagename,
86 const char *filename, const char *query)
87{
88 char *tmp;
89 char *delim;
90
91 if (ctx.cfg.virtual_root) {
92 tmp = fmt("%s/%s/%s/%s", ctx.cfg.virtual_root, reponame,
93 pagename, (filename ? filename:""));
94 delim = "?";
95 } else {
96 tmp = fmt("?url=%s/%s/%s", reponame, pagename,
97 (filename ? filename : ""));
98 delim = "&";
99 }
100 if (query)
101 tmp = fmt("%s%s%s", tmp, delim, query);
102 return tmp;
103}
104
105char *cgit_pageurl(const char *reponame, const char *pagename,
106 const char *query)
107{
108 return cgit_fileurl(reponame,pagename,0,query);
109}
110
111const char *cgit_repobasename(const char *reponame)
112{
113 /* I assume we don't need to store more than one repo basename */
114 static char rvbuf[1024];
115 int p;
116 const char *rv;
117 strncpy(rvbuf,reponame,sizeof(rvbuf));
118 if(rvbuf[sizeof(rvbuf)-1])
119 die("cgit_repobasename: truncated repository name '%s'", reponame);
120 p = strlen(rvbuf)-1;
121 /* strip trailing slashes */
122 while(p && rvbuf[p]=='/') rvbuf[p--]=0;
123 /* strip trailing .git */
124 if(p>=3 && !strncmp(&rvbuf[p-3],".git",4)) {
125 p -= 3; rvbuf[p--] = 0;
126 }
127 /* strip more trailing slashes if any */
128 while( p && rvbuf[p]=='/') rvbuf[p--]=0;
129 /* find last slash in the remaining string */
130 rv = strrchr(rvbuf,'/');
131 if(rv)
132 return ++rv;
133 return rvbuf;
134}
135
136char *cgit_currurl()
137{
138 if (!ctx.cfg.virtual_root)
139 return ctx.cfg.script_name;
140 else if (ctx.qry.page)
141 return fmt("%s/%s/%s/", ctx.cfg.virtual_root, ctx.qry.repo, ctx.qry.page);
142 else if (ctx.qry.repo)
143 return fmt("%s/%s/", ctx.cfg.virtual_root, ctx.qry.repo);
144 else
145 return fmt("%s/", ctx.cfg.virtual_root);
146}
147
148static void site_url(char *page, char *search, int ofs)
149{
150 char *delim = "?";
151
152 if (ctx.cfg.virtual_root) {
153 html_attr(ctx.cfg.virtual_root);
154 if (ctx.cfg.virtual_root[strlen(ctx.cfg.virtual_root) - 1] != '/')
155 html("/");
156 } else
157 html(ctx.cfg.script_name);
158
159 if (page) {
160 htmlf("?p=%s", page);
161 delim = "&";
162 }
163 if (search) {
164 html(delim);
165 html("q=");
166 html_attr(search);
167 delim = "&";
168 }
169 if (ofs) {
170 html(delim);
171 htmlf("ofs=%d", ofs);
172 }
173}
174
175static void site_link(char *page, char *name, char *title, char *class,
176 char *search, int ofs)
177{
178 html("<a");
179 if (title) {
180 html(" title='");
181 html_attr(title);
182 html("'");
183 }
184 if (class) {
185 html(" class='");
186 html_attr(class);
187 html("'");
188 }
189 html(" href='");
190 site_url(page, search, ofs);
191 html("'>");
192 html_txt(name);
193 html("</a>");
194}
195
196void cgit_index_link(char *name, char *title, char *class, char *pattern,
197 int ofs)
198{
199 site_link(NULL, name, title, class, pattern, ofs);
200}
201
202static char *repolink(char *title, char *class, char *page, char *head,
203 char *path)
204{
205 char *delim = "?";
206
207 html("<a");
208 if (title) {
209 html(" title='");
210 html_attr(title);
211 html("'");
212 }
213 if (class) {
214 html(" class='");
215 html_attr(class);
216 html("'");
217 }
218 html(" href='");
219 if (ctx.cfg.virtual_root) {
220 html_url_path(ctx.cfg.virtual_root);
221 if (ctx.cfg.virtual_root[strlen(ctx.cfg.virtual_root) - 1] != '/')
222 html("/");
223 html_url_path(ctx.repo->url);
224 if (ctx.repo->url[strlen(ctx.repo->url) - 1] != '/')
225 html("/");
226 if (page) {
227 html_url_path(page);
228 html("/");
229 if (path)
230 html_url_path(path);
231 }
232 } else {
233 html(ctx.cfg.script_name);
234 html("?url=");
235 html_url_arg(ctx.repo->url);
236 if (ctx.repo->url[strlen(ctx.repo->url) - 1] != '/')
237 html("/");
238 if (page) {
239 html_url_arg(page);
240 html("/");
241 if (path)
242 html_url_arg(path);
243 }
244 delim = "&";
245 }
246 if (head && strcmp(head, ctx.repo->defbranch)) {
247 html(delim);
248 html("h=");
249 html_url_arg(head);
250 delim = "&";
251 }
252 return fmt("%s", delim);
253}
254
255static void reporevlink(char *page, char *name, char *title, char *class,
256 char *head, char *rev, char *path)
257{
258 char *delim;
259
260 delim = repolink(title, class, page, head, path);
261 if (rev && strcmp(rev, ctx.qry.head)) {
262 html(delim);
263 html("id=");
264 html_url_arg(rev);
265 }
266 html("'>");
267 html_txt(name);
268 html("</a>");
269}
270
271void cgit_summary_link(char *name, char *title, char *class, char *head)
272{
273 reporevlink(NULL, name, title, class, head, NULL, NULL);
274}
275
276void cgit_tag_link(char *name, char *title, char *class, char *head,
277 char *rev)
278{
279 reporevlink("tag", name, title, class, head, rev, NULL);
280}
281
282void cgit_tree_link(char *name, char *title, char *class, char *head,
283 char *rev, char *path)
284{
285 reporevlink("tree", name, title, class, head, rev, path);
286}
287
288void cgit_plain_link(char *name, char *title, char *class, char *head,
289 char *rev, char *path)
290{
291 reporevlink("plain", name, title, class, head, rev, path);
292}
293
294void cgit_log_link(char *name, char *title, char *class, char *head,
295 char *rev, char *path, int ofs, char *grep, char *pattern,
296 int showmsg)
297{
298 char *delim;
299
300 delim = repolink(title, class, "log", head, path);
301 if (rev && strcmp(rev, ctx.qry.head)) {
302 html(delim);
303 html("id=");
304 html_url_arg(rev);
305 delim = "&";
306 }
307 if (grep && pattern) {
308 html(delim);
309 html("qt=");
310 html_url_arg(grep);
311 delim = "&";
312 html(delim);
313 html("q=");
314 html_url_arg(pattern);
315 }
316 if (ofs > 0) {
317 html(delim);
318 html("ofs=");
319 htmlf("%d", ofs);
320 delim = "&";
321 }
322 if (showmsg) {
323 html(delim);
324 html("showmsg=1");
325 }
326 html("'>");
327 html_txt(name);
328 html("</a>");
329}
330
331void cgit_commit_link(char *name, char *title, char *class, char *head,
332 char *rev)
333{
334 if (strlen(name) > ctx.cfg.max_msg_len && ctx.cfg.max_msg_len >= 15) {
335 name[ctx.cfg.max_msg_len] = '\0';
336 name[ctx.cfg.max_msg_len - 1] = '.';
337 name[ctx.cfg.max_msg_len - 2] = '.';
338 name[ctx.cfg.max_msg_len - 3] = '.';
339 }
340 reporevlink("commit", name, title, class, head, rev, NULL);
341}
342
343void cgit_refs_link(char *name, char *title, char *class, char *head,
344 char *rev, char *path)
345{
346 reporevlink("refs", name, title, class, head, rev, path);
347}
348
349void cgit_snapshot_link(char *name, char *title, char *class, char *head,
350 char *rev, char *archivename)
351{
352 reporevlink("snapshot", name, title, class, head, rev, archivename);
353}
354
355void cgit_diff_link(char *name, char *title, char *class, char *head,
356 char *new_rev, char *old_rev, char *path)
357{
358 char *delim;
359
360 delim = repolink(title, class, "diff", head, path);
361 if (new_rev && strcmp(new_rev, ctx.qry.head)) {
362 html(delim);
363 html("id=");
364 html_url_arg(new_rev);
365 delim = "&";
366 }
367 if (old_rev) {
368 html(delim);
369 html("id2=");
370 html_url_arg(old_rev);
371 }
372 html("'>");
373 html_txt(name);
374 html("</a>");
375}
376
377void cgit_patch_link(char *name, char *title, char *class, char *head,
378 char *rev)
379{
380 reporevlink("patch", name, title, class, head, rev, NULL);
381}
382
383void cgit_stats_link(char *name, char *title, char *class, char *head,
384 char *path)
385{
386 reporevlink("stats", name, title, class, head, NULL, path);
387}
388
389void cgit_object_link(struct object *obj)
390{
391 char *page, *shortrev, *fullrev, *name;
392
393 fullrev = sha1_to_hex(obj->sha1);
394 shortrev = xstrdup(fullrev);
395 shortrev[10] = '\0';
396 if (obj->type == OBJ_COMMIT) {
397 cgit_commit_link(fmt("commit %s...", shortrev), NULL, NULL,
398 ctx.qry.head, fullrev);
399 return;
400 } else if (obj->type == OBJ_TREE)
401 page = "tree";
402 else if (obj->type == OBJ_TAG)
403 page = "tag";
404 else
405 page = "blob";
406 name = fmt("%s %s...", typename(obj->type), shortrev);
407 reporevlink(page, name, NULL, NULL, ctx.qry.head, fullrev, NULL);
408}
409
410void cgit_print_date(time_t secs, char *format, int local_time)
411{
412 char buf[64];
413 struct tm *time;
414
415 if (!secs)
416 return;
417 if(local_time)
418 time = localtime(&secs);
419 else
420 time = gmtime(&secs);
421 strftime(buf, sizeof(buf)-1, format, time);
422 html_txt(buf);
423}
424
425void cgit_print_age(time_t t, time_t max_relative, char *format)
426{
427 time_t now, secs;
428
429 if (!t)
430 return;
431 time(&now);
432 secs = now - t;
433
434 if (secs > max_relative && max_relative >= 0) {
435 cgit_print_date(t, format, ctx.cfg.local_time);
436 return;
437 }
438
439 if (secs < TM_HOUR * 2) {
440 htmlf("<span class='age-mins'>%.0f min.</span>",
441 secs * 1.0 / TM_MIN);
442 return;
443 }
444 if (secs < TM_DAY * 2) {
445 htmlf("<span class='age-hours'>%.0f hours</span>",
446 secs * 1.0 / TM_HOUR);
447 return;
448 }
449 if (secs < TM_WEEK * 2) {
450 htmlf("<span class='age-days'>%.0f days</span>",
451 secs * 1.0 / TM_DAY);
452 return;
453 }
454 if (secs < TM_MONTH * 2) {
455 htmlf("<span class='age-weeks'>%.0f weeks</span>",
456 secs * 1.0 / TM_WEEK);
457 return;
458 }
459 if (secs < TM_YEAR * 2) {
460 htmlf("<span class='age-months'>%.0f months</span>",
461 secs * 1.0 / TM_MONTH);
462 return;
463 }
464 htmlf("<span class='age-years'>%.0f years</span>",
465 secs * 1.0 / TM_YEAR);
466}
467
468void cgit_print_http_headers(struct cgit_context *ctx)
469{
470 const char *method = getenv("REQUEST_METHOD");
471
472 if (ctx->page.status)
473 htmlf("Status: %d %s\n", ctx->page.status, ctx->page.statusmsg);
474 if (ctx->page.mimetype && ctx->page.charset)
475 htmlf("Content-Type: %s; charset=%s\n", ctx->page.mimetype,
476 ctx->page.charset);
477 else if (ctx->page.mimetype)
478 htmlf("Content-Type: %s\n", ctx->page.mimetype);
479 if (ctx->page.size)
480 htmlf("Content-Length: %ld\n", ctx->page.size);
481 if (ctx->page.filename)
482 htmlf("Content-Disposition: inline; filename=\"%s\"\n",
483 ctx->page.filename);
484 htmlf("Last-Modified: %s\n", http_date(ctx->page.modified));
485 htmlf("Expires: %s\n", http_date(ctx->page.expires));
486 if (ctx->page.etag)
487 htmlf("ETag: \"%s\"\n", ctx->page.etag);
488 html("\n");
489 if (method && !strcmp(method, "HEAD"))
490 exit(0);
491}
492
493void cgit_print_docstart(struct cgit_context *ctx)
494{
495 char *host = cgit_hosturl();
496 html(cgit_doctype);
497 html("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n");
498 html("<head>\n");
499 html("<title>");
500 html_txt(ctx->page.title);
501 html("</title>\n");
502 htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version);
503 if (ctx->cfg.robots && *ctx->cfg.robots)
504 htmlf("<meta name='robots' content='%s'/>\n", ctx->cfg.robots);
505 html("<link rel='stylesheet' type='text/css' href='");
506 html_attr(ctx->cfg.css);
507 html("'/>\n");
508 if (ctx->cfg.favicon) {
509 html("<link rel='shortcut icon' href='");
510 html_attr(ctx->cfg.favicon);
511 html("'/>\n");
512 }
513 if (host && ctx->repo) {
514 html("<link rel='alternate' title='Atom feed' href='");
515 html(cgit_httpscheme());
516 html_attr(cgit_hosturl());
517 html_attr(cgit_fileurl(ctx->repo->url, "atom", ctx->qry.path,
518 fmt("h=%s", ctx->qry.head)));
519 html("' type='application/atom+xml'/>");
520 }
521 html("</head>\n");
522 html("<body>\n");
523 if (ctx->cfg.header)
524 html_include(ctx->cfg.header);
525}
526
527void cgit_print_docend()
528{
529 html("</div>");
530 if (ctx.cfg.footer)
531 html_include(ctx.cfg.footer);
532 else {
533 htmlf("<div class='footer'>generated by cgit %s at ",
534 cgit_version);
535 cgit_print_date(time(NULL), FMT_LONGDATE, ctx.cfg.local_time);
536 html("</div>\n");
537 }
538 html("</body>\n</html>\n");
539}
540
541int print_branch_option(const char *refname, const unsigned char *sha1,
542 int flags, void *cb_data)
543{
544 char *name = (char *)refname;
545 html_option(name, name, ctx.qry.head);
546 return 0;
547}
548
549int print_archive_ref(const char *refname, const unsigned char *sha1,
550 int flags, void *cb_data)
551{
552 struct tag *tag;
553 struct taginfo *info;
554 struct object *obj;
555 char buf[256], *url;
556 unsigned char fileid[20];
557 int *header = (int *)cb_data;
558
559 if (prefixcmp(refname, "refs/archives"))
560 return 0;
561 strncpy(buf, refname+14, sizeof(buf));
562 obj = parse_object(sha1);
563 if (!obj)
564 return 1;
565 if (obj->type == OBJ_TAG) {
566 tag = lookup_tag(sha1);
567 if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag)))
568 return 0;
569 hashcpy(fileid, tag->tagged->sha1);
570 } else if (obj->type != OBJ_BLOB) {
571 return 0;
572 } else {
573 hashcpy(fileid, sha1);
574 }
575 if (!*header) {
576 html("<h1>download</h1>\n");
577 *header = 1;
578 }
579 url = cgit_pageurl(ctx.qry.repo, "blob",
580 fmt("id=%s&path=%s", sha1_to_hex(fileid),
581 buf));
582 html_link_open(url, NULL, "menu");
583 html_txt(strlpart(buf, 20));
584 html_link_close();
585 return 0;
586}
587
588void cgit_add_hidden_formfields(int incl_head, int incl_search, char *page)
589{
590 char *url;
591
592 if (!ctx.cfg.virtual_root) {
593 url = fmt("%s/%s", ctx.qry.repo, page);
594 if (ctx.qry.path)
595 url = fmt("%s/%s", url, ctx.qry.path);
596 html_hidden("url", url);
597 }
598
599 if (incl_head && ctx.qry.head && ctx.repo->defbranch &&
600 strcmp(ctx.qry.head, ctx.repo->defbranch))
601 html_hidden("h", ctx.qry.head);
602
603 if (ctx.qry.sha1)
604 html_hidden("id", ctx.qry.sha1);
605 if (ctx.qry.sha2)
606 html_hidden("id2", ctx.qry.sha2);
607 if (ctx.qry.showmsg)
608 html_hidden("showmsg", "1");
609
610 if (incl_search) {
611 if (ctx.qry.grep)
612 html_hidden("qt", ctx.qry.grep);
613 if (ctx.qry.search)
614 html_hidden("q", ctx.qry.search);
615 }
616}
617
618const char *fallback_cmd = "repolist";
619
620char *hc(struct cgit_cmd *cmd, const char *page)
621{
622 return (strcmp(cmd ? cmd->name : fallback_cmd, page) ? NULL : "active");
623}
624
625void cgit_print_pageheader(struct cgit_context *ctx)
626{
627 struct cgit_cmd *cmd = cgit_get_cmd(ctx);
628
629 if (!cmd && ctx->repo)
630 fallback_cmd = "summary";
631
632 html("<table id='header'>\n");
633 html("<tr>\n");
634 html("<td class='logo' rowspan='2'><a href='");
635 if (ctx->cfg.logo_link)
636 html_attr(ctx->cfg.logo_link);
637 else
638 html_attr(cgit_rooturl());
639 html("'><img src='");
640 html_attr(ctx->cfg.logo);
641 html("' alt='cgit logo'/></a></td>\n");
642
643 html("<td class='main'>");
644 if (ctx->repo) {
645 cgit_index_link("index", NULL, NULL, NULL, 0);
646 html(" : ");
647 cgit_summary_link(ctx->repo->name, ctx->repo->name, NULL, NULL);
648 html("</td><td class='form'>");
649 html("<form method='get' action=''>\n");
650 cgit_add_hidden_formfields(0, 1, ctx->qry.page);
651 html("<select name='h' onchange='this.form.submit();'>\n");
652 for_each_branch_ref(print_branch_option, ctx->qry.head);
653 html("</select> ");
654 html("<input type='submit' name='' value='switch'/>");
655 html("</form>");
656 } else
657 html_txt(ctx->cfg.root_title);
658 html("</td></tr>\n");
659
660 html("<tr><td class='sub'>");
661 if (ctx->repo) {
662 html_txt(ctx->repo->desc);
663 html("</td><td class='sub right'>");
664 html_txt(ctx->repo->owner);
665 } else {
666 if (ctx->cfg.root_desc)
667 html_txt(ctx->cfg.root_desc);
668 else if (ctx->cfg.index_info)
669 html_include(ctx->cfg.index_info);
670 }
671 html("</td></tr></table>\n");
672
673 html("<table class='tabs'><tr><td>\n");
674 if (ctx->repo) {
675 cgit_summary_link("summary", NULL, hc(cmd, "summary"),
676 ctx->qry.head);
677 cgit_refs_link("refs", NULL, hc(cmd, "refs"), ctx->qry.head,
678 ctx->qry.sha1, NULL);
679 cgit_log_link("log", NULL, hc(cmd, "log"), ctx->qry.head,
680 NULL, NULL, 0, NULL, NULL, ctx->qry.showmsg);
681 cgit_tree_link("tree", NULL, hc(cmd, "tree"), ctx->qry.head,
682 ctx->qry.sha1, NULL);
683 cgit_commit_link("commit", NULL, hc(cmd, "commit"),
684 ctx->qry.head, ctx->qry.sha1);
685 cgit_diff_link("diff", NULL, hc(cmd, "diff"), ctx->qry.head,
686 ctx->qry.sha1, ctx->qry.sha2, NULL);
687 if (ctx->repo->max_stats)
688 cgit_stats_link("stats", NULL, hc(cmd, "stats"),
689 ctx->qry.head, NULL);
690 if (ctx->repo->readme)
691 reporevlink("about", "about", NULL,
692 hc(cmd, "about"), ctx->qry.head, NULL,
693 NULL);
694 html("</td><td class='form'>");
695 html("<form class='right' method='get' action='");
696 if (ctx->cfg.virtual_root)
697 html_url_path(cgit_fileurl(ctx->qry.repo, "log",
698 ctx->qry.path, NULL));
699 html("'>\n");
700 cgit_add_hidden_formfields(1, 0, "log");
701 html("<select name='qt'>\n");
702 html_option("grep", "log msg", ctx->qry.grep);
703 html_option("author", "author", ctx->qry.grep);
704 html_option("committer", "committer", ctx->qry.grep);
705 html("</select>\n");
706 html("<input class='txt' type='text' size='10' name='q' value='");
707 html_attr(ctx->qry.search);
708 html("'/>\n");
709 html("<input type='submit' value='search'/>\n");
710 html("</form>\n");
711 } else {
712 site_link(NULL, "index", NULL, hc(cmd, "repolist"), NULL, 0);
713 if (ctx->cfg.root_readme)
714 site_link("about", "about", NULL, hc(cmd, "about"),
715 NULL, 0);
716 html("</td><td class='form'>");
717 html("<form method='get' action='");
718 html_attr(cgit_rooturl());
719 html("'>\n");
720 html("<input type='text' name='q' size='10' value='");
721 html_attr(ctx->qry.search);
722 html("'/>\n");
723 html("<input type='submit' value='search'/>\n");
724 html("</form>");
725 }
726 html("</td></tr></table>\n");
727 html("<div class='content'>");
728}
729
730void cgit_print_filemode(unsigned short mode)
731{
732 if (S_ISDIR(mode))
733 html("d");
734 else if (S_ISLNK(mode))
735 html("l");
736 else if (S_ISGITLINK(mode))
737 html("m");
738 else
739 html("-");
740 html_fileperm(mode >> 6);
741 html_fileperm(mode >> 3);
742 html_fileperm(mode);
743}
744
745void cgit_print_snapshot_links(const char *repo, const char *head,
746 const char *hex, int snapshots)
747{
748 const struct cgit_snapshot_format* f;
749 char *filename;
750
751 for (f = cgit_snapshot_formats; f->suffix; f++) {
752 if (!(snapshots & f->bit))
753 continue;
754 filename = fmt("%s-%s%s", cgit_repobasename(repo), hex,
755 f->suffix);
756 cgit_snapshot_link(filename, NULL, NULL, NULL, NULL, filename);
757 html("<br/>");
758 }
759}