summaryrefslogtreecommitdiffabout
path: root/ui-log.c
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) (unidiff)
tree3ebbebebed59b53066e16720a32e1b34c54dc609 /ui-log.c
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 (limited to 'ui-log.c') (more/less context) (ignore whitespace changes)
-rw-r--r--ui-log.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/ui-log.c b/ui-log.c
index 7d1985e..6d5509b 100644
--- a/ui-log.c
+++ b/ui-log.c
@@ -1,120 +1,124 @@
1/* ui-log.c: functions for log output 1/* ui-log.c: functions for log output
2 * 2 *
3 * Copyright (C) 2006 Lars Hjemli 3 * Copyright (C) 2006 Lars Hjemli
4 * 4 *
5 * Licensed under GNU General Public License v2 5 * Licensed under GNU General Public License v2
6 * (see COPYING for full license text) 6 * (see COPYING for full license text)
7 */ 7 */
8 8
9#include "cgit.h" 9#include "cgit.h"
10 10
11int files, lines; 11int files, lines;
12 12
13void count_lines(char *line, int size) 13void count_lines(char *line, int size)
14{ 14{
15 if (size>0 && (line[0] == '+' || line[0] == '-')) 15 if (size>0 && (line[0] == '+' || line[0] == '-'))
16 lines++; 16 lines++;
17} 17}
18 18
19void inspect_files(struct diff_filepair *pair) 19void inspect_files(struct diff_filepair *pair)
20{ 20{
21 files++; 21 files++;
22 cgit_diff_files(pair->one->sha1, pair->two->sha1, count_lines); 22 cgit_diff_files(pair->one->sha1, pair->two->sha1, count_lines);
23} 23}
24 24
25void print_commit(struct commit *commit) 25void print_commit(struct commit *commit)
26{ 26{
27 char buf[32]; 27 char buf[32];
28 struct commitinfo *info; 28 struct commitinfo *info;
29 struct tm *time; 29 struct tm *time;
30 30
31 info = cgit_parse_commit(commit); 31 info = cgit_parse_commit(commit);
32 time = gmtime(&commit->date); 32 time = gmtime(&commit->date);
33 html("<tr><td>"); 33 html("<tr><td>");
34 strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M", time); 34 strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M", time);
35 html_txt(buf); 35 html_txt(buf);
36 html("</td><td>"); 36 html("</td><td>");
37 char *qry = fmt("id=%s", sha1_to_hex(commit->object.sha1)); 37 char *qry = fmt("id=%s", sha1_to_hex(commit->object.sha1));
38 char *url = cgit_pageurl(cgit_query_repo, "commit", qry); 38 char *url = cgit_pageurl(cgit_query_repo, "commit", qry);
39 html_link_open(url, NULL, NULL); 39 html_link_open(url, NULL, NULL);
40 html_ntxt(cgit_max_msg_len, info->subject); 40 html_ntxt(cgit_max_msg_len, info->subject);
41 html_link_close(); 41 html_link_close();
42 files = 0; 42 files = 0;
43 lines = 0; 43 lines = 0;
44 cgit_diff_commit(commit, inspect_files); 44 cgit_diff_commit(commit, inspect_files);
45 html("</td><td class='right'>"); 45 html("</td><td class='right'>");
46 htmlf("%d", files); 46 htmlf("%d", files);
47 html("</td><td class='right'>"); 47 html("</td><td class='right'>");
48 htmlf("%d", lines); 48 htmlf("%d", lines);
49 html("</td><td>"); 49 html("</td><td>");
50 html_txt(info->author); 50 html_txt(info->author);
51 html("</td></tr>\n"); 51 html("</td></tr>\n");
52 cgit_free_commitinfo(info); 52 cgit_free_commitinfo(info);
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;
69 rev.verbose_header = 1; 73 rev.verbose_header = 1;
70 rev.show_root_diff = 0; 74 rev.show_root_diff = 0;
71 setup_revisions(argc, argv, &rev, NULL); 75 setup_revisions(argc, argv, &rev, NULL);
72 if (rev.grep_filter) { 76 if (rev.grep_filter) {
73 rev.grep_filter->regflags |= REG_ICASE; 77 rev.grep_filter->regflags |= REG_ICASE;
74 compile_grep_patterns(rev.grep_filter); 78 compile_grep_patterns(rev.grep_filter);
75 } 79 }
76 prepare_revision_walk(&rev); 80 prepare_revision_walk(&rev);
77 81
78 html("<table class='list nowrap'>"); 82 html("<table class='list nowrap'>");
79 html("<tr class='nohover'><th class='left'>Date</th>" 83 html("<tr class='nohover'><th class='left'>Date</th>"
80 "<th class='left'>Message</th>" 84 "<th class='left'>Message</th>"
81 "<th class='left'>Files</th>" 85 "<th class='left'>Files</th>"
82 "<th class='left'>Lines</th>" 86 "<th class='left'>Lines</th>"
83 "<th class='left'>Author</th></tr>\n"); 87 "<th class='left'>Author</th></tr>\n");
84 88
85 if (ofs<0) 89 if (ofs<0)
86 ofs = 0; 90 ofs = 0;
87 91
88 for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; i++) { 92 for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; i++) {
89 free(commit->buffer); 93 free(commit->buffer);
90 commit->buffer = NULL; 94 commit->buffer = NULL;
91 free_commit_list(commit->parents); 95 free_commit_list(commit->parents);
92 commit->parents = NULL; 96 commit->parents = NULL;
93 } 97 }
94 98
95 for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) { 99 for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) {
96 print_commit(commit); 100 print_commit(commit);
97 free(commit->buffer); 101 free(commit->buffer);
98 commit->buffer = NULL; 102 commit->buffer = NULL;
99 free_commit_list(commit->parents); 103 free_commit_list(commit->parents);
100 commit->parents = NULL; 104 commit->parents = NULL;
101 } 105 }
102 html("</table>\n"); 106 html("</table>\n");
103 107
104 html("<div class='pager'>"); 108 html("<div class='pager'>");
105 if (ofs > 0) { 109 if (ofs > 0) {
106 html("&nbsp;<a href='"); 110 html("&nbsp;<a href='");
107 html(cgit_pageurl(cgit_query_repo, cgit_query_page, 111 html(cgit_pageurl(cgit_query_repo, cgit_query_page,
108 fmt("h=%s&ofs=%d", tip, ofs-cnt))); 112 fmt("h=%s&ofs=%d", tip, ofs-cnt)));
109 html("'>[prev]</a>&nbsp;"); 113 html("'>[prev]</a>&nbsp;");
110 } 114 }
111 115
112 if ((commit = get_revision(&rev)) != NULL) { 116 if ((commit = get_revision(&rev)) != NULL) {
113 html("&nbsp;<a href='"); 117 html("&nbsp;<a href='");
114 html(cgit_pageurl(cgit_query_repo, "log", 118 html(cgit_pageurl(cgit_query_repo, "log",
115 fmt("h=%s&ofs=%d", tip, ofs+cnt))); 119 fmt("h=%s&ofs=%d", tip, ofs+cnt)));
116 html("'>[next]</a>&nbsp;"); 120 html("'>[next]</a>&nbsp;");
117 } 121 }
118 html("</div>"); 122 html("</div>");
119} 123}
120 124