diff options
author | Lars Hjemli | 2007-06-17 14:53:02 +0200 |
---|---|---|
committer | Lars Hjemli | 2007-06-17 14:53:02 +0200 |
commit | 42a7eb9c73457319a3fd5441ff26046fc9b31dad (patch) | |
tree | 4771b955e031005e7c222ef0cbabb719f7cd003a | |
parent | Add git_log_link() and fix bug in generic repolink function (diff) | |
download | cgit-42a7eb9c73457319a3fd5441ff26046fc9b31dad.tar.gz cgit-42a7eb9c73457319a3fd5441ff26046fc9b31dad.zip |
Add cgit_commit_link() + support for id=sha1 to commit view
This adds a function to generate links to the commit page and extends said page to use id from querystring as primary revision specified (fallback to h). Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-rw-r--r-- | cgit.c | 2 | ||||
-rw-r--r-- | cgit.h | 2 | ||||
-rw-r--r-- | ui-commit.c | 3 | ||||
-rw-r--r-- | ui-log.c | 7 | ||||
-rw-r--r-- | ui-shared.c | 16 | ||||
-rw-r--r-- | ui-summary.c | 18 | ||||
-rw-r--r-- | ui-tree.c | 1 |
7 files changed, 31 insertions, 18 deletions
diff --git a/cgit.c b/cgit.c index 1c213c7..f5135d9 100644 --- a/cgit.c +++ b/cgit.c | |||
@@ -100,7 +100,7 @@ static void cgit_print_repo_page(struct cacheitem *item) | |||
100 | cgit_print_tree(cgit_query_sha1, cgit_query_path); | 100 | cgit_print_tree(cgit_query_sha1, cgit_query_path); |
101 | break; | 101 | break; |
102 | case CMD_COMMIT: | 102 | case CMD_COMMIT: |
103 | cgit_print_commit(cgit_query_head); | 103 | cgit_print_commit(cgit_query_sha1); |
104 | break; | 104 | break; |
105 | case CMD_DIFF: | 105 | case CMD_DIFF: |
106 | cgit_print_diff(cgit_query_head, cgit_query_sha1, cgit_query_sha2, | 106 | cgit_print_diff(cgit_query_head, cgit_query_sha1, cgit_query_sha2, |
diff --git a/cgit.h b/cgit.h index b2f6361..c276a24 100644 --- a/cgit.h +++ b/cgit.h | |||
@@ -205,6 +205,8 @@ extern void cgit_tree_link(char *name, char *title, char *class, char *head, | |||
205 | char *rev, char *path); | 205 | char *rev, char *path); |
206 | extern void cgit_log_link(char *name, char *title, char *class, char *head, | 206 | extern void cgit_log_link(char *name, char *title, char *class, char *head, |
207 | char *rev, char *path); | 207 | char *rev, char *path); |
208 | extern void cgit_commit_link(char *name, char *title, char *class, char *head, | ||
209 | char *rev); | ||
208 | 210 | ||
209 | extern void cgit_print_error(char *msg); | 211 | extern void cgit_print_error(char *msg); |
210 | extern void cgit_print_date(time_t secs, char *format); | 212 | extern void cgit_print_date(time_t secs, char *format); |
diff --git a/ui-commit.c b/ui-commit.c index 885f870..8864fc6 100644 --- a/ui-commit.c +++ b/ui-commit.c | |||
@@ -156,6 +156,9 @@ void cgit_print_commit(const char *hex) | |||
156 | char *tmp; | 156 | char *tmp; |
157 | int i; | 157 | int i; |
158 | 158 | ||
159 | if (!hex) | ||
160 | hex = cgit_query_head; | ||
161 | |||
159 | if (get_sha1(hex, sha1)) { | 162 | if (get_sha1(hex, sha1)) { |
160 | cgit_print_error(fmt("Bad object id: %s", hex)); | 163 | cgit_print_error(fmt("Bad object id: %s", hex)); |
161 | return; | 164 | return; |
diff --git a/ui-log.c b/ui-log.c index bb17e1d..8d774b0 100644 --- a/ui-log.c +++ b/ui-log.c | |||
@@ -31,11 +31,8 @@ void print_commit(struct commit *commit) | |||
31 | html("<tr><td>"); | 31 | html("<tr><td>"); |
32 | cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE); | 32 | cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE); |
33 | html("</td><td>"); | 33 | html("</td><td>"); |
34 | char *qry = fmt("h=%s", sha1_to_hex(commit->object.sha1)); | 34 | cgit_commit_link(info->subject, NULL, NULL, cgit_query_head, |
35 | char *url = cgit_pageurl(cgit_query_repo, "commit", qry); | 35 | sha1_to_hex(commit->object.sha1)); |
36 | html_link_open(url, NULL, NULL); | ||
37 | html_ntxt(cgit_max_msg_len, info->subject); | ||
38 | html_link_close(); | ||
39 | if (cgit_repo->enable_log_filecount) { | 36 | if (cgit_repo->enable_log_filecount) { |
40 | files = 0; | 37 | files = 0; |
41 | lines = 0; | 38 | lines = 0; |
diff --git a/ui-shared.c b/ui-shared.c index 64ee79c..71c899a 100644 --- a/ui-shared.c +++ b/ui-shared.c | |||
@@ -136,8 +136,8 @@ static char *repolink(char *title, char *class, char *page, char *head, | |||
136 | return fmt("%s", delim); | 136 | return fmt("%s", delim); |
137 | } | 137 | } |
138 | 138 | ||
139 | static char *reporevlink(char *page, char *name, char *title, char *class, | 139 | static void reporevlink(char *page, char *name, char *title, char *class, |
140 | char *head, char *rev, char *path) | 140 | char *head, char *rev, char *path) |
141 | { | 141 | { |
142 | char *delim; | 142 | char *delim; |
143 | 143 | ||
@@ -164,6 +164,18 @@ void cgit_log_link(char *name, char *title, char *class, char *head, | |||
164 | reporevlink("log", name, title, class, head, rev, path); | 164 | reporevlink("log", name, title, class, head, rev, path); |
165 | } | 165 | } |
166 | 166 | ||
167 | void cgit_commit_link(char *name, char *title, char *class, char *head, | ||
168 | char *rev) | ||
169 | { | ||
170 | if (strlen(name) > cgit_max_msg_len && cgit_max_msg_len >= 15) { | ||
171 | name[cgit_max_msg_len] = '\0'; | ||
172 | name[cgit_max_msg_len - 1] = '.'; | ||
173 | name[cgit_max_msg_len - 2] = '.'; | ||
174 | name[cgit_max_msg_len - 3] = '.'; | ||
175 | } | ||
176 | reporevlink("commit", name, title, class, head, rev, NULL); | ||
177 | } | ||
178 | |||
167 | void cgit_print_date(time_t secs, char *format) | 179 | void cgit_print_date(time_t secs, char *format) |
168 | { | 180 | { |
169 | char buf[64]; | 181 | char buf[64]; |
diff --git a/ui-summary.c b/ui-summary.c index 29b76e3..03dd078 100644 --- a/ui-summary.c +++ b/ui-summary.c | |||
@@ -15,8 +15,10 @@ static int cgit_print_branch_cb(const char *refname, const unsigned char *sha1, | |||
15 | { | 15 | { |
16 | struct commit *commit; | 16 | struct commit *commit; |
17 | struct commitinfo *info; | 17 | struct commitinfo *info; |
18 | char buf[256], *url; | 18 | char buf[256]; |
19 | char *ref; | ||
19 | 20 | ||
21 | ref = xstrdup(refname); | ||
20 | strncpy(buf, refname, sizeof(buf)); | 22 | strncpy(buf, refname, sizeof(buf)); |
21 | commit = lookup_commit(sha1); | 23 | commit = lookup_commit(sha1); |
22 | // object is not really parsed at this point, because of some fallout | 24 | // object is not really parsed at this point, because of some fallout |
@@ -25,17 +27,13 @@ static int cgit_print_branch_cb(const char *refname, const unsigned char *sha1, | |||
25 | if (commit && !parse_commit(commit)){ | 27 | if (commit && !parse_commit(commit)){ |
26 | info = cgit_parse_commit(commit); | 28 | info = cgit_parse_commit(commit); |
27 | html("<tr><td>"); | 29 | html("<tr><td>"); |
28 | cgit_log_link(refname, NULL, NULL, refname, NULL, NULL); | 30 | cgit_log_link(ref, NULL, NULL, ref, NULL, NULL); |
29 | html("</td><td>"); | 31 | html("</td><td>"); |
30 | cgit_print_age(commit->date, -1, NULL); | 32 | cgit_print_age(commit->date, -1, NULL); |
31 | html("</td><td>"); | 33 | html("</td><td>"); |
32 | html_txt(info->author); | 34 | html_txt(info->author); |
33 | html("</td><td>"); | 35 | html("</td><td>"); |
34 | url = cgit_pageurl(cgit_query_repo, "commit", | 36 | cgit_commit_link(info->subject, NULL, NULL, ref, NULL); |
35 | fmt("h=%s", sha1_to_hex(sha1))); | ||
36 | html_link_open(url, NULL, NULL); | ||
37 | html_ntxt(cgit_max_msg_len, info->subject); | ||
38 | html_link_close(); | ||
39 | html("</td></tr>\n"); | 37 | html("</td></tr>\n"); |
40 | cgit_free_commitinfo(info); | 38 | cgit_free_commitinfo(info); |
41 | } else { | 39 | } else { |
@@ -45,6 +43,7 @@ static int cgit_print_branch_cb(const char *refname, const unsigned char *sha1, | |||
45 | htmlf("*** bad ref %s ***", sha1_to_hex(sha1)); | 43 | htmlf("*** bad ref %s ***", sha1_to_hex(sha1)); |
46 | html("</td></tr>\n"); | 44 | html("</td></tr>\n"); |
47 | } | 45 | } |
46 | free(ref); | ||
48 | return 0; | 47 | return 0; |
49 | } | 48 | } |
50 | 49 | ||
@@ -54,8 +53,9 @@ static void cgit_print_object_ref(struct object *obj) | |||
54 | char *page, *arg, *url; | 53 | char *page, *arg, *url; |
55 | 54 | ||
56 | if (obj->type == OBJ_COMMIT) { | 55 | if (obj->type == OBJ_COMMIT) { |
57 | page = "commit"; | 56 | cgit_commit_link(fmt("commit %s", sha1_to_hex(obj->sha1)), NULL, NULL, |
58 | arg = "h"; | 57 | cgit_query_head, sha1_to_hex(obj->sha1)); |
58 | return; | ||
59 | } else if (obj->type == OBJ_TREE) { | 59 | } else if (obj->type == OBJ_TREE) { |
60 | page = "tree"; | 60 | page = "tree"; |
61 | arg = "id"; | 61 | arg = "id"; |
diff --git a/ui-tree.c b/ui-tree.c index e16b638..1037c82 100644 --- a/ui-tree.c +++ b/ui-tree.c | |||
@@ -58,7 +58,6 @@ static int ls_item(const unsigned char *sha1, const char *base, int baselen, | |||
58 | char *fullpath; | 58 | char *fullpath; |
59 | enum object_type type; | 59 | enum object_type type; |
60 | unsigned long size = 0; | 60 | unsigned long size = 0; |
61 | char *url, *qry; | ||
62 | 61 | ||
63 | name = xstrdup(pathname); | 62 | name = xstrdup(pathname); |
64 | fullpath = fmt("%s%s%s", cgit_query_path ? cgit_query_path : "", | 63 | fullpath = fmt("%s%s%s", cgit_query_path ? cgit_query_path : "", |