Add ui-tag.c
This file implements the tag-command, i.e. printing of annotated tags. Signed-off-by: Lars Hjemli <hjemli@gmail.com> Signed-off-by: Lars Hjemli <hjemli@gmail.com>
This commit is contained in:
		
							
								
								
									
										2
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								Makefile
									
									
									
									
									
								
							@@ -23,7 +23,7 @@ VERSION:
 | 
			
		||||
EXTLIBS = git/libgit.a git/xdiff/lib.a -lz -lcrypto
 | 
			
		||||
OBJECTS = shared.o cache.o parsing.o html.o ui-shared.o ui-repolist.o \
 | 
			
		||||
	ui-summary.o ui-log.o ui-tree.o ui-commit.o ui-diff.o \
 | 
			
		||||
	ui-snapshot.o ui-blob.o
 | 
			
		||||
	ui-snapshot.o ui-blob.o ui-tag.o
 | 
			
		||||
 | 
			
		||||
CFLAGS += -Wall
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										3
									
								
								cgit.c
									
									
									
									
									
								
							
							
						
						
									
										3
									
								
								cgit.c
									
									
									
									
									
								
							@@ -101,6 +101,9 @@ static void cgit_print_repo_page(struct cacheitem *item)
 | 
			
		||||
	case CMD_COMMIT:
 | 
			
		||||
		cgit_print_commit(cgit_query_sha1);
 | 
			
		||||
		break;
 | 
			
		||||
	case CMD_TAG:
 | 
			
		||||
		cgit_print_tag(cgit_query_sha1);
 | 
			
		||||
		break;
 | 
			
		||||
	case CMD_DIFF:
 | 
			
		||||
		cgit_print_diff(cgit_query_sha1, cgit_query_sha2);
 | 
			
		||||
		break;
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										5
									
								
								cgit.h
									
									
									
									
									
								
							
							
						
						
									
										5
									
								
								cgit.h
									
									
									
									
									
								
							@@ -27,7 +27,7 @@
 | 
			
		||||
#define CMD_TREE     4
 | 
			
		||||
#define CMD_BLOB     5
 | 
			
		||||
#define CMD_SNAPSHOT 6
 | 
			
		||||
 | 
			
		||||
#define CMD_TAG      7
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Dateformats used on misc. pages
 | 
			
		||||
