blob: d38e40a17423cd507f63f3e4b0bfa5d77fb9c0f8 [file] [log] [blame]
Lars Hjemlid14c5f62006-12-11 17:04:19 +01001/* ui-log.c: functions for log output
2 *
3 * Copyright (C) 2006 Lars Hjemli
4 *
5 * Licensed under GNU General Public License v2
6 * (see COPYING for full license text)
7 */
8
9#include "cgit.h"
10
Lars Hjemli48dc0032007-05-13 11:27:46 +020011int files, lines;
12
Lars Hjemli80e577c2007-05-13 17:03:27 +020013void count_lines(char *line, int size)
14{
15 if (size>0 && (line[0] == '+' || line[0] == '-'))
16 lines++;
17}
18
Lars Hjemli48dc0032007-05-13 11:27:46 +020019void inspect_files(struct diff_filepair *pair)
20{
21 files++;
Lars Hjemlie1893442007-05-18 13:55:52 +020022 if (cgit_repo->enable_log_linecount)
23 cgit_diff_files(pair->one->sha1, pair->two->sha1, count_lines);
Lars Hjemli48dc0032007-05-13 11:27:46 +020024}
25
Lars Hjemli2101e262006-12-15 18:17:36 +010026void print_commit(struct commit *commit)
Lars Hjemlid14c5f62006-12-11 17:04:19 +010027{
Lars Hjemli2101e262006-12-15 18:17:36 +010028 struct commitinfo *info;
Lars Hjemlid14c5f62006-12-11 17:04:19 +010029
Lars Hjemli2101e262006-12-15 18:17:36 +010030 info = cgit_parse_commit(commit);
Lars Hjemlid14c5f62006-12-11 17:04:19 +010031 html("<tr><td>");
Lars Hjemli237ef7b2007-05-22 23:15:36 +020032 cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE);
Lars Hjemlid14c5f62006-12-11 17:04:19 +010033 html("</td><td>");
Lars Hjemli42a7eb92007-06-17 14:53:02 +020034 cgit_commit_link(info->subject, NULL, NULL, cgit_query_head,
35 sha1_to_hex(commit->object.sha1));
Lars Hjemlie1893442007-05-18 13:55:52 +020036 if (cgit_repo->enable_log_filecount) {
37 files = 0;
38 lines = 0;
39 cgit_diff_commit(commit, inspect_files);
40 html("</td><td class='right'>");
41 htmlf("%d", files);
42 if (cgit_repo->enable_log_linecount) {
43 html("</td><td class='right'>");
44 htmlf("%d", lines);
45 }
46 }
Lars Hjemlid14c5f62006-12-11 17:04:19 +010047 html("</td><td>");
Lars Hjemli2101e262006-12-15 18:17:36 +010048 html_txt(info->author);
Lars Hjemlid14c5f62006-12-11 17:04:19 +010049 html("</td></tr>\n");
Lars Hjemliaaa24bd2006-12-16 14:58:20 +010050 cgit_free_commitinfo(info);
Lars Hjemlid14c5f62006-12-11 17:04:19 +010051}
52
Lars Hjemli2101e262006-12-15 18:17:36 +010053
Ondrej Jirmana9226152007-05-26 03:26:14 +020054void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *path, int pager)
Lars Hjemlid14c5f62006-12-11 17:04:19 +010055{
56 struct rev_info rev;
57 struct commit *commit;
Lars Hjemli9fb53af2007-05-14 11:10:59 +020058 const char *argv[] = {NULL, tip, NULL, NULL, NULL};
Lars Hjemli732d68d2006-12-28 02:45:28 +010059 int argc = 2;
Lars Hjemli420712a2006-12-14 00:40:34 +010060 int i;
Lars Hjemli48dc0032007-05-13 11:27:46 +020061
Lars Hjemlicd79c162007-06-17 14:58:45 +020062 if (!tip)
63 argv[1] = cgit_query_head;
64
Lars Hjemli732d68d2006-12-28 02:45:28 +010065 if (grep)
66 argv[argc++] = fmt("--grep=%s", grep);
Lars Hjemli9fb53af2007-05-14 11:10:59 +020067 if (path) {
68 argv[argc++] = "--";
69 argv[argc++] = path;
70 }
Lars Hjemlid14c5f62006-12-11 17:04:19 +010071 init_revisions(&rev, NULL);
72 rev.abbrev = DEFAULT_ABBREV;
73 rev.commit_format = CMIT_FMT_DEFAULT;
74 rev.verbose_header = 1;
75 rev.show_root_diff = 0;
Lars Hjemli732d68d2006-12-28 02:45:28 +010076 setup_revisions(argc, argv, &rev, NULL);
77 if (rev.grep_filter) {
78 rev.grep_filter->regflags |= REG_ICASE;
79 compile_grep_patterns(rev.grep_filter);
80 }
Lars Hjemlid14c5f62006-12-11 17:04:19 +010081 prepare_revision_walk(&rev);
82
Lars Hjemli9d8d9b62006-12-22 00:58:18 +010083 html("<table class='list nowrap'>");
Lars Hjemli237ef7b2007-05-22 23:15:36 +020084 html("<tr class='nohover'><th class='left'>Age</th>"
Lars Hjemlie1893442007-05-18 13:55:52 +020085 "<th class='left'>Message</th>");
86
87 if (cgit_repo->enable_log_filecount) {
88 html("<th class='left'>Files</th>");
89 if (cgit_repo->enable_log_linecount)
90 html("<th class='left'>Lines</th>");
91 }
92 html("<th class='left'>Author</th></tr>\n");
Lars Hjemli420712a2006-12-14 00:40:34 +010093
94 if (ofs<0)
95 ofs = 0;
96
97 for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; i++) {
98 free(commit->buffer);
99 commit->buffer = NULL;
100 free_commit_list(commit->parents);
101 commit->parents = NULL;
102 }
103
104 for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) {
Lars Hjemli2101e262006-12-15 18:17:36 +0100105 print_commit(commit);
Lars Hjemlid14c5f62006-12-11 17:04:19 +0100106 free(commit->buffer);
107 commit->buffer = NULL;
108 free_commit_list(commit->parents);
109 commit->parents = NULL;
110 }
111 html("</table>\n");
Lars Hjemli420712a2006-12-14 00:40:34 +0100112
Ondrej Jirmana9226152007-05-26 03:26:14 +0200113 if (pager) {
114 html("<div class='pager'>");
115 if (ofs > 0) {
Lars Hjemli103940f2007-06-29 20:27:41 +0200116 cgit_log_link("[prev]", NULL, NULL, cgit_query_head,
117 cgit_query_sha1, cgit_query_path,
118 ofs - cnt);
119 html("&nbsp;");
Ondrej Jirmana9226152007-05-26 03:26:14 +0200120 }
Ondrej Jirmana9226152007-05-26 03:26:14 +0200121 if ((commit = get_revision(&rev)) != NULL) {
Lars Hjemli103940f2007-06-29 20:27:41 +0200122 cgit_log_link("[next]", NULL, NULL, cgit_query_head,
123 cgit_query_sha1, cgit_query_path,
124 ofs + cnt);
Ondrej Jirmana9226152007-05-26 03:26:14 +0200125 }
126 html("</div>");
Lars Hjemli420712a2006-12-14 00:40:34 +0100127 }
Lars Hjemlid14c5f62006-12-11 17:04:19 +0100128}