author | Lars Hjemli <hjemli@gmail.com> | 2007-06-17 12:53:02 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2007-06-17 12:53:02 (UTC) |
commit | 42a7eb9c73457319a3fd5441ff26046fc9b31dad (patch) (unidiff) | |
tree | 4771b955e031005e7c222ef0cbabb719f7cd003a | |
parent | 48c487d72daef7e71683a85f775db8d36ab20341 (diff) | |
download | cgit-42a7eb9c73457319a3fd5441ff26046fc9b31dad.zip cgit-42a7eb9c73457319a3fd5441ff26046fc9b31dad.tar.gz cgit-42a7eb9c73457319a3fd5441ff26046fc9b31dad.tar.bz2 |
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 | 14 | ||||
-rw-r--r-- | ui-summary.c | 18 | ||||
-rw-r--r-- | ui-tree.c | 1 |
7 files changed, 30 insertions, 17 deletions
@@ -95,17 +95,17 @@ static void cgit_print_repo_page(struct cacheitem *item) | |||
95 | cgit_print_log(cgit_query_head, cgit_query_ofs, | 95 | cgit_print_log(cgit_query_head, cgit_query_ofs, |
96 | cgit_max_commit_count, cgit_query_search, | 96 | cgit_max_commit_count, cgit_query_search, |
97 | cgit_query_path, 1); | 97 | cgit_query_path, 1); |
98 | break; | 98 | break; |
99 | case CMD_TREE: | 99 | case CMD_TREE: |
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, |
107 | cgit_query_path); | 107 | cgit_query_path); |
108 | break; | 108 | break; |
109 | default: | 109 | default: |
110 | cgit_print_error("Invalid request"); | 110 | cgit_print_error("Invalid request"); |
111 | } | 111 | } |
@@ -200,16 +200,18 @@ extern int cache_expired(struct cacheitem *item); | |||
200 | extern char *cgit_repourl(const char *reponame); | 200 | extern char *cgit_repourl(const char *reponame); |
201 | extern char *cgit_pageurl(const char *reponame, const char *pagename, | 201 | extern char *cgit_pageurl(const char *reponame, const char *pagename, |
202 | const char *query); | 202 | const char *query); |
203 | 203 | ||
204 | extern void cgit_tree_link(char *name, char *title, char *class, char *head, | 204 | 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); |
211 | extern void cgit_print_age(time_t t, time_t max_relative, char *format); | 213 | extern void cgit_print_age(time_t t, time_t max_relative, char *format); |
212 | extern void cgit_print_docstart(char *title, struct cacheitem *item); | 214 | extern void cgit_print_docstart(char *title, struct cacheitem *item); |
213 | extern void cgit_print_docend(); | 215 | extern void cgit_print_docend(); |
214 | extern void cgit_print_pageheader(char *title, int show_search); | 216 | extern void cgit_print_pageheader(char *title, int show_search); |
215 | extern void cgit_print_snapshot_start(const char *mimetype, | 217 | extern void cgit_print_snapshot_start(const char *mimetype, |
diff --git a/ui-commit.c b/ui-commit.c index 885f870..8864fc6 100644 --- a/ui-commit.c +++ b/ui-commit.c | |||
@@ -151,16 +151,19 @@ void cgit_print_commit(const char *hex) | |||
151 | struct commitinfo *info; | 151 | struct commitinfo *info; |
152 | struct commit_list *p; | 152 | struct commit_list *p; |
153 | unsigned char sha1[20]; | 153 | unsigned char sha1[20]; |
154 | char *query; | 154 | char *query; |
155 | char *filename; | 155 | char *filename; |
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; |
162 | } | 165 | } |
163 | commit = lookup_commit_reference(sha1); | 166 | commit = lookup_commit_reference(sha1); |
164 | if (!commit) { | 167 | if (!commit) { |
165 | cgit_print_error(fmt("Bad commit reference: %s", hex)); | 168 | cgit_print_error(fmt("Bad commit reference: %s", hex)); |
166 | return; | 169 | return; |
@@ -26,21 +26,18 @@ void inspect_files(struct diff_filepair *pair) | |||
26 | void print_commit(struct commit *commit) | 26 | void print_commit(struct commit *commit) |
27 | { | 27 | { |
28 | struct commitinfo *info; | 28 | struct commitinfo *info; |
29 | 29 | ||
30 | info = cgit_parse_commit(commit); | 30 | info = cgit_parse_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; |
42 | cgit_diff_commit(commit, inspect_files); | 39 | cgit_diff_commit(commit, inspect_files); |
43 | html("</td><td class='right'>"); | 40 | html("</td><td class='right'>"); |
44 | htmlf("%d", files); | 41 | htmlf("%d", files); |
45 | if (cgit_repo->enable_log_linecount) { | 42 | if (cgit_repo->enable_log_linecount) { |
46 | html("</td><td class='right'>"); | 43 | html("</td><td class='right'>"); |
diff --git a/ui-shared.c b/ui-shared.c index 64ee79c..71c899a 100644 --- a/ui-shared.c +++ b/ui-shared.c | |||
@@ -131,17 +131,17 @@ static char *repolink(char *title, char *class, char *page, char *head, | |||
131 | html(delim); | 131 | html(delim); |
132 | html("h="); | 132 | html("h="); |
133 | html_attr(head); | 133 | html_attr(head); |
134 | delim = "&"; | 134 | delim = "&"; |
135 | } | 135 | } |
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 | ||
144 | delim = repolink(title, class, page, head, path); | 144 | delim = repolink(title, class, page, head, path); |
145 | if (rev && strcmp(rev, cgit_query_head)) { | 145 | if (rev && strcmp(rev, cgit_query_head)) { |
146 | html(delim); | 146 | html(delim); |
147 | html("id="); | 147 | html("id="); |
@@ -159,16 +159,28 @@ void cgit_tree_link(char *name, char *title, char *class, char *head, | |||
159 | } | 159 | } |
160 | 160 | ||
161 | void cgit_log_link(char *name, char *title, char *class, char *head, | 161 | void cgit_log_link(char *name, char *title, char *class, char *head, |
162 | char *rev, char *path) | 162 | char *rev, char *path) |
163 | { | 163 | { |
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]; |
170 | struct tm *time; | 182 | struct tm *time; |
171 | 183 | ||
172 | time = gmtime(&secs); | 184 | time = gmtime(&secs); |
173 | strftime(buf, sizeof(buf)-1, format, time); | 185 | strftime(buf, sizeof(buf)-1, format, time); |
174 | html_txt(buf); | 186 | html_txt(buf); |
diff --git a/ui-summary.c b/ui-summary.c index 29b76e3..03dd078 100644 --- a/ui-summary.c +++ b/ui-summary.c | |||
@@ -10,57 +10,57 @@ | |||
10 | 10 | ||
11 | static int header; | 11 | static int header; |
12 | 12 | ||
13 | static int cgit_print_branch_cb(const char *refname, const unsigned char *sha1, | 13 | static int cgit_print_branch_cb(const char *refname, const unsigned char *sha1, |
14 | int flags, void *cb_data) | 14 | int flags, void *cb_data) |
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 |
23 | // from previous calls to git functions in cgit_print_log() | 25 | // from previous calls to git functions in cgit_print_log() |
24 | commit->object.parsed = 0; | 26 | commit->object.parsed = 0; |
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 { |
42 | html("<tr><td>"); | 40 | html("<tr><td>"); |
43 | html_txt(buf); | 41 | html_txt(buf); |
44 | html("</td><td colspan='3'>"); | 42 | html("</td><td colspan='3'>"); |
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 | ||
51 | 50 | ||
52 | static void cgit_print_object_ref(struct object *obj) | 51 | static void cgit_print_object_ref(struct object *obj) |
53 | { | 52 | { |
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"; |
62 | } else { | 62 | } else { |
63 | page = "view"; | 63 | page = "view"; |
64 | arg = "id"; | 64 | arg = "id"; |
65 | } | 65 | } |
66 | 66 | ||
@@ -53,17 +53,16 @@ static void print_object(const unsigned char *sha1, char *path) | |||
53 | 53 | ||
54 | static int ls_item(const unsigned char *sha1, const char *base, int baselen, | 54 | static int ls_item(const unsigned char *sha1, const char *base, int baselen, |
55 | const char *pathname, unsigned int mode, int stage) | 55 | const char *pathname, unsigned int mode, int stage) |
56 | { | 56 | { |
57 | char *name; | 57 | char *name; |
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 : "", |
65 | cgit_query_path ? "/" : "", name); | 64 | cgit_query_path ? "/" : "", name); |
66 | 65 | ||
67 | type = sha1_object_info(sha1, &size); | 66 | type = sha1_object_info(sha1, &size); |
68 | if (type == OBJ_BAD && !S_ISDIRLNK(mode)) { | 67 | if (type == OBJ_BAD && !S_ISDIRLNK(mode)) { |
69 | htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>", | 68 | htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>", |