]> gitweb.ps.run Git - ps-cgit/blob - ui-tag.c
tag: move layout into page function
[ps-cgit] / ui-tag.c
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
14 static 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
34 static 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
42 void cgit_print_tag(char *revname)
43 {
44         struct strbuf fullref = STRBUF_INIT;
45         unsigned char sha1[20];
46         struct object *obj;
47         struct tag *tag;
48         struct taginfo *info;
49
50         if (!revname)
51                 revname = ctx.qry.head;
52
53         strbuf_addf(&fullref, "refs/tags/%s", revname);
54         if (get_sha1(fullref.buf, sha1)) {
55                 cgit_print_error_page(404, "Not found",
56                         "Bad tag reference: %s", revname);
57                 goto cleanup;
58         }
59         obj = parse_object(sha1);
60         if (!obj) {
61                 cgit_print_error_page(500, "Internal server error",
62                         "Bad object id: %s", sha1_to_hex(sha1));
63                 goto cleanup;
64         }
65         if (obj->type == OBJ_TAG) {
66                 tag = lookup_tag(sha1);
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", sha1_to_hex(sha1));
77                 if (info->tagger_date > 0) {
78                         html("<tr><td>tag date</td><td>");
79                         cgit_print_date(info->tagger_date, FMT_LONGDATE, ctx.cfg.local_time);
80                         html("</td></tr>\n");
81                 }
82                 if (info->tagger) {
83                         html("<tr><td>tagged by</td><td>");
84                         cgit_open_filter(ctx.repo->email_filter, info->tagger_email, "tag");
85                         html_txt(info->tagger);
86                         if (info->tagger_email && !ctx.cfg.noplainemail) {
87                                 html(" ");
88                                 html_txt(info->tagger_email);
89                         }
90                         cgit_close_filter(ctx.repo->email_filter);
91                         html("</td></tr>\n");
92                 }
93                 html("<tr><td>tagged object</td><td class='sha1'>");
94                 cgit_object_link(tag->tagged);
95                 html("</td></tr>\n");
96                 if (ctx.repo->snapshots)
97                         print_download_links(revname);
98                 html("</table>\n");
99                 print_tag_content(info->msg);
100                 cgit_print_layout_end();
101         } else {
102                 cgit_print_layout_start();
103                 html("<table class='commit-info'>\n");
104                 htmlf("<tr><td>tag name</td><td>");
105                 html_txt(revname);
106                 html("</td></tr>\n");
107                 html("<tr><td>Tagged object</td><td class='sha1'>");
108                 cgit_object_link(obj);
109                 html("</td></tr>\n");
110                 if (ctx.repo->snapshots)
111                         print_download_links(revname);
112                 html("</table>\n");
113                 cgit_print_layout_end();
114         }
115
116 cleanup:
117         strbuf_release(&fullref);
118 }