blob: c1d173836357a017538db1dd7028b265acc04895 [file] [log] [blame]
Lars Hjemli4e9107a2007-07-22 23:42:55 +02001/* ui-tag.c: display a tag
2 *
Lukas Fleischerf7f26f82014-01-08 15:10:49 +01003 * Copyright (C) 2006-2014 cgit Development Team <cgit@lists.zx2c4.com>
Lars Hjemli4e9107a2007-07-22 23:42:55 +02004 *
5 * Licensed under GNU General Public License v2
6 * (see COPYING for full license text)
7 */
8
9#include "cgit.h"
John Keeping8f208792013-04-06 11:37:59 +010010#include "ui-tag.h"
Lars Hjemlib1f9b9c2008-02-23 22:45:33 +010011#include "html.h"
Lars Hjemlia4d1ca12008-03-24 16:50:57 +010012#include "ui-shared.h"
Lars Hjemli4e9107a2007-07-22 23:42:55 +020013
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
Lukas Fleischerbafab422013-03-04 08:52:33 +010034static void print_download_links(char *revname)
Alexey Nezhdanov8cdccac2009-09-27 23:00:29 +040035{
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
Lars Hjemli4e9107a2007-07-22 23:42:55 +020042void cgit_print_tag(char *revname)
43{
John Keepingfb3655d2013-04-06 10:28:57 +010044 struct strbuf fullref = STRBUF_INIT;
Lars Hjemli4e9107a2007-07-22 23:42:55 +020045 unsigned char sha1[20];
46 struct object *obj;
47 struct tag *tag;
48 struct taginfo *info;
49
Lars Hjemli8a631b12009-08-17 09:19:05 +020050 if (!revname)
51 revname = ctx.qry.head;
52
John Keepingfb3655d2013-04-06 10:28:57 +010053 strbuf_addf(&fullref, "refs/tags/%s", revname);
54 if (get_sha1(fullref.buf, sha1)) {
John Keepinged5bd302013-04-06 11:23:52 +010055 cgit_print_error("Bad tag reference: %s", revname);
John Keepingfb3655d2013-04-06 10:28:57 +010056 goto cleanup;
Lars Hjemli4e9107a2007-07-22 23:42:55 +020057 }
58 obj = parse_object(sha1);
59 if (!obj) {
John Keepinged5bd302013-04-06 11:23:52 +010060 cgit_print_error("Bad object id: %s", sha1_to_hex(sha1));
John Keepingfb3655d2013-04-06 10:28:57 +010061 goto cleanup;
Lars Hjemli4e9107a2007-07-22 23:42:55 +020062 }
63 if (obj->type == OBJ_TAG) {
64 tag = lookup_tag(sha1);
65 if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) {
John Keepinged5bd302013-04-06 11:23:52 +010066 cgit_print_error("Bad tag object: %s", revname);
John Keepingfb3655d2013-04-06 10:28:57 +010067 goto cleanup;
Lars Hjemli4e9107a2007-07-22 23:42:55 +020068 }
69 html("<table class='commit-info'>\n");
Lars Hjemli322a4bc2009-10-06 20:33:04 +020070 htmlf("<tr><td>tag name</td><td>");
Lars Hjemli720b6ec2009-01-11 16:37:47 +010071 html_txt(revname);
72 htmlf(" (%s)</td></tr>\n", sha1_to_hex(sha1));
Lars Hjemli4e9107a2007-07-22 23:42:55 +020073 if (info->tagger_date > 0) {
Lars Hjemli322a4bc2009-10-06 20:33:04 +020074 html("<tr><td>tag date</td><td>");
Stefan Naewe0f0ab142008-08-01 14:54:38 +020075 cgit_print_date(info->tagger_date, FMT_LONGDATE, ctx.cfg.local_time);
Lars Hjemli43291e42007-07-23 01:42:49 +020076 html("</td></tr>\n");
Lars Hjemli4e9107a2007-07-22 23:42:55 +020077 }
78 if (info->tagger) {
Lars Hjemli322a4bc2009-10-06 20:33:04 +020079 html("<tr><td>tagged by</td><td>");
Jason A. Donenfeld786609b2014-01-13 16:24:40 +010080 cgit_open_filter(ctx.repo->email_filter, info->tagger_email, "tag");
Lars Hjemli4e9107a2007-07-22 23:42:55 +020081 html_txt(info->tagger);
Martin Szulecki2f56e392009-08-07 14:05:17 +020082 if (info->tagger_email && !ctx.cfg.noplainemail) {
Lars Hjemlia608ff72008-09-15 22:40:02 +020083 html(" ");
84 html_txt(info->tagger_email);
85 }
Jason A. Donenfelda5e15532014-01-13 04:04:52 +010086 cgit_close_filter(ctx.repo->email_filter);
Lars Hjemli4e9107a2007-07-22 23:42:55 +020087 html("</td></tr>\n");
88 }
Lars Hjemli322a4bc2009-10-06 20:33:04 +020089 html("<tr><td>tagged object</td><td class='sha1'>");
Lars Hjemli4e9107a2007-07-22 23:42:55 +020090 cgit_object_link(tag->tagged);
91 html("</td></tr>\n");
Alexey Nezhdanov8cdccac2009-09-27 23:00:29 +040092 if (ctx.repo->snapshots)
93 print_download_links(revname);
Lars Hjemli4e9107a2007-07-22 23:42:55 +020094 html("</table>\n");
95 print_tag_content(info->msg);
Robin Redeker372b4042009-01-11 16:25:01 +010096 } else {
97 html("<table class='commit-info'>\n");
Lars Hjemli322a4bc2009-10-06 20:33:04 +020098 htmlf("<tr><td>tag name</td><td>");
Robin Redeker372b4042009-01-11 16:25:01 +010099 html_txt(revname);
100 html("</td></tr>\n");
Lars Hjemli322a4bc2009-10-06 20:33:04 +0200101 html("<tr><td>Tagged object</td><td class='sha1'>");
Robin Redeker372b4042009-01-11 16:25:01 +0100102 cgit_object_link(obj);
103 html("</td></tr>\n");
Alexey Nezhdanov8cdccac2009-09-27 23:00:29 +0400104 if (ctx.repo->snapshots)
105 print_download_links(revname);
Robin Redeker372b4042009-01-11 16:25:01 +0100106 html("</table>\n");
Lukas Fleischer53bc7472013-03-03 16:04:29 +0100107 }
John Keepingfb3655d2013-04-06 10:28:57 +0100108
109cleanup:
110 strbuf_release(&fullref);
Lars Hjemli4e9107a2007-07-22 23:42:55 +0200111}