summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--ui-log.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/ui-log.c b/ui-log.c
index b930bb2..7d1985e 100644
--- a/ui-log.c
+++ b/ui-log.c
@@ -1,110 +1,120 @@
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)
14{
15 if (size>0 && (line[0] == '+' || line[0] == '-'))
16 lines++;
17}
18
13void inspect_files(struct diff_filepair *pair) 19void inspect_files(struct diff_filepair *pair)
14{ 20{
15 files++; 21 files++;
22 cgit_diff_files(pair->one->sha1, pair->two->sha1, count_lines);
16} 23}
17 24
18void print_commit(struct commit *commit) 25void print_commit(struct commit *commit)
19{ 26{
20 char buf[32]; 27 char buf[32];
21 struct commitinfo *info; 28 struct commitinfo *info;
22 struct tm *time; 29 struct tm *time;
23 30
24 info = cgit_parse_commit(commit); 31 info = cgit_parse_commit(commit);
25 time = gmtime(&commit->date); 32 time = gmtime(&commit->date);
26 html("<tr><td>"); 33 html("<tr><td>");
27 strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M", time); 34 strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M", time);
28 html_txt(buf); 35 html_txt(buf);
29 html("</td><td>"); 36 html("</td><td>");
30 char *qry = fmt("id=%s", sha1_to_hex(commit->object.sha1)); 37 char *qry = fmt("id=%s", sha1_to_hex(commit->object.sha1));
31 char *url = cgit_pageurl(cgit_query_repo, "commit", qry); 38 char *url = cgit_pageurl(cgit_query_repo, "commit", qry);
32 html_link_open(url, NULL, NULL); 39 html_link_open(url, NULL, NULL);
33 html_ntxt(cgit_max_msg_len, info->subject); 40 html_ntxt(cgit_max_msg_len, info->subject);
34 html_link_close(); 41 html_link_close();
35 html("</td><td class='right'>");
36 files = 0; 42 files = 0;
37 lines = 0; 43 lines = 0;
38 cgit_diff_commit(commit, inspect_files); 44 cgit_diff_commit(commit, inspect_files);
45 html("</td><td class='right'>");
39 htmlf("%d", files); 46 htmlf("%d", files);
47 html("</td><td class='right'>");
48 htmlf("%d", lines);
40 html("</td><td>"); 49 html("</td><td>");
41 html_txt(info->author); 50 html_txt(info->author);
42 html("</td></tr>\n"); 51 html("</td></tr>\n");
43 cgit_free_commitinfo(info); 52 cgit_free_commitinfo(info);
44} 53}
45 54
46 55
47void 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)
48{ 57{
49 struct rev_info rev; 58 struct rev_info rev;
50 struct commit *commit; 59 struct commit *commit;
51 const char *argv[3] = {NULL, tip, NULL}; 60 const char *argv[3] = {NULL, tip, NULL};
52 int argc = 2; 61 int argc = 2;
53 int i; 62 int i;
54 63
55 if (grep) 64 if (grep)
56 argv[argc++] = fmt("--grep=%s", grep); 65 argv[argc++] = fmt("--grep=%s", grep);
57 init_revisions(&rev, NULL); 66 init_revisions(&rev, NULL);
58 rev.abbrev = DEFAULT_ABBREV; 67 rev.abbrev = DEFAULT_ABBREV;
59 rev.commit_format = CMIT_FMT_DEFAULT; 68 rev.commit_format = CMIT_FMT_DEFAULT;
60 rev.verbose_header = 1; 69 rev.verbose_header = 1;
61 rev.show_root_diff = 0; 70 rev.show_root_diff = 0;
62 setup_revisions(argc, argv, &rev, NULL); 71 setup_revisions(argc, argv, &rev, NULL);
63 if (rev.grep_filter) { 72 if (rev.grep_filter) {
64 rev.grep_filter->regflags |= REG_ICASE; 73 rev.grep_filter->regflags |= REG_ICASE;
65 compile_grep_patterns(rev.grep_filter); 74 compile_grep_patterns(rev.grep_filter);
66 } 75 }
67 prepare_revision_walk(&rev); 76 prepare_revision_walk(&rev);
68 77
69 html("<table class='list nowrap'>"); 78 html("<table class='list nowrap'>");
70 html("<tr class='nohover'><th class='left'>Date</th>" 79 html("<tr class='nohover'><th class='left'>Date</th>"
71 "<th class='left'>Message</th>" 80 "<th class='left'>Message</th>"
72 "<th class='left'>Files</th>" 81 "<th class='left'>Files</th>"
82 "<th class='left'>Lines</th>"
73 "<th class='left'>Author</th></tr>\n"); 83 "<th class='left'>Author</th></tr>\n");
74 84
75 if (ofs<0) 85 if (ofs<0)
76 ofs = 0; 86 ofs = 0;
77 87
78 for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; i++) { 88 for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; i++) {
79 free(commit->buffer); 89 free(commit->buffer);
80 commit->buffer = NULL; 90 commit->buffer = NULL;
81 free_commit_list(commit->parents); 91 free_commit_list(commit->parents);
82 commit->parents = NULL; 92 commit->parents = NULL;
83 } 93 }
84 94
85 for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) { 95 for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) {
86 print_commit(commit); 96 print_commit(commit);
87 free(commit->buffer); 97 free(commit->buffer);
88 commit->buffer = NULL; 98 commit->buffer = NULL;
89 free_commit_list(commit->parents); 99 free_commit_list(commit->parents);
90 commit->parents = NULL; 100 commit->parents = NULL;
91 } 101 }
92 html("</table>\n"); 102 html("</table>\n");
93 103
94 html("<div class='pager'>"); 104 html("<div class='pager'>");
95 if (ofs > 0) { 105 if (ofs > 0) {
96 html("&nbsp;<a href='"); 106 html("&nbsp;<a href='");
97 html(cgit_pageurl(cgit_query_repo, cgit_query_page, 107 html(cgit_pageurl(cgit_query_repo, cgit_query_page,
98 fmt("h=%s&ofs=%d", tip, ofs-cnt))); 108 fmt("h=%s&ofs=%d", tip, ofs-cnt)));
99 html("'>[prev]</a>&nbsp;"); 109 html("'>[prev]</a>&nbsp;");
100 } 110 }
101 111
102 if ((commit = get_revision(&rev)) != NULL) { 112 if ((commit = get_revision(&rev)) != NULL) {
103 html("&nbsp;<a href='"); 113 html("&nbsp;<a href='");
104 html(cgit_pageurl(cgit_query_repo, "log", 114 html(cgit_pageurl(cgit_query_repo, "log",
105 fmt("h=%s&ofs=%d", tip, ofs+cnt))); 115 fmt("h=%s&ofs=%d", tip, ofs+cnt)));
106 html("'>[next]</a>&nbsp;"); 116 html("'>[next]</a>&nbsp;");
107 } 117 }
108 html("</div>"); 118 html("</div>");
109} 119}
110 120