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