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