diff options
-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
@@ -23,7 +23,7 @@ VERSION: | |||
23 | EXTLIBS = git/libgit.a git/xdiff/lib.a -lz -lcrypto | 23 | EXTLIBS = git/libgit.a git/xdiff/lib.a -lz -lcrypto |
24 | OBJECTS = shared.o cache.o parsing.o html.o ui-shared.o ui-repolist.o \ | 24 | OBJECTS = shared.o cache.o parsing.o html.o ui-shared.o ui-repolist.o \ |
25 | ui-summary.o ui-log.o ui-tree.o ui-commit.o ui-diff.o \ | 25 | ui-summary.o ui-log.o ui-tree.o ui-commit.o ui-diff.o \ |
26 | ui-snapshot.o ui-blob.o | 26 | ui-snapshot.o ui-blob.o ui-tag.o |
27 | 27 | ||
28 | CFLAGS += -Wall | 28 | CFLAGS += -Wall |
29 | 29 | ||
@@ -101,6 +101,9 @@ static void cgit_print_repo_page(struct cacheitem *item) | |||
101 | case CMD_COMMIT: | 101 | case CMD_COMMIT: |
102 | cgit_print_commit(cgit_query_sha1); | 102 | cgit_print_commit(cgit_query_sha1); |
103 | break; | 103 | break; |
104 | case CMD_TAG: | ||
105 | cgit_print_tag(cgit_query_sha1); | ||
106 | break; | ||
104 | case CMD_DIFF: | 107 | case CMD_DIFF: |
105 | cgit_print_diff(cgit_query_sha1, cgit_query_sha2); | 108 | cgit_print_diff(cgit_query_sha1, cgit_query_sha2); |
106 | break; | 109 | break; |
@@ -27,7 +27,7 @@ | |||
27 | #define CMD_TREE 4 | 27 | #define CMD_TREE 4 |
28 | #define CMD_BLOB 5 | 28 | #define CMD_BLOB 5 |
29 | #define CMD_SNAPSHOT 6 | 29 | #define CMD_SNAPSHOT 6 |
30 | 30 | #define CMD_TAG 7 | |
31 | 31 | ||
32 | /* | 32 | /* |
33 | * Dateformats used on misc. pages | 33 | * Dateformats used on misc. pages |
@@ -212,6 +212,8 @@ extern void cgit_commit_link(char *name, char *title, char *class, char *head, | |||
212 | extern void cgit_diff_link(char *name, char *title, char *class, char *head, | 212 | extern void cgit_diff_link(char *name, char *title, char *class, char *head, |
213 | char *new_rev, char *old_rev, char *path); | 213 | char *new_rev, char *old_rev, char *path); |
214 | 214 | ||
215 | extern void cgit_object_link(struct object *obj); | ||
216 | |||
215 | extern void cgit_print_error(char *msg); | 217 | extern void cgit_print_error(char *msg); |
216 | extern void cgit_print_date(time_t secs, char *format); | 218 | extern void cgit_print_date(time_t secs, char *format); |
217 | extern void cgit_print_age(time_t t, time_t max_relative, char *format); | 219 | 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 * | |||
228 | extern void cgit_print_blob(struct cacheitem *item, const char *hex, char *path); | 230 | extern void cgit_print_blob(struct cacheitem *item, const char *hex, char *path); |
229 | extern void cgit_print_tree(const char *rev, char *path); | 231 | extern void cgit_print_tree(const char *rev, char *path); |
230 | extern void cgit_print_commit(char *hex); | 232 | extern void cgit_print_commit(char *hex); |
233 | extern void cgit_print_tag(char *revname); | ||
231 | extern void cgit_print_diff(const char *new_hex, const char *old_hex); | 234 | extern void cgit_print_diff(const char *new_hex, const char *old_hex); |
232 | extern void cgit_print_snapshot(struct cacheitem *item, const char *hex, | 235 | extern void cgit_print_snapshot(struct cacheitem *item, const char *hex, |
233 | const char *format, const char *prefix, | 236 | const char *format, const char *prefix, |
@@ -63,7 +63,7 @@ int htmlfd = 0; | |||
63 | int cgit_get_cmd_index(const char *cmd) | 63 | int cgit_get_cmd_index(const char *cmd) |
64 | { | 64 | { |
65 | static char *cmds[] = {"log", "commit", "diff", "tree", "blob", | 65 | static char *cmds[] = {"log", "commit", "diff", "tree", "blob", |
66 | "snapshot", NULL}; | 66 | "snapshot", "tag", NULL}; |
67 | int i; | 67 | int i; |
68 | 68 | ||
69 | for(i = 0; cmds[i]; i++) | 69 | for(i = 0; cmds[i]; i++) |
diff --git a/ui-shared.c b/ui-shared.c index d4376ce..fd71c12 100644 --- a/ui-shared.c +++ b/ui-shared.c | |||
@@ -218,6 +218,30 @@ void cgit_diff_link(char *name, char *title, char *class, char *head, | |||
218 | html("</a>"); | 218 | html("</a>"); |
219 | } | 219 | } |
220 | 220 | ||
221 | void cgit_object_link(struct object *obj) | ||
222 | { | ||
223 | char *page, *arg, *url; | ||
224 | |||
225 | if (obj->type == OBJ_COMMIT) { | ||
226 | cgit_commit_link(fmt("commit %s", sha1_to_hex(obj->sha1)), NULL, NULL, | ||
227 | cgit_query_head, sha1_to_hex(obj->sha1)); | ||
228 | return; | ||
229 | } else if (obj->type == OBJ_TREE) { | ||
230 | page = "tree"; | ||
231 | arg = "id"; | ||
232 | } else { | ||
233 | page = "blob"; | ||
234 | arg = "id"; | ||
235 | } | ||
236 | |||
237 | url = cgit_pageurl(cgit_query_repo, page, | ||
238 | fmt("%s=%s", arg, sha1_to_hex(obj->sha1))); | ||
239 | html_link_open(url, NULL, NULL); | ||
240 | htmlf("%s %s", typename(obj->type), | ||
241 | sha1_to_hex(obj->sha1)); | ||
242 | html_link_close(); | ||
243 | } | ||
244 | |||
221 | void cgit_print_date(time_t secs, char *format) | 245 | void cgit_print_date(time_t secs, char *format) |
222 | { | 246 | { |
223 | char buf[64]; | 247 | char buf[64]; |
diff --git a/ui-summary.c b/ui-summary.c index b4bc6d8..de8a180 100644 --- a/ui-summary.c +++ b/ui-summary.c | |||
@@ -47,31 +47,6 @@ static int cgit_print_branch_cb(const char *refname, const unsigned char *sha1, | |||
47 | return 0; | 47 | return 0; |
48 | } | 48 | } |
49 | 49 | ||
50 | |||
51 | static void cgit_print_object_ref(struct object *obj) | ||
52 | { | ||
53 | char *page, *arg, *url; | ||
54 | |||
55 | if (obj->type == OBJ_COMMIT) { | ||
56 | cgit_commit_link(fmt("commit %s", sha1_to_hex(obj->sha1)), NULL, NULL, | ||
57 | cgit_query_head, sha1_to_hex(obj->sha1)); | ||
58 | return; | ||
59 | } else if (obj->type == OBJ_TREE) { | ||
60 | page = "tree"; | ||
61 | arg = "id"; | ||
62 | } else { | ||
63 | page = "view"; | ||
64 | arg = "id"; | ||
65 | } | ||
66 | |||
67 | url = cgit_pageurl(cgit_query_repo, page, | ||
68 | fmt("%s=%s", arg, sha1_to_hex(obj->sha1))); | ||
69 | html_link_open(url, NULL, NULL); | ||
70 | htmlf("%s %s", typename(obj->type), | ||
71 | sha1_to_hex(obj->sha1)); | ||
72 | html_link_close(); | ||
73 | } | ||
74 | |||
75 | static void print_tag_header() | 50 | static void print_tag_header() |
76 | { | 51 | { |
77 | html("<tr class='nohover'><th class='left'>Tag</th>" | 52 | 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, | |||
100 | if (!header) | 75 | if (!header) |
101 | print_tag_header(); | 76 | print_tag_header(); |
102 | html("<tr><td>"); | 77 | html("<tr><td>"); |
103 | url = cgit_pageurl(cgit_query_repo, "view", | 78 | url = cgit_pageurl(cgit_query_repo, "tag", |
104 | fmt("id=%s", sha1_to_hex(sha1))); | 79 | fmt("id=%s", refname)); |
105 | html_link_open(url, NULL, NULL); | 80 | html_link_open(url, NULL, NULL); |
106 | html_txt(buf); | 81 | html_txt(buf); |
107 | html_link_close(); | 82 | html_link_close(); |
@@ -112,7 +87,7 @@ static int cgit_print_tag_cb(const char *refname, const unsigned char *sha1, | |||
112 | if (info->tagger) | 87 | if (info->tagger) |
113 | html(info->tagger); | 88 | html(info->tagger); |
114 | html("</td><td>"); | 89 | html("</td><td>"); |
115 | cgit_print_object_ref(tag->tagged); | 90 | cgit_object_link(tag->tagged); |
116 | html("</td></tr>\n"); | 91 | html("</td></tr>\n"); |
117 | } else { | 92 | } else { |
118 | if (!header) | 93 | if (!header) |
@@ -120,7 +95,7 @@ static int cgit_print_tag_cb(const char *refname, const unsigned char *sha1, | |||
120 | html("<tr><td>"); | 95 | html("<tr><td>"); |
121 | html_txt(buf); | 96 | html_txt(buf); |
122 | html("</td><td colspan='2'/><td>"); | 97 | html("</td><td colspan='2'/><td>"); |
123 | cgit_print_object_ref(obj); | 98 | cgit_object_link(obj); |
124 | html("</td></tr>\n"); | 99 | html("</td></tr>\n"); |
125 | } | 100 | } |
126 | return 0; | 101 | return 0; |
diff --git a/ui-tag.c b/ui-tag.c new file mode 100644 index 0000000..a6989ff --- /dev/null +++ b/ui-tag.c | |||
@@ -0,0 +1,74 @@ | |||
1 | /* ui-tag.c: display a tag | ||
2 | * | ||
3 | * Copyright (C) 2007 Lars Hjemli | ||
4 | * | ||
5 | * Licensed under GNU General Public License v2 | ||
6 | * (see COPYING for full license text) | ||
7 | */ | ||
8 | |||
9 | #include "cgit.h" | ||
10 | |||
11 | |||
12 | static void print_tag_content(char *buf) | ||
13 | { | ||
14 | char *p; | ||
15 | |||
16 | if (!buf) | ||
17 | return; | ||
18 | |||
19 | html("<div class='commit-subject'>"); | ||
20 | p = strchr(buf, '\n'); | ||
21 | if (p) | ||
22 | *p = '\0'; | ||
23 | html_txt(buf); | ||
24 | html("</div>"); | ||
25 | if (p) { | ||
26 | html("<div class='commit-msg'>"); | ||
27 | html_txt(++p); | ||
28 | html("</div>"); | ||
29 | } | ||
30 | } | ||
31 | |||
32 | void cgit_print_tag(char *revname) | ||
33 | { | ||
34 | unsigned char sha1[20]; | ||
35 | struct object *obj; | ||
36 | struct tag *tag; | ||
37 | struct taginfo *info; | ||
38 | |||
39 | if (get_sha1(revname, sha1)) { | ||
40 | cgit_print_error(fmt("Bad tag reference: %s", revname)); | ||
41 | return; | ||
42 | } | ||
43 | obj = parse_object(sha1); | ||
44 | if (!obj) { | ||
45 | cgit_print_error(fmt("Bad object id: %s", sha1_to_hex(sha1))); | ||
46 | return; | ||
47 | } | ||
48 | if (obj->type == OBJ_TAG) { | ||
49 | tag = lookup_tag(sha1); | ||
50 | if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) { | ||
51 | cgit_print_error(fmt("Bad tag object: %s", revname)); | ||
52 | return; | ||
53 | } | ||
54 | html("<table class='commit-info'>\n"); | ||
55 | htmlf("<tr><td>Tag name</td><td>%s (%s)</td></tr>\n", | ||
56 | revname, sha1_to_hex(sha1)); | ||
57 | if (info->tagger_date > 0) { | ||
58 | html("<tr><td>Tag date</td><td>"); | ||
59 | cgit_print_date(info->tagger_date, FMT_LONGDATE); | ||
60 | html("</td><tr>\n"); | ||
61 | } | ||
62 | if (info->tagger) { | ||
63 | html("<tr><td>Tagged by</td><td>"); | ||
64 | html_txt(info->tagger); | ||
65 | html("</td></tr>\n"); | ||
66 | } | ||
67 | html("<tr><td>Tagged object</td><td>"); | ||
68 | cgit_object_link(tag->tagged); | ||
69 | html("</td></tr>\n"); | ||
70 | html("</table>\n"); | ||
71 | print_tag_content(info->msg); | ||
72 | } | ||
73 | return; | ||
74 | } | ||