blob: 746f40bbaf8a5bd2d3f2c07abd0290b971ae452b [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 Hjemlid14c5f62006-12-11 17:04:19 +010038
Lars Hjemli2101e262006-12-15 18:17:36 +010039 info = cgit_parse_commit(commit);
Lars Hjemlid14c5f62006-12-11 17:04:19 +010040 html("<tr><td>");
Lars Hjemlie9a70422008-04-14 22:23:48 +020041 tmp = fmt("id=%s", sha1_to_hex(commit->object.sha1));
42 tmp = cgit_pageurl(ctx.repo->url, "commit", tmp);
43 html_link_open(tmp, NULL, NULL);
Lars Hjemli237ef7b2007-05-22 23:15:36 +020044 cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE);
Lars Hjemlie9a70422008-04-14 22:23:48 +020045 html_link_close();
Lars Hjemlid14c5f62006-12-11 17:04:19 +010046 html("</td><td>");
Lars Hjemlid14d77f2008-02-16 11:53:40 +010047 cgit_commit_link(info->subject, NULL, NULL, ctx.qry.head,
Lars Hjemli42a7eb92007-06-17 14:53:02 +020048 sha1_to_hex(commit->object.sha1));
Lars Hjemli5764fe92008-04-14 22:13:38 +020049 html("</td><td>");
50 html_txt(info->author);
Lars Hjemlid1f3bbe2008-02-16 13:56:09 +010051 if (ctx.repo->enable_log_filecount) {
Lars Hjemlie1893442007-05-18 13:55:52 +020052 files = 0;
Lars Hjemlid04c4732007-11-06 00:35:12 +010053 add_lines = 0;
54 rem_lines = 0;
Lars Hjemlie1893442007-05-18 13:55:52 +020055 cgit_diff_commit(commit, inspect_files);
Lars Hjemli5764fe92008-04-14 22:13:38 +020056 html("</td><td>");
Lars Hjemlie1893442007-05-18 13:55:52 +020057 htmlf("%d", files);
Lars Hjemlid1f3bbe2008-02-16 13:56:09 +010058 if (ctx.repo->enable_log_linecount) {
Lars Hjemli5764fe92008-04-14 22:13:38 +020059 html("</td><td>");
Lars Hjemlid04c4732007-11-06 00:35:12 +010060 htmlf("-%d/+%d", rem_lines, add_lines);
Lars Hjemlie1893442007-05-18 13:55:52 +020061 }
62 }
Lars Hjemlid14c5f62006-12-11 17:04:19 +010063 html("</td></tr>\n");
Lars Hjemliaaa24bd2006-12-16 14:58:20 +010064 cgit_free_commitinfo(info);
Lars Hjemlid14c5f62006-12-11 17:04:19 +010065}
66
Lars Hjemli2101e262006-12-15 18:17:36 +010067
Lars Hjemli5764fe92008-04-14 22:13:38 +020068void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern,
69 char *path, int pager)
Lars Hjemlid14c5f62006-12-11 17:04:19 +010070{
71 struct rev_info rev;
72 struct commit *commit;
Lars Hjemli9fb53af2007-05-14 11:10:59 +020073 const char *argv[] = {NULL, tip, NULL, NULL, NULL};
Lars Hjemli732d68d2006-12-28 02:45:28 +010074 int argc = 2;
Lars Hjemli5764fe92008-04-14 22:13:38 +020075 int i, columns = 3;
Lars Hjemli48dc0032007-05-13 11:27:46 +020076
Lars Hjemlicd79c162007-06-17 14:58:45 +020077 if (!tip)
Lars Hjemlid14d77f2008-02-16 11:53:40 +010078 argv[1] = ctx.qry.head;
Lars Hjemlicd79c162007-06-17 14:58:45 +020079
Lars Hjemli68ca0322007-10-28 15:23:00 +010080 if (grep && pattern && (!strcmp(grep, "grep") ||
81 !strcmp(grep, "author") ||
82 !strcmp(grep, "committer")))
83 argv[argc++] = fmt("--%s=%s", grep, pattern);
84
Lars Hjemli9fb53af2007-05-14 11:10:59 +020085 if (path) {
86 argv[argc++] = "--";
87 argv[argc++] = path;
88 }
Lars Hjemlid14c5f62006-12-11 17:04:19 +010089 init_revisions(&rev, NULL);
90 rev.abbrev = DEFAULT_ABBREV;
91 rev.commit_format = CMIT_FMT_DEFAULT;
92 rev.verbose_header = 1;
93 rev.show_root_diff = 0;
Lars Hjemli732d68d2006-12-28 02:45:28 +010094 setup_revisions(argc, argv, &rev, NULL);
95 if (rev.grep_filter) {
96 rev.grep_filter->regflags |= REG_ICASE;
97 compile_grep_patterns(rev.grep_filter);
98 }
Lars Hjemlid14c5f62006-12-11 17:04:19 +010099 prepare_revision_walk(&rev);
100
Lars Hjemli5764fe92008-04-14 22:13:38 +0200101 if (pager)
102 html("<table class='list nowrap'>");
Lars Hjemlie1893442007-05-18 13:55:52 +0200103
Lars Hjemli5764fe92008-04-14 22:13:38 +0200104 html("<tr class='nohover'><th class='left'>Age</th>"
105 "<th class='left'>Commit message</th>"
106 "<th class='left'>Author</th>");
Lars Hjemlid1f3bbe2008-02-16 13:56:09 +0100107 if (ctx.repo->enable_log_filecount) {
Lars Hjemli5764fe92008-04-14 22:13:38 +0200108 html("<th class='left'>Files</th>");
109 columns++;
110 if (ctx.repo->enable_log_linecount) {
111 html("<th class='left'>Lines</th>");
112 columns++;
113 }
Lars Hjemlie1893442007-05-18 13:55:52 +0200114 }
Lars Hjemli5764fe92008-04-14 22:13:38 +0200115 html("</tr>\n");
Lars Hjemli420712a2006-12-14 00:40:34 +0100116
117 if (ofs<0)
118 ofs = 0;
119
120 for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; i++) {
121 free(commit->buffer);
122 commit->buffer = NULL;
123 free_commit_list(commit->parents);
124 commit->parents = NULL;
125 }
126
127 for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) {
Lars Hjemli2101e262006-12-15 18:17:36 +0100128 print_commit(commit);
Lars Hjemlid14c5f62006-12-11 17:04:19 +0100129 free(commit->buffer);
130 commit->buffer = NULL;
131 free_commit_list(commit->parents);
132 commit->parents = NULL;
133 }
Ondrej Jirmana9226152007-05-26 03:26:14 +0200134 if (pager) {
Lars Hjemli5764fe92008-04-14 22:13:38 +0200135 htmlf("</table><div class='pager'>",
136 columns);
Ondrej Jirmana9226152007-05-26 03:26:14 +0200137 if (ofs > 0) {
Lars Hjemlid14d77f2008-02-16 11:53:40 +0100138 cgit_log_link("[prev]", NULL, NULL, ctx.qry.head,
139 ctx.qry.sha1, ctx.qry.path,
140 ofs - cnt, ctx.qry.grep,
141 ctx.qry.search);
Lars Hjemli103940f2007-06-29 20:27:41 +0200142 html("&nbsp;");
Ondrej Jirmana9226152007-05-26 03:26:14 +0200143 }
Ondrej Jirmana9226152007-05-26 03:26:14 +0200144 if ((commit = get_revision(&rev)) != NULL) {
Lars Hjemlid14d77f2008-02-16 11:53:40 +0100145 cgit_log_link("[next]", NULL, NULL, ctx.qry.head,
146 ctx.qry.sha1, ctx.qry.path,
147 ofs + cnt, ctx.qry.grep,
148 ctx.qry.search);
Ondrej Jirmana9226152007-05-26 03:26:14 +0200149 }
150 html("</div>");
Lars Hjemli5764fe92008-04-14 22:13:38 +0200151 } else if ((commit = get_revision(&rev)) != NULL) {
152 html("<tr class='nohover'><td colspan='3'>");
153 cgit_log_link("[...]", NULL, NULL, ctx.qry.head, NULL, NULL, 0,
154 NULL, NULL);
155 html("</td></tr>\n");
Lars Hjemli420712a2006-12-14 00:40:34 +0100156 }
Lars Hjemlid14c5f62006-12-11 17:04:19 +0100157}