diff options
context:
space:
mode:
authorBryce Kwon <bryce@brycekwon.com>
committerBryce Kwon <bryce@brycekwon.com>
commit
parent
tree
download
Restyle the sources and fix the audit's findings
Diffstat (limited to 'source/ui-tag.c')
-rw-r--r--source/ui-tag.c174
1 file changed, 99 insertions, 75 deletions
diff --git a/source/ui-tag.c b/source/ui-tag.c
index 7d01c5a..d09ff2b 100644
--- a/source/ui-tag.c
+++ b/source/ui-tag.c
@@ -1,43 +1,118 @@
-/* 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 LICENSE.txt for full license text)
+/*
+ * The tag page, which shows a single ref under refs/tags and is where the
+ * branch and tag listings link. An annotated tag is a git object in its own
+ * right, so its page carries the tagger, the date and the message, while a
+ * lightweight tag is only a name for a commit and gets a shorter table. Both
+ * forms link the object the tag points at and, when the repository enables
+ * snapshots, offer the tree at that tag for download as an archive.
*/
#define USE_THE_REPOSITORY_VARIABLE
#include "cgit.h"
-#include "ui-tag.h"
+#include "filter.h"
#include "html.h"
+#include "parsing.h"
+#include "shared.h"
#include "ui-shared.h"
+#include "ui-tag.h"
+
+static void print_object_row(struct object *obj)
+{
+ html("<tr><td>tagged object</td><td class='oid'>");
+ cgit_object_link(obj);
+ html("</td></tr>\n");
+}
+
+static void print_download_row(const char *revname)
+{
+ html("<tr><th>download</th><td class='oid'>");
+ cgit_print_snapshot_links(ctx.repo, revname, "<br/>");
+ html("</td></tr>");
+}
-static void print_tag_content(char *buf)
+/*
+ * Cutting the subject out terminates the message in place, which is safe only
+ * because the caller frees it straight after.
+ */
+static void print_message(char *msg)
{
- char *p;
+ char *newline;
- if (!buf)
+ if (!msg)
return;
html("<div class='commit-subject'>");
- p = strchr(buf, '\n');
- if (p)
- *p = '\0';
- html_txt(buf);
+ newline = strchr(msg, '\n');
+ if (newline)
+ *newline = '\0';
+ html_txt(msg);
html("</div>");
- if (p) {
+ if (newline) {
html("<div class='commit-msg'>");
- html_txt(++p);
+ html_txt(newline + 1);
html("</div>");
}
}
-static void print_download_links(char *revname)
+static void print_annotated_tag(const char *revname,
+ const struct object_id *oid)
{
- html("<tr><th>download</th><td class='oid'>");
- cgit_print_snapshot_links(ctx.repo, revname, "<br/>");
- html("</td></tr>");
+ struct tag *tag;
+ struct taginfo *info;
+
+ tag = lookup_tag(the_repository, oid);
+ if (!tag || parse_tag(the_repository, tag) ||
+ !(info = cgit_parse_tag(tag))) {
+ cgit_print_error_page(500, "Internal server error",
+ "Bad tag object: %s", revname);
+ return;
+ }
+
+ cgit_print_layout_start();
+ html("<table class='commit-info'>\n");
+ html("<tr><td>tag name</td><td>");
+ html_txt(revname);
+ htmlf(" (%s)</td></tr>\n", oid_to_hex(oid));
+ if (info->tagger_date > 0) {
+ html("<tr><td>tag date</td><td>");
+ html_txt(show_date(info->tagger_date, info->tagger_tz,
+ cgit_date_mode(DATE_ISO8601)));
+ html("</td></tr>\n");
+ }
+ if (info->tagger) {
+ html("<tr><td>tagged by</td><td>");
+ cgit_open_filter(ctx.repo->email_filter, info->tagger_email,
+ "tag");
+ html_txt(info->tagger);
+ if (info->tagger_email && !ctx.cfg.noplainemail) {
+ html(" ");
+ html_txt(info->tagger_email);
+ }
+ cgit_close_filter(ctx.repo->email_filter);
+ html("</td></tr>\n");
+ }
+ print_object_row(tag->tagged);
+ if (ctx.repo->snapshots)
+ print_download_row(revname);
+ html("</table>\n");
+ print_message(info->msg);
+ cgit_print_layout_end();
+ cgit_free_taginfo(info);
+}
+
+static void print_lightweight_tag(const char *revname, struct object *obj)
+{
+ cgit_print_layout_start();
+ html("<table class='commit-info'>\n");
+ html("<tr><td>tag name</td><td>");
+ html_txt(revname);
+ html("</td></tr>\n");
+ print_object_row(obj);
+ if (ctx.repo->snapshots)
+ print_download_row(revname);
+ html("</table>\n");
+ cgit_print_layout_end();
}
void cgit_print_tag(char *revname)
@@ -61,61 +136,10 @@ void cgit_print_tag(char *revname)
"Bad object id: %s", oid_to_hex(&oid));
goto cleanup;
}
- if (obj->type == OBJ_TAG) {
- struct tag *tag;
- struct taginfo *info;
-
- tag = lookup_tag(the_repository, &oid);
- if (!tag || parse_tag(the_repository, tag) || !(info = cgit_parse_tag(tag))) {
- cgit_print_error_page(500, "Internal server error",
- "Bad tag object: %s", revname);
- goto cleanup;
- }
- cgit_print_layout_start();
- html("<table class='commit-info'>\n");
- html("<tr><td>tag name</td><td>");
- html_txt(revname);
- htmlf(" (%s)</td></tr>\n", oid_to_hex(&oid));
- if (info->tagger_date > 0) {
- html("<tr><td>tag date</td><td>");
- html_txt(show_date(info->tagger_date, info->tagger_tz,
- cgit_date_mode(DATE_ISO8601)));
- html("</td></tr>\n");
- }
- if (info->tagger) {
- html("<tr><td>tagged by</td><td>");
- cgit_open_filter(ctx.repo->email_filter, info->tagger_email, "tag");
- html_txt(info->tagger);
- if (info->tagger_email && !ctx.cfg.noplainemail) {
- html(" ");
- html_txt(info->tagger_email);
- }
- cgit_close_filter(ctx.repo->email_filter);
- html("</td></tr>\n");
- }
- html("<tr><td>tagged object</td><td class='oid'>");
- cgit_object_link(tag->tagged);
- html("</td></tr>\n");
- if (ctx.repo->snapshots)
- print_download_links(revname);
- html("</table>\n");
- print_tag_content(info->msg);
- cgit_print_layout_end();
- cgit_free_taginfo(info);
- } else {
- cgit_print_layout_start();
- html("<table class='commit-info'>\n");
- html("<tr><td>tag name</td><td>");
- html_txt(revname);
- html("</td></tr>\n");
- html("<tr><td>tagged object</td><td class='oid'>");
- cgit_object_link(obj);
- html("</td></tr>\n");
- if (ctx.repo->snapshots)
- print_download_links(revname);
- html("</table>\n");
- cgit_print_layout_end();
- }
+ if (obj->type == OBJ_TAG)
+ print_annotated_tag(revname, &oid);
+ else
+ print_lightweight_tag(revname, obj);
cleanup:
strbuf_release(&fullref);