summaryrefslogtreecommitdiff
path: root/ui_70-tag.c
blob: 0a1b3863b150af7c68d98aadadd30a65f9e06457 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/* ui-tag.c: display a tag
 *
 * Copyright (C) 2006-2014 cgit Development Team <cgit@lists.zx2c4.com>
 *
 * Licensed under GNU General Public License v2
 *   (see COPYING for full license text)
 */

#include "cgit.h"
#include "ui-tag.h"
#include "html.h"
#include "ui_70-shared.h"

static void print_tag_content(char *buf)
{
	char *p;

	if (!buf)
		return;

	p = strchr(buf, '\n');
	if (p)
		*p = '\0';
	cgit_gopher_start_selector(GOPHER_INFO);
	cgit_gopher_text(buf);
	cgit_gopher_tab();
	cgit_gopher_selector_link("Err");
	cgit_gopher_end_selector();
	if (p) {
		cgit_gopher_start_selector(GOPHER_INFO);
		cgit_gopher_text(++p);
		cgit_gopher_tab();
		cgit_gopher_selector_link("Err");
		cgit_gopher_end_selector();
	}
}

static void print_download_links(char *revname)
{
	html("<tr><th>download</th><td class='sha1'>");
	cgit_print_snapshot_links(ctx.repo, revname, "<br/>");
	html("</td></tr>");
}

void cgit_print_tag(char *revname)
{
	struct strbuf fullref = STRBUF_INIT;
	struct object_id oid;
	struct object *obj;

	if (!revname)
		revname = ctx.qry.head;

	strbuf_addf(&fullref, "refs/tags/%s", revname);
	if (get_oid(fullref.buf, &oid)) {
		cgit_gopher_error("Bad tag reference");
		goto cleanup;
	}
	obj = parse_object(&oid);
	if (!obj) {
		cgit_gopher_error("Bad object id");
		goto cleanup;
	}
	if (obj->type == OBJ_TAG) {
		struct tag *tag;
		struct taginfo *info;

		tag = lookup_tag(&oid);
		if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) {
			cgit_gopher_error("Bad tag object");
			goto cleanup;
		}
		cgit_print_layout_start();
		cgit_gopher_start_selector(GOPHER_INFO);
		cgit_gopher_text_pad("tag name", GOPHER_SUMMARY_NAME_LEN);
		cgit_gopher_text(revname);
		gopherf(" (%s)", oid_to_hex(&oid));
		cgit_gopher_tab();
		cgit_gopher_selector_link("Err");
		cgit_gopher_end_selector();
		if (info->tagger_date > 0) {
			cgit_gopher_start_selector(GOPHER_INFO);
			cgit_gopher_text_pad("tag date", GOPHER_SUMMARY_NAME_LEN);
			cgit_gopher_text(show_date(info->tagger_date, info->tagger_tz,
						cgit_date_mode(DATE_ISO8601)));
			cgit_gopher_tab();
			cgit_gopher_selector_link("Err");
			cgit_gopher_end_selector();
		}
		if (info->tagger) {
			cgit_gopher_start_selector(GOPHER_INFO);
			cgit_gopher_text_pad("tagged by", GOPHER_SUMMARY_NAME_LEN);
			cgit_gopher_text(info->tagger);
			if (info->tagger_email && !ctx.cfg.noplainemail) {
				cgit_gopher_text(" ");
				cgit_gopher_text(info->tagger_email);
			}
			cgit_gopher_tab();
			cgit_gopher_selector_link("Err");
			cgit_gopher_end_selector();
		}
		cgit_gopher_start_selector(GOPHER_MENU);
		cgit_gopher_text_pad("tagged object", GOPHER_SUMMARY_NAME_LEN);
		cgit_gopher_text(oid_to_hex(&tag->tagged->oid));
		cgit_gopher_tab();
		cgit_object_link(tag->tagged);
		cgit_gopher_end_selector();	
		print_tag_content(info->msg);
		cgit_print_layout_end();
		cgit_free_taginfo(info);
	} else {
		cgit_print_layout_start();
		cgit_gopher_start_selector(GOPHER_INFO);
		cgit_gopher_text_pad("tag name", GOPHER_SUMMARY_NAME_LEN);
		cgit_gopher_text(revname);
		cgit_gopher_tab();
		cgit_gopher_selector_link("Err");
		cgit_gopher_end_selector();
		
		cgit_gopher_start_selector(GOPHER_MENU);
		cgit_gopher_text_pad("tagged object", GOPHER_SUMMARY_NAME_LEN);
		cgit_gopher_text(oid_to_hex(&obj->oid));
		cgit_gopher_tab();
		cgit_object_link(obj);
		cgit_gopher_end_selector();	
		cgit_print_layout_end();
	}

cleanup:
	strbuf_release(&fullref);
}