History

Add log filtering by path and link to it from tree view

This enables path-filtering in log-view, and adds a link per entry in tree-view to show the log for each file/directory.

Lars Hjemli committed 19 years ago

Commit 9fb53af1 parent 4fdf5716 files · +37 −13Browse files

Unified · Split

6 files
  1. cgit.c +3 −2
  2. cgit.css +5 −0
  3. cgit.h +2 −2
  4. ui-commit.c +2 −1
  5. ui-log.c +6 −2
  6. ui-tree.c +19 −6
cgit.c+3−2
@@ -108,9 +108,10 @@ static void cgit_print_repo_page(struct cacheitem *item) · 107 unmodified lines
108108
109109 if (!strcmp(cgit_query_page, "log")) {
110110 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);
112113 } 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);
114115 } else if (!strcmp(cgit_query_page, "commit")) {
115116 cgit_print_commit(cgit_query_sha1);
116117 } else if (!strcmp(cgit_query_page, "view")) {
cgit.css+5−0
@@ -189,6 +189,11 @@ td.filesize { · 188 unmodified lines
189189 font-family: monospace;
190190 }
191191
192+td.links {
193+ font-size: 80%;
194+ padding-left: 2em;
195+}
196+
192197 td.filemode {
193198 font-family: monospace;
194199 }
cgit.h+2−2
@@ -169,10 +169,10 @@ extern void cgit_print_snapshot_start(const char *mimetype, · 168 unmodified lines
169169
170170 extern void cgit_print_repolist(struct cacheitem *item);
171171 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);
173173 extern void cgit_print_view(const char *hex, char *path);
174174 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);
176176 extern void cgit_print_commit(const char *hex);
177177 extern void cgit_print_diff(const char *old_hex, const char *new_hex, char *path);
178178 extern void cgit_print_snapshot(struct cacheitem *item, const char *hex,
ui-commit.c+2−1
@@ -186,7 +186,8 @@ void cgit_print_commit(const char *hex) · 185 unmodified lines
186186 cgit_print_date(info->committer_date);
187187 html("</td></tr>\n");
188188 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));
190191 html_attr(cgit_pageurl(cgit_query_repo, "tree", query));
191192 htmlf("'>%s</a></td></tr>\n", sha1_to_hex(commit->tree->object.sha1));
192193 for (p = commit->parents; p ; p = p->next) {
ui-log.c+6−2
@@ -53,16 +53,20 @@ void print_commit(struct commit *commit) · 52 unmodified lines
5353 }
5454
5555
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)
5757 {
5858 struct rev_info rev;
5959 struct commit *commit;
60− const char *argv[3] = {NULL, tip, NULL};
60+ const char *argv[] = {NULL, tip, NULL, NULL, NULL};
6161 int argc = 2;
6262 int i;
6363
6464 if (grep)
6565 argv[argc++] = fmt("--grep=%s", grep);
66+ if (path) {
67+ argv[argc++] = "--";
68+ argv[argc++] = path;
69+ }
6670 init_revisions(&rev, NULL);
6771 rev.abbrev = DEFAULT_ABBREV;
6872 rev.commit_format = CMIT_FMT_DEFAULT;
ui-tree.c+19−6
@@ -8,9 +8,10 @@ · 7 unmodified lines
88
99 #include "cgit.h"
1010
11+char *curr_rev;
1112
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,
1415 int stage)
1516 {
1617 char *name;
@@ -35,30 +36,41 @@ static int print_entry(const unsigned char *sha1, const char *base, · 18 unmodified lines
3536 sha1_to_hex(sha1)));
3637 } else if (S_ISDIR(mode)) {
3738 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,
4042 sha1_to_hex(sha1),
4143 cgit_query_path ? cgit_query_path : "",
4244 pathname)));
4345 } else {
4446 html("class='ls-blob'><a href='");
4547 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),
4750 cgit_query_path ? cgit_query_path : "",
4851 pathname)));
4952 }
5053 htmlf("'>%s</a></div></td>", name);
5154 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>");
5263 html("</tr>\n");
5364 free(name);
5465 return 0;
5566 }
5667
57−void cgit_print_tree(const char *hex, char *path)
68+void cgit_print_tree(const char *rev, const char *hex, char *path)
5869 {
5970 struct tree *tree;
6071 unsigned char sha1[20];
6172
73+ curr_rev = xstrdup(rev);
6274 if (get_sha1_hex(hex, sha1)) {
6375 cgit_print_error(fmt("Invalid object id: %s", hex));
6476 return;
@@ -75,6 +87,7 @@ void cgit_print_tree(const char *hex, char *path) · 10 unmodified lines
7587 html("<th class='left'>Mode</th>");
7688 html("<th class='left'>Name</th>");
7789 html("<th class='right'>Size</th>");
90+ html("<th/>");
7891 html("</tr>\n");
7992 read_tree_recursive(tree, "", 0, 1, NULL, print_entry);
8093 html("</table>\n");

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t