all repos — cgit @ 87a89aed41136d388537b146000c4af6c1135a8c

a hyperfast web frontend for git written in c

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 = "&amp;";
245	}
246	if (head && strcmp(head, ctx.repo->defbranch)) {
247		html(delim);
248		html("h=");
249		html_url_arg(head);
250		delim = "&amp;";
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 = "&amp;";
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	if (ctx->page.mimetype && ctx->page.charset)
471		htmlf("Content-Type: %s; charset=%s\n", ctx->page.mimetype,
472		      ctx->page.charset);
473	else if (ctx->page.mimetype)
474		htmlf("Content-Type: %s\n", ctx->page.mimetype);
475	if (ctx->page.size)
476		htmlf("Content-Length: %ld\n", ctx->page.size);
477	if (ctx->page.filename)
478		htmlf("Content-Disposition: inline; filename=\"%s\"\n",
479		      ctx->page.filename);
480	htmlf("Last-Modified: %s\n", http_date(ctx->page.modified));
481	htmlf("Expires: %s\n", http_date(ctx->page.expires));
482	html("\n");
483}
484
485void cgit_print_docstart(struct cgit_context *ctx)
486{
487	char *host = cgit_hosturl();
488	html(cgit_doctype);
489	html("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n");
490	html("<head>\n");
491	html("<title>");
492	html_txt(ctx->page.title);
493	html("</title>\n");
494	htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version);
495	if (ctx->cfg.robots && *ctx->cfg.robots)
496		htmlf("<meta name='robots' content='%s'/>\n", ctx->cfg.robots);
497	html("<link rel='stylesheet' type='text/css' href='");
498	html_attr(ctx->cfg.css);
499	html("'/>\n");
500	if (ctx->cfg.favicon) {
501		html("<link rel='shortcut icon' href='");
502		html_attr(ctx->cfg.favicon);
503		html("'/>\n");
504	}
505	if (host && ctx->repo) {
506		html("<link rel='alternate' title='Atom feed' href='http://");
507		html_attr(cgit_hosturl());
508		html_attr(cgit_fileurl(ctx->repo->url, "atom", ctx->qry.path,
509				       fmt("h=%s", ctx->qry.head)));
510		html("' type='application/atom+xml'/>");
511	}
512	html("</head>\n");
513	html("<body>\n");
514	if (ctx->cfg.header)
515		html_include(ctx->cfg.header);
516}
517
518void cgit_print_docend()
519{
520	html("</div>");
521	if (ctx.cfg.footer)
522		html_include(ctx.cfg.footer);
523	else {
524		htmlf("<div class='footer'>generated  by cgit %s at ",
525			cgit_version);
526		cgit_print_date(time(NULL), FMT_LONGDATE, ctx.cfg.local_time);
527		html("</div>\n");
528	}
529	html("</body>\n</html>\n");
530}
531
532int print_branch_option(const char *refname, const unsigned char *sha1,
533			int flags, void *cb_data)
534{
535	char *name = (char *)refname;
536	html_option(name, name, ctx.qry.head);
537	return 0;
538}
539
540int print_archive_ref(const char *refname, const unsigned char *sha1,
541		       int flags, void *cb_data)
542{
543	struct tag *tag;
544	struct taginfo *info;
545	struct object *obj;
546	char buf[256], *url;
547	unsigned char fileid[20];
548	int *header = (int *)cb_data;
549
550	if (prefixcmp(refname, "refs/archives"))
551		return 0;
552	strncpy(buf, refname+14, sizeof(buf));
553	obj = parse_object(sha1);
554	if (!obj)
555		return 1;
556	if (obj->type == OBJ_TAG) {
557		tag = lookup_tag(sha1);
558		if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag)))
559			return 0;
560		hashcpy(fileid, tag->tagged->sha1);
561	} else if (obj->type != OBJ_BLOB) {
562		return 0;
563	} else {
564		hashcpy(fileid, sha1);
565	}
566	if (!*header) {
567		html("<h1>download</h1>\n");
568		*header = 1;
569	}
570	url = cgit_pageurl(ctx.qry.repo, "blob",
571			   fmt("id=%s&amp;path=%s", sha1_to_hex(fileid),
572			       buf));
573	html_link_open(url, NULL, "menu");
574	html_txt(strlpart(buf, 20));
575	html_link_close();
576	return 0;
577}
578
579void cgit_add_hidden_formfields(int incl_head, int incl_search, char *page)
580{
581	char *url;
582
583	if (!ctx.cfg.virtual_root) {
584		url = fmt("%s/%s", ctx.qry.repo, page);
585		if (ctx.qry.path)
586			url = fmt("%s/%s", url, ctx.qry.path);
587		html_hidden("url", url);
588	}
589
590	if (incl_head && ctx.qry.head && ctx.repo->defbranch &&
591	    strcmp(ctx.qry.head, ctx.repo->defbranch))
592		html_hidden("h", ctx.qry.head);
593
594	if (ctx.qry.sha1)
595		html_hidden("id", ctx.qry.sha1);
596	if (ctx.qry.sha2)
597		html_hidden("id2", ctx.qry.sha2);
598	if (ctx.qry.showmsg)
599		html_hidden("showmsg", "1");
600
601	if (incl_search) {
602		if (ctx.qry.grep)
603			html_hidden("qt", ctx.qry.grep);
604		if (ctx.qry.search)
605			html_hidden("q", ctx.qry.search);
606	}
607}
608
609const char *fallback_cmd = "repolist";
610
611char *hc(struct cgit_cmd *cmd, const char *page)
612{
613	return (strcmp(cmd ? cmd->name : fallback_cmd, page) ? NULL : "active");
614}
615
616void cgit_print_pageheader(struct cgit_context *ctx)
617{
618	struct cgit_cmd *cmd = cgit_get_cmd(ctx);
619
620	if (!cmd && ctx->repo)
621		fallback_cmd = "summary";
622
623	html("<table id='header'>\n");
624	html("<tr>\n");
625	html("<td class='logo' rowspan='2'><a href='");
626	if (ctx->cfg.logo_link)
627		html_attr(ctx->cfg.logo_link);
628	else
629		html_attr(cgit_rooturl());
630	html("'><img src='");
631	html_attr(ctx->cfg.logo);
632	html("' alt='cgit logo'/></a></td>\n");
633
634	html("<td class='main'>");
635	if (ctx->repo) {
636		cgit_index_link("index", NULL, NULL, NULL, 0);
637		html(" : ");
638		cgit_summary_link(ctx->repo->name, ctx->repo->name, NULL, NULL);
639		html("</td><td class='form'>");
640		html("<form method='get' action=''>\n");
641		cgit_add_hidden_formfields(0, 1, ctx->qry.page);
642		html("<select name='h' onchange='this.form.submit();'>\n");
643		for_each_branch_ref(print_branch_option, ctx->qry.head);
644		html("</select> ");
645		html("<input type='submit' name='' value='switch'/>");
646		html("</form>");
647	} else
648		html_txt(ctx->cfg.root_title);
649	html("</td></tr>\n");
650
651	html("<tr><td class='sub'>");
652	if (ctx->repo) {
653		html_txt(ctx->repo->desc);
654		html("</td><td class='sub right'>");
655		html_txt(ctx->repo->owner);
656	} else {
657		if (ctx->cfg.root_desc)
658			html_txt(ctx->cfg.root_desc);
659		else if (ctx->cfg.index_info)
660			html_include(ctx->cfg.index_info);
661	}
662	html("</td></tr></table>\n");
663
664	html("<table class='tabs'><tr><td>\n");
665	if (ctx->repo) {
666		cgit_summary_link("summary", NULL, hc(cmd, "summary"),
667				  ctx->qry.head);
668		cgit_refs_link("refs", NULL, hc(cmd, "refs"), ctx->qry.head,
669			       ctx->qry.sha1, NULL);
670		cgit_log_link("log", NULL, hc(cmd, "log"), ctx->qry.head,
671			      NULL, NULL, 0, NULL, NULL, ctx->qry.showmsg);
672		cgit_tree_link("tree", NULL, hc(cmd, "tree"), ctx->qry.head,
673			       ctx->qry.sha1, NULL);
674		cgit_commit_link("commit", NULL, hc(cmd, "commit"),
675				 ctx->qry.head, ctx->qry.sha1);
676		cgit_diff_link("diff", NULL, hc(cmd, "diff"), ctx->qry.head,
677			       ctx->qry.sha1, ctx->qry.sha2, NULL);
678		if (ctx->repo->max_stats)
679			cgit_stats_link("stats", NULL, hc(cmd, "stats"),
680					ctx->qry.head, NULL);
681		if (ctx->repo->readme)
682			reporevlink("about", "about", NULL,
683				    hc(cmd, "about"), ctx->qry.head, NULL,
684				    NULL);
685		html("</td><td class='form'>");
686		html("<form class='right' method='get' action='");
687		if (ctx->cfg.virtual_root)
688			html_url_path(cgit_fileurl(ctx->qry.repo, "log",
689						   ctx->qry.path, NULL));
690		html("'>\n");
691		cgit_add_hidden_formfields(1, 0, "log");
692		html("<select name='qt'>\n");
693		html_option("grep", "log msg", ctx->qry.grep);
694		html_option("author", "author", ctx->qry.grep);
695		html_option("committer", "committer", ctx->qry.grep);
696		html("</select>\n");
697		html("<input class='txt' type='text' size='10' name='q' value='");
698		html_attr(ctx->qry.search);
699		html("'/>\n");
700		html("<input type='submit' value='search'/>\n");
701		html("</form>\n");
702	} else {
703		site_link(NULL, "index", NULL, hc(cmd, "repolist"), NULL, 0);
704		if (ctx->cfg.root_readme)
705			site_link("about", "about", NULL, hc(cmd, "about"),
706				  NULL, 0);
707		html("</td><td class='form'>");
708		html("<form method='get' action='");
709		html_attr(cgit_rooturl());
710		html("'>\n");
711		html("<input type='text' name='q' size='10' value='");
712		html_attr(ctx->qry.search);
713		html("'/>\n");
714		html("<input type='submit' value='search'/>\n");
715		html("</form>");
716	}
717	html("</td></tr></table>\n");
718	html("<div class='content'>");
719}
720
721void cgit_print_filemode(unsigned short mode)
722{
723	if (S_ISDIR(mode))
724		html("d");
725	else if (S_ISLNK(mode))
726		html("l");
727	else if (S_ISGITLINK(mode))
728		html("m");
729	else
730		html("-");
731	html_fileperm(mode >> 6);
732	html_fileperm(mode >> 3);
733	html_fileperm(mode);
734}
735
736void cgit_print_snapshot_links(const char *repo, const char *head,
737			       const char *hex, int snapshots)
738{
739	const struct cgit_snapshot_format* f;
740    	char *filename;
741
742	for (f = cgit_snapshot_formats; f->suffix; f++) {
743		if (!(snapshots & f->bit))
744			continue;
745		filename = fmt("%s-%s%s", cgit_repobasename(repo), hex,
746			       f->suffix);
747		cgit_snapshot_link(filename, NULL, NULL, NULL, NULL, filename);
748		html("<br/>");
749	}
750}