blob: 00ecd4e3e0c8d3200a716c77daacb00b4a62da2b [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"
Lars Hjemlib1f9b9c2008-02-23 22:45:33 +010010#include "html.h"
Lars Hjemlia4d1ca12008-03-24 16:50:57 +010011#include "ui-shared.h"
Lars Hjemlid14c5f62006-12-11 17:04:19 +010012
Lars Hjemlid04c4732007-11-06 00:35:12 +010013int files, add_lines, rem_lines;
Lars Hjemli48dc0032007-05-13 11:27:46 +020014
Lars Hjemli80e577c2007-05-13 17:03:27 +020015void count_lines(char *line, int size)
16{
Lars Hjemlid04c4732007-11-06 00:35:12 +010017 if (size <= 0)
18 return;
19
20 if (line[0] == '+')
21 add_lines++;
22
23 else if (line[0] == '-')
24 rem_lines++;
Lars Hjemli80e577c2007-05-13 17:03:27 +020025}
26
Lars Hjemli48dc0032007-05-13 11:27:46 +020027void inspect_files(struct diff_filepair *pair)
28{
29 files++;
Lars Hjemlid1f3bbe2008-02-16 13:56:09 +010030 if (ctx.repo->enable_log_linecount)
Lars Hjemlie1893442007-05-18 13:55:52 +020031 cgit_diff_files(pair->one->sha1, pair->two->sha1, count_lines);
Lars Hjemli48dc0032007-05-13 11:27:46 +020032}
33
Lars Hjemli2101e262006-12-15 18:17:36 +010034void print_commit(struct commit *commit)
Lars Hjemlid14c5f62006-12-11 17:04:19 +010035{
Lars Hjemli2101e262006-12-15 18:17:36 +010036 struct commitinfo *info;
Lars Hjemlie9a70422008-04-14 22:23:48 +020037 char *tmp;
Lars Hjemli951f5502008-11-29 18:58:31 +010038 int cols = 2;
Lars Hjemlid14c5f62006-12-11 17:04:19 +010039
Lars Hjemli2101e262006-12-15 18:17:36 +010040 info = cgit_parse_commit(commit);
Lars Hjemliab671642008-11-29 19:11:26 +010041 htmlf("<tr%s><td>",
42 ctx.qry.showmsg ? " class='logheader'" : "");
Lars Hjemlie9a70422008-04-14 22:23:48 +020043 tmp = fmt("id=%s", sha1_to_hex(commit->object.sha1));
44 tmp = cgit_pageurl(ctx.repo->url, "commit", tmp);
45 html_link_open(tmp, NULL, NULL);
Lars Hjemli237ef7b2007-05-22 23:15:36 +020046 cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE);
Lars Hjemlie9a70422008-04-14 22:23:48 +020047 html_link_close();
Lars Hjemliab671642008-11-29 19:11:26 +010048 htmlf("</td><td%s>",
49 ctx.qry.showmsg ? " class='logsubject'" : "");
Lars Hjemlid14d77f2008-02-16 11:53:40 +010050 cgit_commit_link(info->subject, NULL, NULL, ctx.qry.head,
Lars Hjemli42a7eb92007-06-17 14:53:02 +020051 sha1_to_hex(commit->object.sha1));
Lars Hjemli5764fe92008-04-14 22:13:38 +020052 html("</td><td>");
53 html_txt(info->author);
Lars Hjemlid1f3bbe2008-02-16 13:56:09 +010054 if (ctx.repo->enable_log_filecount) {
Lars Hjemlie1893442007-05-18 13:55:52 +020055 files = 0;
Lars Hjemlid04c4732007-11-06 00:35:12 +010056 add_lines = 0;
57 rem_lines = 0;
Lars Hjemlie1893442007-05-18 13:55:52 +020058 cgit_diff_commit(commit, inspect_files);
Lars Hjemli5764fe92008-04-14 22:13:38 +020059 html("</td><td>");
Lars Hjemlie1893442007-05-18 13:55:52 +020060 htmlf("%d", files);
Lars Hjemlid1f3bbe2008-02-16 13:56:09 +010061 if (ctx.repo->enable_log_linecount) {
Lars Hjemli5764fe92008-04-14 22:13:38 +020062 html("</td><td>");
Lars Hjemlid04c4732007-11-06 00:35:12 +010063 htmlf("-%d/+%d", rem_lines, add_lines);
Lars Hjemlie1893442007-05-18 13:55:52 +020064 }
65 }
Lars Hjemlid14c5f62006-12-11 17:04:19 +010066 html("</td></tr>\n");
Lars Hjemli0274b572008-11-29 18:39:41 +010067 if (ctx.qry.showmsg) {
Lars Hjemli0274b572008-11-29 18:39:41 +010068 if (ctx.repo->enable_log_filecount) {
Lars Hjemli951f5502008-11-29 18:58:31 +010069 cols++;
Lars Hjemli0274b572008-11-29 18:39:41 +010070 if (ctx.repo->enable_log_linecount)
Lars Hjemli951f5502008-11-29 18:58:31 +010071 cols++;
Lars Hjemli0274b572008-11-29 18:39:41 +010072 }
Lars Hjemliab671642008-11-29 19:11:26 +010073 htmlf("<tr class='nohover'><td/><td colspan='%d' class='logmsg'>",
Lars Hjemli951f5502008-11-29 18:58:31 +010074 cols);
75 html_txt(info->msg);
Lars Hjemliab671642008-11-29 19:11:26 +010076 html("</td></tr>\n");
Lars Hjemli0274b572008-11-29 18:39:41 +010077 }
Lars Hjemliaaa24bd2006-12-16 14:58:20 +010078 cgit_free_commitinfo(info);
Lars Hjemlid14c5f62006-12-11 17:04:19 +010079}
80
Lars Hjemli2101e262006-12-15 18:17:36 +010081
Lars Hjemli5764fe92008-04-14 22:13:38 +020082void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern,
83 char *path, int pager)
Lars Hjemlid14c5f62006-12-11 17:04:19 +010084{
85 struct rev_info rev;
86 struct commit *commit;
Lars Hjemli9fb53af2007-05-14 11:10:59 +020087 const char *argv[] = {NULL, tip, NULL, NULL, NULL};
Lars Hjemli732d68d2006-12-28 02:45:28 +010088 int argc = 2;
Lars Hjemli5764fe92008-04-14 22:13:38 +020089 int i, columns = 3;
Lars Hjemli48dc0032007-05-13 11:27:46 +020090
Lars Hjemlicd79c162007-06-17 14:58:45 +020091 if (!tip)
Lars Hjemlid14d77f2008-02-16 11:53:40 +010092 argv[1] = ctx.qry.head;
Lars Hjemlicd79c162007-06-17 14:58:45 +020093
Lars Hjemli68ca0322007-10-28 15:23:00 +010094 if (grep && pattern && (!strcmp(grep, "grep") ||
95 !strcmp(grep, "author") ||
96 !strcmp(grep, "committer")))
97 argv[argc++] = fmt("--%s=%s", grep, pattern);
98
Lars Hjemli9fb53af2007-05-14 11:10:59 +020099 if (path) {
100 argv[argc++] = "--";
101 argv[argc++] = path;
102 }
Lars Hjemlid14c5f62006-12-11 17:04:19 +0100103 init_revisions(&rev, NULL);
104 rev.abbrev = DEFAULT_ABBREV;
105 rev.commit_format = CMIT_FMT_DEFAULT;
106 rev.verbose_header = 1;
107 rev.show_root_diff = 0;
Lars Hjemli732d68d2006-12-28 02:45:28 +0100108 setup_revisions(argc, argv, &rev, NULL);
Lars Hjemlib7f33782008-10-05 19:19:59 +0200109 rev.grep_filter.regflags |= REG_ICASE;
110 compile_grep_patterns(&rev.grep_filter);
Lars Hjemlid14c5f62006-12-11 17:04:19 +0100111 prepare_revision_walk(&rev);
112
Lars Hjemli5764fe92008-04-14 22:13:38 +0200113 if (pager)
114 html("<table class='list nowrap'>");
Lars Hjemlie1893442007-05-18 13:55:52 +0200115
Lars Hjemli5764fe92008-04-14 22:13:38 +0200116 html("<tr class='nohover'><th class='left'>Age</th>"
Lars Hjemli0274b572008-11-29 18:39:41 +0100117 "<th class='left'>Commit message");
118 if (pager) {
119 html(" (");
120 cgit_log_link("toggle", NULL, NULL, ctx.qry.head, ctx.qry.sha1,
121 ctx.qry.path, ctx.qry.ofs, ctx.qry.grep,
122 ctx.qry.search, ctx.qry.showmsg ? 0 : 1);
123 html(")");
124 }
125 html("</th><th class='left'>Author</th>");
Lars Hjemlid1f3bbe2008-02-16 13:56:09 +0100126 if (ctx.repo->enable_log_filecount) {
Lars Hjemli5764fe92008-04-14 22:13:38 +0200127 html("<th class='left'>Files</th>");
128 columns++;
129 if (ctx.repo->enable_log_linecount) {
130 html("<th class='left'>Lines</th>");
131 columns++;
132 }
Lars Hjemlie1893442007-05-18 13:55:52 +0200133 }
Lars Hjemli5764fe92008-04-14 22:13:38 +0200134 html("</tr>\n");
Lars Hjemli420712a2006-12-14 00:40:34 +0100135
136 if (ofs<0)
137 ofs = 0;
138
139 for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; i++) {
140 free(commit->buffer);
141 commit->buffer = NULL;
142 free_commit_list(commit->parents);
143 commit->parents = NULL;
144 }
145
146 for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) {
Lars Hjemli2101e262006-12-15 18:17:36 +0100147 print_commit(commit);
Lars Hjemlid14c5f62006-12-11 17:04:19 +0100148 free(commit->buffer);
149 commit->buffer = NULL;
150 free_commit_list(commit->parents);
151 commit->parents = NULL;
152 }
Ondrej Jirmana9226152007-05-26 03:26:14 +0200153 if (pager) {
Lars Hjemli5764fe92008-04-14 22:13:38 +0200154 htmlf("</table><div class='pager'>",
155 columns);
Ondrej Jirmana9226152007-05-26 03:26:14 +0200156 if (ofs > 0) {
Lars Hjemlid14d77f2008-02-16 11:53:40 +0100157 cgit_log_link("[prev]", NULL, NULL, ctx.qry.head,
158 ctx.qry.sha1, ctx.qry.path,
159 ofs - cnt, ctx.qry.grep,
Lars Hjemli0274b572008-11-29 18:39:41 +0100160 ctx.qry.search, ctx.qry.showmsg);
Lars Hjemli103940f2007-06-29 20:27:41 +0200161 html("&nbsp;");
Ondrej Jirmana9226152007-05-26 03:26:14 +0200162 }
Ondrej Jirmana9226152007-05-26 03:26:14 +0200163 if ((commit = get_revision(&rev)) != NULL) {
Lars Hjemlid14d77f2008-02-16 11:53:40 +0100164 cgit_log_link("[next]", NULL, NULL, ctx.qry.head,
165 ctx.qry.sha1, ctx.qry.path,
166 ofs + cnt, ctx.qry.grep,
Lars Hjemli0274b572008-11-29 18:39:41 +0100167 ctx.qry.search, ctx.qry.showmsg);
Ondrej Jirmana9226152007-05-26 03:26:14 +0200168 }
169 html("</div>");
Lars Hjemli5764fe92008-04-14 22:13:38 +0200170 } else if ((commit = get_revision(&rev)) != NULL) {
171 html("<tr class='nohover'><td colspan='3'>");
172 cgit_log_link("[...]", NULL, NULL, ctx.qry.head, NULL, NULL, 0,
Lars Hjemli0274b572008-11-29 18:39:41 +0100173 NULL, NULL, ctx.qry.showmsg);
Lars Hjemli5764fe92008-04-14 22:13:38 +0200174 html("</td></tr>\n");
Lars Hjemli420712a2006-12-14 00:40:34 +0100175 }
Lars Hjemlid14c5f62006-12-11 17:04:19 +0100176}