]> gitweb.ps.run Git - ps-cgit/commitdiff
Add log filtering by path and link to it from tree view
authorLars Hjemli <hjemli@gmail.com>
Mon, 14 May 2007 09:10:59 +0000 (11:10 +0200)
committerLars Hjemli <hjemli@gmail.com>
Mon, 14 May 2007 09:13:18 +0000 (11:13 +0200)
This enables path-filtering in log-view, and adds a link per entry in
tree-view to show the log for each file/directory.

Signed-off-by: Lars Hjemli <hjemli@gmail.com>
cgit.c
cgit.css
cgit.h
ui-commit.c
ui-log.c
ui-tree.c

diff --git a/cgit.c b/cgit.c
index 3d85a08766c99d536d290e0621e85f71a2fd579e..9e63d185d5dde00a347f13ccf1fed7efc5dec6b2 100644 (file)
--- a/cgit.c
+++ b/cgit.c
@@ -108,9 +108,10 @@ static void cgit_print_repo_page(struct cacheitem *item)
 
        if (!strcmp(cgit_query_page, "log")) {
                cgit_print_log(cgit_query_head, cgit_query_ofs,
-                              cgit_max_commit_count, cgit_query_search);
+                              cgit_max_commit_count, cgit_query_search,
+                              cgit_query_path);
        } else if (!strcmp(cgit_query_page, "tree")) {
-               cgit_print_tree(cgit_query_sha1, cgit_query_path);
+               cgit_print_tree(cgit_query_head, cgit_query_sha1, cgit_query_path);
        } else if (!strcmp(cgit_query_page, "commit")) {
                cgit_print_commit(cgit_query_sha1);
        } else if (!strcmp(cgit_query_page, "view")) {
index fe0ba50a55e637f90fa291c525a3275e32368fc9..6231e28db0a89d3b61d361a1e1619c3f5cb90a13 100644 (file)
--- a/cgit.css
+++ b/cgit.css
@@ -189,6 +189,11 @@ td.filesize {
        font-family: monospace;
 }
 
+td.links {
+       font-size: 80%;
+       padding-left: 2em;
+}
+
 td.filemode {
        font-family: monospace;
 }
diff --git a/cgit.h b/cgit.h
index 93699b5412242534a49d9586604f7de7df0fd659..0fff7b084bb7e24c41ca8b54ab32dfaa6d9ae6a4 100644 (file)
--- a/cgit.h
+++ b/cgit.h
@@ -169,10 +169,10 @@ extern void cgit_print_snapshot_start(const char *mimetype,
 
 extern void cgit_print_repolist(struct cacheitem *item);
 extern void cgit_print_summary();
-extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep);
+extern void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *path);
 extern void cgit_print_view(const char *hex, char *path);
 extern void cgit_print_blob(struct cacheitem *item, const char *hex, char *path);
