all repos — cgit @ ef3108656b9c6e22604c18bd9d05bdc847d81e87

a hyperfast web frontend for git written in c

ui-tag.c (view raw)

  1/* ui-tag.c: display a tag
  2 *
  3 * Copyright (C) 2006-2014 cgit Development Team <cgit@lists.zx2c4.com>
  4 *
  5 * Licensed under GNU General Public License v2
  6 *   (see COPYING for full license text)
  7 */
  8
  9#include "cgit.h"
 10#include "ui-tag.h"
 11#include "html.h"
 12#include "ui-shared.h"
 13
 14static void print_tag_content(char *buf)
 15{
 16	char *p;
 17
 18	if (!buf)
 19		return;
 20
 21	html("<div class='commit-subject'>");
 22	p = strchr(buf, '\n');
 23	if (p)
 24		*p = '\0';
 25	html_txt(buf);
 26	html("</div>");
 27	if (p) {
 28		html("<div class='commit-msg'>");
 29		html_txt(++p);
 30		html("</div>");
 31	}
 32}
 33
 34static void print_download_links(char *revname)
 35{
 36	html("<tr><th>download</th><td class='sha1'>");
 37	cgit_print_snapshot_links(ctx.qry.repo, ctx.qry.head,
 38				  revname, ctx.repo->snapshots);
 39	html("</td></tr>");
 40}
 41
 42void cgit_print_tag(char *revname)
 43{
 44	struct strbuf fullref = STRBUF_INIT;
 45	unsigned char sha1[20];
 46	struct object *obj;
 47
 48	if (!revname)
 49		revname = ctx.qry.head;
 50
 51	strbuf_addf(&fullref, "refs/tags/%s", revname);
 52	if (get_sha1(fullref.buf, sha1)) {
 53		cgit_print_error_page(404, "Not found",
 54			"Bad tag reference: %s", revname);
 55		goto cleanup;
 56	}
 57	obj = parse_object(sha1);
 58	if (!obj) {
 59		cgit_print_error_page(500, "Internal server error",
 60			"Bad object id: %s", sha1_to_hex(sha1));
 61		goto cleanup;
 62	}
 63	if (obj->type == OBJ_TAG) {
 64		struct tag *tag;
 65		struct taginfo *info;
 66
 67		tag = lookup_tag(sha1);
 68		if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) {
 69			cgit_print_error_page(500, "Internal server error",
 70				"Bad tag object: %s", revname);
 71			goto cleanup;
 72		}
 73		cgit_print_layout_start();
 74		html("<table class='commit-info'>\n");
 75		htmlf("<tr><td>tag name</td><td>");
 76		html_txt(revname);
 77		htmlf(" (%s)</td></tr>\n", sha1_to_hex(sha1));
 78		if (info->tagger_date > 0) {
 79			html("<tr><td>tag date</td><td>");
 80			html_txt(show_date(info->tagger_date, info->tagger_tz,
 81						cgit_date_mode(DATE_ISO8601)));
 82			html("</td></tr>\n");
 83		}
 84		if (info->tagger) {
 85			html("<tr><td>tagged by</td><td>");
 86			cgit_open_filter(ctx.repo->email_filter, info->tagger_email, "tag");
 87			html_txt(info->tagger);
 88			if (info->tagger_email && !ctx.cfg.noplainemail) {
 89				html(" ");
 90				html_txt(info->tagger_email);
 91			}
 92			cgit_close_filter(ctx.repo->email_filter);
 93			html("</td></tr>\n");
 94		}
 95		html("<tr><td>tagged object</td><td class='sha1'>");
 96		cgit_object_link(tag->tagged);
 97		html("</td></tr>\n");
 98		if (ctx.repo->snapshots)
 99			print_download_links(revname);
100		html("</table>\n");
101		print_tag_content(info->msg);
102		cgit_print_layout_end();
103		cgit_free_taginfo(info);
104	} else {
105		cgit_print_layout_start();
106		html("<table class='commit-info'>\n");
107		htmlf("<tr><td>tag name</td><td>");
108		html_txt(revname);
109		html("</td></tr>\n");
110		html("<tr><td>Tagged object</td><td class='sha1'>");
111		cgit_object_link(obj);
112		html("</td></tr>\n");
113		if (ctx.repo->snapshots)
114			print_download_links(revname);
115		html("</table>\n");
116		cgit_print_layout_end();
117	}
118
119cleanup:
120	strbuf_release(&fullref);
121}