@@ -212,6 +212,8 @@ extern void cgit_commit_link(char *name, char *title, char *class, char *head,
 | 
			
		||||
extern void cgit_diff_link(char *name, char *title, char *class, char *head,
 | 
			
		||||
			   char *new_rev, char *old_rev, char *path);
 | 
			
		||||
 | 
			
		||||
extern void cgit_object_link(struct object *obj);
 | 
			
		||||
 | 
			
		||||
extern void cgit_print_error(char *msg);
 | 
			
		||||
extern void cgit_print_date(time_t secs, char *format);
 | 
			
		||||
extern void cgit_print_age(time_t t, time_t max_relative, char *format);
 | 
			
		||||
@@ -228,6 +230,7 @@ extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *
 | 
			
		||||
extern void cgit_print_blob(struct cacheitem *item, const char *hex, char *path);
 | 
			
		||||
extern void cgit_print_tree(const char *rev, char *path);
 | 
			
		||||
extern void cgit_print_commit(char *hex);
 | 
			
		||||
extern void cgit_print_tag(char *revname);
 | 
			
		||||
extern void cgit_print_diff(const char *new_hex, const char *old_hex);
 | 
			
		||||
extern void cgit_print_snapshot(struct cacheitem *item, const char *hex,
 | 
			
		||||
				const char *format, const char *prefix,
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										2
									
								
								shared.c
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								shared.c
									
									
									
									
									
								
							@@ -63,7 +63,7 @@ int htmlfd = 0;
 | 
			
		||||
int cgit_get_cmd_index(const char *cmd)
 | 
			
		||||
{
 | 
			
		||||
	static char *cmds[] = {"log", "commit", "diff", "tree", "blob",
 | 
			
		||||
			       "snapshot", NULL};
 | 
			
		||||
			       "snapshot", "tag", NULL};
 | 
			
		||||
	int i;
 | 
			
		||||
 | 
			
		||||
	for(i = 0; cmds[i]; i++)
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										24
									
								
								ui-shared.c
									
									
									
									
									
								
							
							
						
						
									
										24
									
								
								ui-shared.c
									
									
									
									
									
								
							@@ -218,6 +218,30 @@ void cgit_diff_link(char *name, char *title, char *class, char *head,
 | 
			
		||||
	html("</a>");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void cgit_object_link(struct object *obj)
 | 
			
		||||
{
 | 
			
		||||
	char *page, *arg, *url;
 | 
			
		||||
 | 
			
		||||
	if (obj->type == OBJ_COMMIT) {
 | 
			
		||||
                cgit_commit_link(fmt("commit %s", sha1_to_hex(obj->sha1)), NULL, NULL,
 | 
			
		||||
				 cgit_query_head, sha1_to_hex(obj->sha1));
 | 
			
		||||
		return;
 | 
			
		||||
	} else if (obj->type == OBJ_TREE) {
 | 
			
		||||
		page = "tree";
 | 
			
		||||
		arg = "id";
 | 
			
		||||
	} else {
 | 
			
		||||
		page = "blob";
 | 
			
		||||
		arg = "id";
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	url = cgit_pageurl(cgit_query_repo, page,
 | 
			
		||||
			   fmt("%s=%s", arg, sha1_to_hex(obj->sha1)));
 | 
			
		||||
	html_link_open(url, NULL, NULL);
 | 
			
		||||
	htmlf("%s %s", typename(obj->type),
 | 
			
		||||
	      sha1_to_hex(obj->sha1));
 | 
			
		||||
	html_link_close();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void cgit_print_date(time_t secs, char *format)
 | 
			
		||||
{
 | 
			
		||||
	char buf[64];
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										33
									
								
								ui-summary.c
									
									
									
									
									
								
							
							
						
						
									
										33
									
								
								ui-summary.c
									
									
									
									
									
								
							@@ -47,31 +47,6 @@ static int cgit_print_branch_cb(const char *refname, const unsigned char *sha1,
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
static void cgit_print_object_ref(struct object *obj)
 | 
			
		||||
{
 | 
			
		||||
	char *page, *arg, *url;
 | 
			
		||||
 | 
			
		||||
	if (obj->type == OBJ_COMMIT) {
 | 
			
		||||
                cgit_commit_link(fmt("commit %s", sha1_to_hex(obj->sha1)), NULL, NULL,
 | 
			
		||||
				 cgit_query_head, sha1_to_hex(obj->sha1));
 | 
			
		||||
		return;
 | 
			
		||||
	} else if (obj->type == OBJ_TREE) {
 | 
			
		||||
		page = "tree";
 | 
			
		||||
		arg = "id";
 | 
			
		||||
	} else {
 | 
			
		||||
		page = "view";
 | 
			
		||||
		arg = "id";
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	url = cgit_pageurl(cgit_query_repo, page,
 | 
			
		||||
			   fmt("%s=%s", arg, sha1_to_hex(obj->sha1)));
 | 
			
		||||
	html_link_open(url, NULL, NULL);
 | 
			
		||||
	htmlf("%s %s", typename(obj->type),
 | 
			
		||||
	      sha1_to_hex(obj->sha1));
 | 
			
		||||
	html_link_close();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void print_tag_header()
 | 
			
		||||
{
 | 
			
		||||
	html("<tr class='nohover'><th class='left'>Tag</th>"
 | 
			
		||||
@@ -100,8 +75,8 @@ static int cgit_print_tag_cb(const char *refname, const unsigned char *sha1,
 | 
			
		||||
		if (!header)
 | 
			
		||||
			print_tag_header();
 | 
			
		||||
		html("<tr><td>");
 | 
			
		||||
		url = cgit_pageurl(cgit_query_repo, "view",
 | 
			
		||||
				   fmt("id=%s", sha1_to_hex(sha1)));
 | 
			
		||||
		url = cgit_pageurl(cgit_query_repo, "tag",
 | 
			
		||||
				   fmt("id=%s", refname));
 | 
			
		||||
		html_link_open(url, NULL, NULL);
 | 
			
		||||
		html_txt(buf);
 | 
			
		||||
		html_link_close();
 | 
			
		||||
@@ -112,7 +87,7 @@ static int cgit_print_tag_cb(const char *refname, const unsigned char *sha1,
 | 
			
		||||
		if (info->tagger)
 | 
			
		||||
			html(info->tagger);
 | 
			
		||||
		html("</td><td>");
 | 
			
		||||
		cgit_print_object_ref(tag->tagged);
 | 
			
		||||
		cgit_object_link(tag->tagged);
 | 
			
		||||
		html("</td></tr>\n");
 | 
			
		||||
	} else {
 | 
			
		||||
		if (!header)
 | 
			
		||||
@@ -120,7 +95,7 @@ static int cgit_print_tag_cb(const char *refname, const unsigned char *sha1,
 | 
			
		||||
		html("<tr><td>");
 | 
			
		||||
		html_txt(buf);
 | 
			
		||||
		html("</td><td colspan='2'/><td>");
 | 
			
		||||
		cgit_print_object_ref(obj);
 | 
			
		||||
		cgit_object_link(obj);
 | 
			
		||||
		html("</td></tr>\n");
 | 
			
		||||
	}
 | 
			
		||||
	return 0;
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										74
									
								
								ui-tag.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										74
									
								
								ui-tag.c
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,74 @@
 | 
			
		||||
/* ui-tag.c: display a tag
 | 
			
		||||
 *
 | 
			
		||||
 * Copyright (C) 2007 Lars Hjemli
 | 
			
		||||
 *
 | 
			
		||||
 * Licensed under GNU General Public License v2
 | 
			
		||||
 *   (see COPYING for full license text)
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include "cgit.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
static void print_tag_content(char *buf)
 | 
			
		||||
{
 | 
			
		||||
	char *p;
 | 
			
		||||
 | 
			
		||||
	if (!buf)
 | 
			
		||||
		return;
 | 
			
		||||
 | 
			
		||||
	html("<div class='commit-subject'>");
 | 
			
		||||
	p = strchr(buf, '\n');
 | 
			
		||||
	if (p)
 | 
			
		||||
		*p = '\0';
 | 
			
		||||
	html_txt(buf);
 | 
			
		||||
	html("</div>");
 | 
			
		||||
	if (p) {
 | 
			
		||||
		html("<div class='commit-msg'>");
 | 
			
		||||
		html_txt(++p);
 | 
			
		||||
		html("</div>");
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void cgit_print_tag(char *revname)
 | 
			
		||||
{
 | 
			
		||||
	unsigned char sha1[20];
 | 
			
		||||
	struct object *obj;
 | 
			
		||||
	struct tag *tag;
 | 
			
		||||
	struct taginfo *info;
 | 
			
		||||
 | 
			
		||||
	if (get_sha1(revname, sha1)) {
 | 
			
		||||
		cgit_print_error(fmt("Bad tag reference: %s", revname));
 | 
			
		||||
		return;
 | 
			
		||||
	}
 | 
			
		||||
	obj = parse_object(sha1);
 | 
			
		||||
	if (!obj) {
 | 
			
		||||
		cgit_print_error(fmt("Bad object id: %s", sha1_to_hex(sha1)));
 | 
			
		||||
		return;
 | 
			
		||||
	}
 | 
			
		||||
	if (obj->type == OBJ_TAG) {
 | 
			
		||||
		tag = lookup_tag(sha1);
 | 
			
		||||
		if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) {
 | 
			
		||||
			cgit_print_error(fmt("Bad tag object: %s", revname));
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
		html("<table class='commit-info'>\n");
 | 
			
		||||
		htmlf("<tr><td>Tag name</td><td>%s (%s)</td></tr>\n",
 | 
			
		||||
		      revname, sha1_to_hex(sha1));
 | 
			
		||||
		if (info->tagger_date > 0) {
 | 
			
		||||
			html("<tr><td>Tag date</td><td>");
 | 
			
		||||
			cgit_print_date(info->tagger_date, FMT_LONGDATE);
 | 
			
		||||
			html("</td><tr>\n");
 | 
			
		||||
		}
 | 
			
		||||
		if (info->tagger) {
 | 
			
		||||
			html("<tr><td>Tagged by</td><td>");
 | 
			
		||||
			html_txt(info->tagger);
 | 
			
		||||
			html("</td></tr>\n");
 | 
			
		||||
		}
 | 
			
		||||
		html("<tr><td>Tagged object</td><td>");
 | 
			
		||||
		cgit_object_link(tag->tagged);
 | 
			
		||||
		html("</td></tr>\n");
 | 
			
		||||
		html("</table>\n");
 | 
			
		||||
		print_tag_content(info->msg);
 | 
			
		||||
	}
 | 
			
		||||
	return;
 | 
			
		||||
}
 | 
			
		||||
		Viittaa uudesa ongelmassa
	
	Block a user