author | Lars Hjemli <hjemli@gmail.com> | 2007-07-22 21:42:55 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2007-07-22 21:44:57 (UTC) |
commit | 4e9107abfe8d3edff17826875b417bcf40dc7390 (patch) (side-by-side diff) | |
tree | 96cfafa9b8838f34e1363ee3019eae64a6229b30 | |
parent | 71ebcbe23ab548e5c0ad40aa8be5741654ed3201 (diff) | |
download | cgit-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>
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | cgit.c | 3 | ||||
-rw-r--r-- | cgit.h | 5 | ||||
-rw-r--r-- | shared.c | 2 | ||||
-rw-r--r-- | ui-shared.c | 24 | ||||
-rw-r--r-- | ui-summary.c | 33 | ||||
-rw-r--r-- | ui-tag.c | 74 |
7 files changed, 111 insertions, 32 deletions
@@ -10,33 +10,33 @@ CGIT_SCRIPT_NAME = cgit.cgi -include cgit.conf CGIT_VERSION = 0.5 all: cgit VERSION: sh gen-version.sh -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 CFLAGS += -Igit CFLAGS += -DSHA1_HEADER='$(SHA1_HEADER)' CFLAGS += -DCGIT_VERSION='"$(CGIT_VERSION)"' CFLAGS += -DCGIT_CONFIG='"$(CGIT_CONFIG)"' CFLAGS += -DCGIT_SCRIPT_NAME='"$(CGIT_SCRIPT_NAME)"' # # If make is run on a nongit platform, get the git sources as a tarball. @@ -88,32 +88,35 @@ static void cgit_print_repo_page(struct cacheitem *item) } cgit_print_pageheader(cgit_query_page, show_search); switch(cgit_cmd) { case CMD_LOG: cgit_print_log(cgit_query_sha1, cgit_query_ofs, cgit_max_commit_count, cgit_query_search, cgit_query_path, 1); break; 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"); } cgit_print_docend(); } static void cgit_fill_cache(struct cacheitem *item, int use_cache) { static char buf[PATH_MAX]; int stdout2; getcwd(buf, sizeof(buf)); item->st.st_mtime = time(NULL); @@ -14,33 +14,33 @@ #include <refs.h> #include <revision.h> #include <log-tree.h> #include <archive.h> #include <xdiff/xdiff.h> /* * The valid cgit repo-commands */ #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" /* * Limits used for relative dates */ #define TM_MIN 60 #define TM_HOUR (TM_MIN * 60) #define TM_DAY (TM_HOUR * 24) #define TM_WEEK (TM_DAY * 7) #define TM_YEAR (TM_DAY * 365) @@ -199,38 +199,41 @@ extern int cache_cancel_lock(struct cacheitem *item); extern int cache_exist(struct cacheitem *item); extern int cache_expired(struct cacheitem *item); extern char *cgit_repourl(const char *reponame); extern char *cgit_pageurl(const char *reponame, const char *pagename, const char *query); extern void cgit_tree_link(char *name, char *title, char *class, char *head, char *rev, char *path); 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); extern void cgit_print_snapshot_start(const char *mimetype, const char *filename, struct cacheitem *item); 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 */ @@ -50,33 +50,33 @@ char *cgit_querystring = NULL; char *cgit_query_repo = NULL; char *cgit_query_page = NULL; char *cgit_query_head = NULL; char *cgit_query_search = NULL; char *cgit_query_sha1 = NULL; char *cgit_query_sha2 = NULL; char *cgit_query_path = NULL; char *cgit_query_name = NULL; 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; } int chk_zero(int result, char *msg) { if (result != 0) die("%s: %s", msg, strerror(errno)); return result; } int chk_positive(int result, char *msg) diff --git a/ui-shared.c b/ui-shared.c index d4376ce..fd71c12 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -205,32 +205,56 @@ void cgit_diff_link(char *name, char *title, char *class, char *head, if (new_rev && strcmp(new_rev, cgit_query_head)) { html(delim); html("id="); html_attr(new_rev); delim = "&"; } if (old_rev) { html(delim); html("id2="); html_attr(old_rev); } 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); strftime(buf, sizeof(buf)-1, format, time); html_txt(buf); } void cgit_print_age(time_t t, time_t max_relative, char *format) { time_t now, secs; time(&now); secs = now - t; diff --git a/ui-summary.c b/ui-summary.c index b4bc6d8..de8a180 100644 --- a/ui-summary.c +++ b/ui-summary.c @@ -34,106 +34,81 @@ static int cgit_print_branch_cb(const char *refname, const unsigned char *sha1, html_txt(info->author); html("</td><td>"); cgit_commit_link(info->subject, NULL, NULL, ref, NULL); html("</td></tr>\n"); cgit_free_commitinfo(info); } else { html("<tr><td>"); html_txt(buf); html("</td><td colspan='3'>"); htmlf("*** bad ref %s ***", sha1_to_hex(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"); header = 1; } static int cgit_print_tag_cb(const char *refname, const unsigned char *sha1, int flags, void *cb_data) { struct tag *tag; struct taginfo *info; struct object *obj; char buf[256], *url; strncpy(buf, refname, sizeof(buf)); obj = parse_object(sha1); if (!obj) return 1; if (obj->type == OBJ_TAG) { 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, int flags, void *cb_data) { struct tag *tag; struct taginfo *info; struct object *obj; char buf[256], *url; unsigned char fileid[20]; if (prefixcmp(refname, "refs/archives")) return 0; 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; +} |