summaryrefslogtreecommitdiffabout
authorLars Hjemli <hjemli@gmail.com>2007-05-14 09:10:59 (UTC)
committer Lars Hjemli <hjemli@gmail.com>2007-05-14 09:13:18 (UTC)
commit9fb53af215639fcd3bfb876fa9c8bac221244bdf (patch) (side-by-side diff)
tree3ebbebebed59b53066e16720a32e1b34c54dc609
parent4fdf571c888fd38ae362684c429a3bdf24240ef7 (diff)
downloadcgit-9fb53af215639fcd3bfb876fa9c8bac221244bdf.zip
cgit-9fb53af215639fcd3bfb876fa9c8bac221244bdf.tar.gz
cgit-9fb53af215639fcd3bfb876fa9c8bac221244bdf.tar.bz2
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. Signed-off-by: Lars Hjemli <hjemli@gmail.com>
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--cgit.c5
-rw-r--r--cgit.css5
-rw-r--r--cgit.h4
-rw-r--r--ui-commit.c3
-rw-r--r--ui-log.c8
-rw-r--r--ui-tree.c25
6 files changed, 37 insertions, 13 deletions
diff --git a/cgit.c b/cgit.c
index 3d85a08..9e63d18 100644
--- a/cgit.c
+++ b/cgit.c
@@ -87,51 +87,52 @@ static void cgit_print_repo_page(struct cacheitem *item)
}
if (!strcmp(cgit_query_page, "blob")) {
cgit_print_blob(item, cgit_query_sha1, cgit_query_path);
return;
}
}
if (cgit_query_page && !strcmp(cgit_query_page, "log"))
show_search = 1;
cgit_print_docstart(title, item);
if (!cgit_query_page) {
cgit_print_pageheader("summary", show_search);
cgit_print_summary();
cgit_print_docend();
return;
}
cgit_print_pageheader(cgit_query_page, show_search);
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")) {
cgit_print_view(cgit_query_sha1, cgit_query_path);
} else if (!strcmp(cgit_query_page, "diff")) {
cgit_print_diff(cgit_query_sha1, cgit_query_sha2, cgit_query_path);
} else {
cgit_print_error("Invalid request");
}
cgit_print_docend();
}
static void cgit_fill_cache(struct cacheitem *item, int use_cache)
{
static char buf[PATH_MAX];
int stdout2;
getcwd(buf, sizeof(buf));
item->st.st_mtime = time(NULL);
if (use_cache) {
stdout2 = chk_positive(dup(STDOUT_FILENO),
"Preserving STDOUT");
chk_zero(close(STDOUT_FILENO), "Closing STDOUT");
diff --git a/cgit.css b/cgit.css
index fe0ba50..6231e28 100644
--- a/cgit.css
+++ b/cgit.css
@@ -168,48 +168,53 @@ div#blob {
}
div.error {
color: red;
font-weight: bold;
margin: 1em 2em;
}
td.ls-blob, td.ls-dir, td.ls-mod {
font-family: monospace;
}
div.ls-dir a {
font-weight: bold;
}
th.filesize, td.filesize {
text-align: right;
}
td.filesize {
font-family: monospace;
}
+td.links {
+ font-size: 80%;
+ padding-left: 2em;
+}
+
td.filemode {
font-family: monospace;
}
td.blob {
white-space: pre;
font-family: monospace;
background-color: white;
}
table.nowrap td {
white-space: nowrap;
}
table.commit-info {
border-collapse: collapse;
margin-top: 1.5em;
}
table.commit-info th {
text-align: left;
font-weight: normal;
padding: 0.1em 1em 0.1em 0.1em;
}
diff --git a/cgit.h b/cgit.h
index 93699b5..0fff7b0 100644
--- a/cgit.h
+++ b/cgit.h
@@ -148,35 +148,35 @@ extern struct commitinfo *cgit_parse_commit(struct commit *commit);
extern struct taginfo *cgit_parse_tag(struct tag *tag);
extern char *cache_safe_filename(const char *unsafe);
extern int cache_lock(struct cacheitem *item);
extern int cache_unlock(struct cacheitem *item);
extern int cache_cancel_lock(struct cacheitem *item);
extern int cache_exist(struct cacheitem *item);
extern int cache_expired(struct cacheitem *item);
extern char *cgit_repourl(const char *reponame);
extern char *cgit_pageurl(const char *reponame, const char *pagename,
const char *query);
extern void cgit_print_error(char *msg);
extern void cgit_print_date(unsigned long secs);
extern void cgit_print_docstart(char *title, struct cacheitem *item);
extern void cgit_print_docend();
extern void cgit_print_pageheader(char *title, int show_search);
extern void cgit_print_snapshot_start(const char *mimetype,
const char *filename,
struct cacheitem *item);
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,
const char *format, const char *prefix,
const char *filename);
#endif /* CGIT_H */
diff --git a/ui-commit.c b/ui-commit.c
index b3d1c28..20a7cb2 100644
--- a/ui-commit.c
+++ b/ui-commit.c
@@ -165,49 +165,50 @@ void cgit_print_commit(const char *hex)
}
commit = lookup_commit_reference(sha1);
if (!commit) {
cgit_print_error(fmt("Bad commit reference: %s", hex));
return;
}
info = cgit_parse_commit(commit);
html("<table class='commit-info'>\n");
html("<tr><th>author</th><td>");
html_txt(info->author);
html(" ");
html_txt(info->author_email);
html("</td><td class='right'>");
cgit_print_date(info->author_date);
html("</td></tr>\n");
html("<tr><th>committer</th><td>");
html_txt(info->committer);
html(" ");
html_txt(info->committer_email);
html("</td><td class='right'>");
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) {
parent = lookup_commit_reference(p->item->object.sha1);
if (!parent) {
html("<tr><td colspan='3'>");
cgit_print_error("Error reading parent commit");
html("</td></tr>");
continue;
}
html("<tr><th>parent</th>"
"<td colspan='2' class='sha1'>"
"<a href='");
query = fmt("id=%s", sha1_to_hex(p->item->object.sha1));
html_attr(cgit_pageurl(cgit_query_repo, "commit", query));
htmlf("'>%s</a> (<a href='",
sha1_to_hex(p->item->object.sha1));
query = fmt("id=%s&id2=%s", sha1_to_hex(parent->tree->object.sha1),
sha1_to_hex(commit->tree->object.sha1));
html_attr(cgit_pageurl(cgit_query_repo, "diff", query));
html("'>diff</a>)</td></tr>");
}
if (cgit_repo->snapshots) {
htmlf("<tr><th>download</th><td colspan='2' class='sha1'><a href='");
diff --git a/ui-log.c b/ui-log.c
index 7d1985e..6d5509b 100644
--- a/ui-log.c
+++ b/ui-log.c
@@ -32,58 +32,62 @@ void print_commit(struct commit *commit)
time = gmtime(&commit->date);
html("<tr><td>");
strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M", time);
html_txt(buf);
html("</td><td>");
char *qry = fmt("id=%s", sha1_to_hex(commit->object.sha1));
char *url = cgit_pageurl(cgit_query_repo, "commit", qry);
html_link_open(url, NULL, NULL);
html_ntxt(cgit_max_msg_len, info->subject);
html_link_close();
files = 0;
lines = 0;
cgit_diff_commit(commit, inspect_files);
html("</td><td class='right'>");
htmlf("%d", files);
html("</td><td class='right'>");
htmlf("%d", lines);
html("</td><td>");
html_txt(info->author);
html("</td></tr>\n");
cgit_free_commitinfo(info);
}
-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;
rev.verbose_header = 1;
rev.show_root_diff = 0;
setup_revisions(argc, argv, &rev, NULL);
if (rev.grep_filter) {
rev.grep_filter->regflags |= REG_ICASE;
compile_grep_patterns(rev.grep_filter);
}
prepare_revision_walk(&rev);
html("<table class='list nowrap'>");
html("<tr class='nohover'><th class='left'>Date</th>"
"<th class='left'>Message</th>"
"<th class='left'>Files</th>"
"<th class='left'>Lines</th>"
"<th class='left'>Author</th></tr>\n");
if (ofs<0)
ofs = 0;
for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; i++) {
free(commit->buffer);
diff --git a/ui-tree.c b/ui-tree.c
index dee8309..db63e13 100644
--- a/ui-tree.c
+++ b/ui-tree.c
@@ -1,81 +1,94 @@
/* ui-tree.c: functions for tree output
*
* Copyright (C) 2006 Lars Hjemli
*
* Licensed under GNU General Public License v2
* (see COPYING for full license text)
*/
#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;
enum object_type type;
unsigned long size = 0;
name = xstrdup(pathname);
type = sha1_object_info(sha1, &size);
if (type == OBJ_BAD && !S_ISDIRLNK(mode)) {
htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>",
name,
sha1_to_hex(sha1));
return 0;
}
html("<tr><td class='filemode'>");
html_filemode(mode);
html("</td><td ");
if (S_ISDIRLNK(mode)) {
htmlf("class='ls-mod'><a href='");
html_attr(fmt(cgit_repo->module_link,
name,
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;
}
tree = parse_tree_indirect(sha1);
if (!tree) {
cgit_print_error(fmt("Not a tree object: %s", hex));
return;
}
html_txt(path);
html("<table class='list'>\n");
html("<tr class='nohover'>");
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");
}