-extern void cgit_print_tree(const char *hex, char *path);
+extern void cgit_print_tree(const char *rev, const char *hex, char *path);
 extern void cgit_print_commit(const char *hex);
 extern void cgit_print_diff(const char *old_hex, const char *new_hex, char *path);
 extern void cgit_print_snapshot(struct cacheitem *item, const char *hex, 
index b3d1c28c2c188b7a2357058582cf9db8095348ed..20a7cb2259d978c72dab0084c1f4dd091c857176 100644 (file)
@@ -186,7 +186,8 @@ void cgit_print_commit(const char *hex)
        cgit_print_date(info->committer_date);
        html("</td></tr>\n");
        html("<tr><th>tree</th><td colspan='2' class='sha1'><a href='");
-       query = fmt("id=%s", sha1_to_hex(commit->tree->object.sha1));
+       query = fmt("h=%s&id=%s", sha1_to_hex(commit->object.sha1),
+                   sha1_to_hex(commit->tree->object.sha1));
        html_attr(cgit_pageurl(cgit_query_repo, "tree", query));
        htmlf("'>%s</a></td></tr>\n", sha1_to_hex(commit->tree->object.sha1));
        for (p = commit->parents; p ; p = p->next) {
index 7d1985e94ab9c60d3d72ce3bc5cd540ede84f1b9..6d5509bd3bce42e795a2c640c47a916e0085a277 100644 (file)
--- a/ui-log.c
+++ b/ui-log.c
@@ -53,16 +53,20 @@ void print_commit(struct commit *commit)
 }
 
 
-void cgit_print_log(const char *tip, int ofs, int cnt, char *grep)
+void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *path)
 {
        struct rev_info rev;
        struct commit *commit;
-       const char *argv[3] = {NULL, tip, NULL};
+       const char *argv[] = {NULL, tip, NULL, NULL, NULL};
        int argc = 2;
        int i;
 
        if (grep)
                argv[argc++] = fmt("--grep=%s", grep);
+       if (path) {
+               argv[argc++] = "--";
+               argv[argc++] = path;
+       }
        init_revisions(&rev, NULL);
        rev.abbrev = DEFAULT_ABBREV;
        rev.commit_format = CMIT_FMT_DEFAULT;
index dee83098c93a0113a9feb24b4aa364fc13cc1c40..db63e13fe7e2b5d13d28f55c75345a79bd0422e7 100644 (file)
--- a/ui-tree.c
+++ b/ui-tree.c
@@ -8,9 +8,10 @@
 
 #include "cgit.h"
 
+char *curr_rev;
 
-static int print_entry(const unsigned char *sha1, const char *base, 
-                      int baselen, const char *pathname, unsigned int mode, 
+static int print_entry(const unsigned char *sha1, const char *base,
+                      int baselen, const char *pathname, unsigned int mode,
                       int stage)
 {
        char *name;
@@ -35,30 +36,41 @@ static int print_entry(const unsigned char *sha1, const char *base,
                              sha1_to_hex(sha1)));
        } else if (S_ISDIR(mode)) {
                html("class='ls-dir'><a href='");
-               html_attr(cgit_pageurl(cgit_query_repo, "tree", 
-                                      fmt("id=%s&path=%s%s/", 
+               html_attr(cgit_pageurl(cgit_query_repo, "tree",
+                                      fmt("h=%s&id=%s&path=%s%s/",
+                                          curr_rev,
                                           sha1_to_hex(sha1),
                                           cgit_query_path ? cgit_query_path : "",
                                           pathname)));
        } else {
                html("class='ls-blob'><a href='");
                html_attr(cgit_pageurl(cgit_query_repo, "view",
-                                     fmt("id=%s&path=%s%s", sha1_to_hex(sha1),
+                                     fmt("h=%s&id=%s&path=%s%s", curr_rev,
+                                         sha1_to_hex(sha1),
                                          cgit_query_path ? cgit_query_path : "",
                                          pathname)));
        }
        htmlf("'>%s</a></div></td>", name);
        htmlf("<td class='filesize'>%li</td>", size);
+
+       html("<td class='links'><a href='");
+       html_attr(cgit_pageurl(cgit_query_repo, "log",
+                              fmt("h=%s&path=%s%s",
+                                  curr_rev,
+                                  cgit_query_path ? cgit_query_path : "",
+                                  pathname)));
+       html("'>history</a></td>");
        html("</tr>\n");
        free(name);
        return 0;
 }
 
-void cgit_print_tree(const char *hex, char *path)
+void cgit_print_tree(const char *rev, const char *hex, char *path)
 {
        struct tree *tree;
        unsigned char sha1[20];
 
+       curr_rev = xstrdup(rev);
        if (get_sha1_hex(hex, sha1)) {
                cgit_print_error(fmt("Invalid object id: %s", hex));
                return;
@@ -75,6 +87,7 @@ void cgit_print_tree(const char *hex, char *path)
        html("<th class='left'>Mode</th>");
        html("<th class='left'>Name</th>");
        html("<th class='right'>Size</th>");
+       html("<th/>");
        html("</tr>\n");
        read_tree_recursive(tree, "", 0, 1, NULL, print_entry);
        html("</table>\n");