all repos — cgit @ c4d23d02ec5a26d09d389dcf7b8928ecd5798ccc

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.repo, revname, "<br/>");
 38	html("</td></tr>");
 39}
 40
 41void cgit_print_tag(char *revname)
 42{
 43	struct strbuf fullref = STRBUF_INIT;
 44	struct object_id oid;
 45	struct object *obj;
 46
 47	if (!revname)
 48		revname = ctx.qry.head;
 49
 50	strbuf_addf(&fullref, "refs/tags/%s", revname);
 51	if (get_oid(fullref.buf, &oid)) {
 52		cgit_print_error_page(404, "Not found",
 53			"Bad tag reference: %s", revname);
 54		goto cleanup;
 55	}
 56	obj = parse_object(&oid);
 57	if (!obj) {
 58		cgit_print_error_page(500, "Internal server error",
 59			"Bad object id: %s", oid_to_hex(&oid));
 60		goto cleanup;
 61	}
 62	if (obj->type == OBJ_TAG) {
 63		struct tag *tag;
 64		struct taginfo *info;
 65
 66		tag = lookup_tag(&oid);
 67		if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) {
 68			cgit_print_error_page(500, "Internal server error",
 69				"Bad tag object: %s", revname);
 70			goto cleanup;
 71		}
 72		cgit_print_layout_start();
 73		html("<table class='commit-info'>\n");
 74		htmlf("<tr><td>tag name</td><td>");
 75		html_txt(revname);
 76		htmlf(" (%s)</td></tr>\n", oid_to_hex(&oid));
 77		if (info->tagger_date > 0) {
 78			html("<tr><td>tag date</td><td>");
 79			html_txt(show_date(info->tagger_date, info->tagger_tz,
 80						cgit_date_mode(DATE_ISO8601)));
 81			html("</td></tr>\n");
 82		}
 83		if (info->tagger) {
 84			html("<tr><td>tagged by</td><td>");
 85			cgit_open_filter(ctx.repo->email_filter, info->tagger_email, "tag");
 86			html_txt(info->tagger);
 87			if (info->tagger_email && !ctx.cfg.noplainemail) {
 88				html(" ");
 89				html_txt(info->tagger_email);
 90			}
 91			cgit_close_filter(ctx.repo->email_filter);
 92			html("</td></tr>\n");
 93		}
 94		html("<tr><td>tagged object</td><td class='sha1'>");
 95		cgit_object_link(tag->tagged);
 96		html("</td></tr>\n");
 97		if (ctx.repo->snapshots)
 98			print_download_links(revname);
 99		html("</table>\n");
100		print_tag_content(info->msg);
101		cgit_print_layout_end();
102		cgit_free_taginfo(info);
103	} else {
104		cgit_print_layout_start();
105		html("<table class='commit-info'>\n");
106		htmlf("<tr><td>tag name</td><td>");
107		html_txt(revname);
108		html("</td></tr>\n");
109		html("<tr><td>tagged object</td><td class='sha1'>");
110		cgit_object_link(obj);
111		html("</td></tr>\n");
112		if (ctx.repo->snapshots)
113			print_download_links(revname);
114		html("</table>\n");
115		cgit_print_layout_end();
116	}
117
118cleanup:
119	strbuf_release(&fullref);
120}