This enables path-filtering in log-view, and adds a link per entry in tree-view to show the log for each file/directory.
Unified · Split
| @@ -108,9 +108,10 @@ static void cgit_print_repo_page(struct cacheitem *item) · 107 unmodified lines | ||
| 108 | 108 | |
| 109 | 109 | if (!strcmp(cgit_query_page, "log")) { |
| 110 | 110 | cgit_print_log(cgit_query_head, cgit_query_ofs, |
| 111 | − cgit_max_commit_count, cgit_query_search); | |
| 111 | + cgit_max_commit_count, cgit_query_search, | |
| 112 | + cgit_query_path); | |
| 112 | 113 | } else if (!strcmp(cgit_query_page, "tree")) { |
| 113 | − cgit_print_tree(cgit_query_sha1, cgit_query_path); | |
| 114 | + cgit_print_tree(cgit_query_head, cgit_query_sha1, cgit_query_path); | |
| 114 | 115 | } else if (!strcmp(cgit_query_page, "commit")) { |
| 115 | 116 | cgit_print_commit(cgit_query_sha1); |
| 116 | 117 | } else if (!strcmp(cgit_query_page, "view")) { |
| @@ -189,6 +189,11 @@ td.filesize { · 188 unmodified lines | ||
| 189 | 189 | font-family: monospace; |
| 190 | 190 | } |
| 191 | 191 | |
| 192 | +td.links { | |
| 193 | + font-size: 80%; | |
| 194 | + padding-left: 2em; | |
| 195 | +} | |
| 196 | + | |
| 192 | 197 | td.filemode { |
| 193 | 198 | font-family: monospace; |
| 194 | 199 | } |
| @@ -169,10 +169,10 @@ extern void cgit_print_snapshot_start(const char *mimetype, · 168 unmodified lines | ||
| 169 | 169 | |
| 170 | 170 | extern void cgit_print_repolist(struct cacheitem *item); |
| 171 | 171 | extern void cgit_print_summary(); |
| 172 | −extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep); | |
| 172 | +extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *path); | |
| 173 | 173 | extern void cgit_print_view(const char *hex, char *path); |
| 174 | 174 | extern void cgit_print_blob(struct cacheitem *item, const char *hex, char *path); |
| 175 | −extern void cgit_print_tree(const char *hex, char *path); | |
| 175 | +extern void cgit_print_tree(const char *rev, const char *hex, char *path); | |
| 176 | 176 | extern void cgit_print_commit(const char *hex); |
| 177 | 177 | extern void cgit_print_diff(const char *old_hex, const char *new_hex, char *path); |
| 178 | 178 | extern void cgit_print_snapshot(struct cacheitem *item, const char *hex, |
| @@ -186,7 +186,8 @@ void cgit_print_commit(const char *hex) · 185 unmodified lines | ||
| 186 | 186 | cgit_print_date(info->committer_date); |
| 187 | 187 | html("</td></tr>\n"); |
| 188 | 188 | html("<tr><th>tree</th><td colspan='2' class='sha1'><a href='"); |
| 189 | − query = fmt("id=%s", sha1_to_hex(commit->tree->object.sha1)); | |
| 189 | + query = fmt("h=%s&id=%s", sha1_to_hex(commit->object.sha1), | |
| 190 | + sha1_to_hex(commit->tree->object.sha1)); | |
| 190 | 191 | html_attr(cgit_pageurl(cgit_query_repo, "tree", query)); |
| 191 | 192 | htmlf("'>%s</a></td></tr>\n", sha1_to_hex(commit->tree->object.sha1)); |
| 192 | 193 | for (p = commit->parents; p ; p = p->next) { |
| @@ -53,16 +53,20 @@ void print_commit(struct commit *commit) · 52 unmodified lines | ||
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | |
| 56 | −void cgit_print_log(const char *tip, int ofs, int cnt, char *grep) | |
| 56 | +void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *path) | |
| 57 | 57 | { |
| 58 | 58 | struct rev_info rev; |
| 59 | 59 | struct commit *commit; |
| 60 | − const char *argv[3] = {NULL, tip, NULL}; | |
| 60 | + const char *argv[] = {NULL, tip, NULL, NULL, NULL}; | |
| 61 | 61 | int argc = 2; |
| 62 | 62 | int i; |
| 63 | 63 | |
| 64 | 64 | if (grep) |
| 65 | 65 | argv[argc++] = fmt("--grep=%s", grep); |
| 66 | + if (path) { | |
| 67 | + argv[argc++] = "--"; | |
| 68 | + argv[argc++] = path; | |
| 69 | + } | |
| 66 | 70 | init_revisions(&rev, NULL); |
| 67 | 71 | rev.abbrev = DEFAULT_ABBREV; |
| 68 | 72 | rev.commit_format = CMIT_FMT_DEFAULT; |
| @@ -8,9 +8,10 @@ · 7 unmodified lines | ||
| 8 | 8 | |
| 9 | 9 | #include "cgit.h" |
| 10 | 10 | |
| 11 | +char *curr_rev; | |
| 11 | 12 | |
| 12 | −static int print_entry(const unsigned char *sha1, const char *base, | |
| 13 | − int baselen, const char *pathname, unsigned int mode, | |
| 13 | +static int print_entry(const unsigned char *sha1, const char *base, | |
| 14 | + int baselen, const char *pathname, unsigned int mode, | |
| 14 | 15 | int stage) |
| 15 | 16 | { |
| 16 | 17 | char *name; |
| @@ -35,30 +36,41 @@ static int print_entry(const unsigned char *sha1, const char *base, · 18 unmodified lines | ||
| 35 | 36 | sha1_to_hex(sha1))); |
| 36 | 37 | } else if (S_ISDIR(mode)) { |
| 37 | 38 | html("class='ls-dir'><a href='"); |
| 38 | − html_attr(cgit_pageurl(cgit_query_repo, "tree", | |
| 39 | − fmt("id=%s&path=%s%s/", | |
| 39 | + html_attr(cgit_pageurl(cgit_query_repo, "tree", | |
| 40 | + fmt("h=%s&id=%s&path=%s%s/", | |
| 41 | + curr_rev, | |
| 40 | 42 | sha1_to_hex(sha1), |
| 41 | 43 | cgit_query_path ? cgit_query_path : "", |
| 42 | 44 | pathname))); |
| 43 | 45 | } else { |
| 44 | 46 | html("class='ls-blob'><a href='"); |
| 45 | 47 | html_attr(cgit_pageurl(cgit_query_repo, "view", |
| 46 | − fmt("id=%s&path=%s%s", sha1_to_hex(sha1), | |
| 48 | + fmt("h=%s&id=%s&path=%s%s", curr_rev, | |
| 49 | + sha1_to_hex(sha1), | |
| 47 | 50 | cgit_query_path ? cgit_query_path : "", |
| 48 | 51 | pathname))); |
| 49 | 52 | } |
| 50 | 53 | htmlf("'>%s</a></div></td>", name); |
| 51 | 54 | htmlf("<td class='filesize'>%li</td>", size); |
| 55 | + | |
| 56 | + html("<td class='links'><a href='"); | |
| 57 | + html_attr(cgit_pageurl(cgit_query_repo, "log", | |
| 58 | + fmt("h=%s&path=%s%s", | |
| 59 | + curr_rev, | |
| 60 | + cgit_query_path ? cgit_query_path : "", | |
| 61 | + pathname))); | |
| 62 | + html("'>history</a></td>"); | |
| 52 | 63 | html("</tr>\n"); |
| 53 | 64 | free(name); |
| 54 | 65 | return 0; |
| 55 | 66 | } |
| 56 | 67 | |
| 57 | −void cgit_print_tree(const char *hex, char *path) | |
| 68 | +void cgit_print_tree(const char *rev, const char *hex, char *path) | |
| 58 | 69 | { |
| 59 | 70 | struct tree *tree; |
| 60 | 71 | unsigned char sha1[20]; |
| 61 | 72 | |
| 73 | + curr_rev = xstrdup(rev); | |
| 62 | 74 | if (get_sha1_hex(hex, sha1)) { |
| 63 | 75 | cgit_print_error(fmt("Invalid object id: %s", hex)); |
| 64 | 76 | return; |
| @@ -75,6 +87,7 @@ void cgit_print_tree(const char *hex, char *path) · 10 unmodified lines | ||
| 75 | 87 | html("<th class='left'>Mode</th>"); |
| 76 | 88 | html("<th class='left'>Name</th>"); |
| 77 | 89 | html("<th class='right'>Size</th>"); |
| 90 | + html("<th/>"); | |
| 78 | 91 | html("</tr>\n"); |
| 79 | 92 | read_tree_recursive(tree, "", 0, 1, NULL, print_entry); |
| 80 | 93 | html("</table>\n"); |