summaryrefslogtreecommitdiffabout
authorLars Hjemli <hjemli@gmail.com>2007-07-22 21:42:55 (UTC)
committer Lars Hjemli <hjemli@gmail.com>2007-07-22 21:44:57 (UTC)
commit4e9107abfe8d3edff17826875b417bcf40dc7390 (patch) (side-by-side diff)
tree96cfafa9b8838f34e1363ee3019eae64a6229b30
parent71ebcbe23ab548e5c0ad40aa8be5741654ed3201 (diff)
downloadcgit-4e9107abfe8d3edff17826875b417bcf40dc7390.zip
cgit-4e9107abfe8d3edff17826875b417bcf40dc7390.tar.gz
cgit-4e9107abfe8d3edff17826875b417bcf40dc7390.tar.bz2
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>
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--Makefile2
-rw-r--r--cgit.c3
-rw-r--r--cgit.h5
-rw-r--r--shared.c2
-rw-r--r--ui-shared.c24
-rw-r--r--ui-summary.c33
-rw-r--r--ui-tag.c74
7 files changed, 111 insertions, 32 deletions
diff --git a/Makefile b/Makefile
index cea09f1..50d0011 100644
--- a/Makefile
+++ b/Makefile
@@ -20,13 +20,13 @@ VERSION:
-include 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
ifdef DEBUG
CFLAGS += -g
endif
diff --git a/cgit.c b/cgit.c
index 1281bfa..4b91829 100644
--- a/cgit.c
+++ b/cgit.c
@@ -98,12 +98,15 @@ static void cgit_print_repo_page(struct cacheitem *item)
case CMD_TREE:
cgit_print_tree(cgit_query_sha1, cgit_query_path);
break;
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;
default:
cgit_print_error("Invalid request");
}
diff --git a/cgit.h b/cgit.h
index 2ff5340..610a16d 100644
--- a/cgit.h
+++ b/cgit.h
@@ -24,13 +24,13 @@
#define CMD_LOG 1
#define CMD_COMMIT 2
#define CMD_DIFF 3
#define CMD_TREE 4
#define CMD_BLOB 5
#define CMD_SNAPSHOT 6
-
+#define CMD_TAG 7
/*
* Dateformats used on misc. pages
*/
#define FMT_LONGDATE "%Y-%m-%d %H:%M:%S"
#define FMT_SHORTDATE "%Y-%m-%d"
@@ -209,12 +209,14 @@ extern void cgit_log_link(char *name, char *title, char *class, char *head,
char *rev, char *path, int ofs);
extern void cgit_commit_link(char *name, char *title, char *class, char *head,
char *rev);
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);
extern void cgit_print_docstart(char *title, struct cacheitem *item);
extern void cgit_print_docend();
extern void cgit_print_pageheader(char *title, int show_search);
@@ -225,12 +227,13 @@ extern void cgit_print_snapshot_start(const char *mimetype,
extern void cgit_print_repolist(struct cacheitem *item);
extern void cgit_print_summary();
extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *path, int pager);
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,
const char *filename);
#endif /* CGIT_H */
diff --git a/shared.c b/shared.c
index 1a5b866..06693b0 100644
--- a/shared.c
+++ b/shared.c
@@ -60,13 +60,13 @@ int cgit_query_ofs = 0;
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++)
if (!strcmp(cmd, cmds[i]))
return i + 1;
return 0;
diff --git a/ui-shared.c b/ui-shared.c
index d4376ce..fd71c12 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -215,12 +215,36 @@ void cgit_diff_link(char *name, char *title, char *class, char *head,
}
html("'>");
html_txt(name);
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];
struct tm *time;
time = gmtime(&secs);
diff --git a/ui-summary.c b/ui-summary.c
index b4bc6d8..de8a180 100644
--- a/ui-summary.c
+++ b/ui-summary.c
@@ -44,37 +44,12 @@ static int cgit_print_branch_cb(const char *refname, const unsigned char *sha1,
html("</td></tr>\n");
}
free(ref);
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>"
"<th class='left'>Age</th>"
"<th class='left'>Author</th>"
"<th class='left'>Reference</th></tr>\n");
@@ -97,33 +72,33 @@ static int cgit_print_tag_cb(const char *refname, const unsigned char *sha1,
tag = lookup_tag(sha1);
if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag)))
return 2;
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();
html("</td><td>");
if (info->tagger_date > 0)
cgit_print_age(info->tagger_date, -1, NULL);
html("</td><td>");
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)
print_tag_header();
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;
}
static int cgit_print_archive_cb(const char *refname, const unsigned char *sha1,
diff --git a/ui-tag.c b/ui-tag.c
new file mode 100644
index 0000000..a6989ff
--- a/dev/null
+++ b/ui-tag.c
@@ -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;
+}