]> gitweb.ps.run Git - ps-cgit/blob - ui-log.c
ui-log: use css to make full-log prettier
[ps-cgit] / ui-log.c
1 /* 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 #include "html.h"
11 #include "ui-shared.h"
12
13 int files, add_lines, rem_lines;
14
15 void count_lines(char *line, int size)
16 {
17         if (size <= 0)
18                 return;
19
20         if (line[0] == '+')
21                 add_lines++;
22
23         else if (line[0] == '-')
24                 rem_lines++;
25 }
26
27 void inspect_files(struct diff_filepair *pair)
28 {
29         files++;
30         if (ctx.repo->enable_log_linecount)
31                 cgit_diff_files(pair->one->sha1, pair->two->sha1, count_lines);
32 }
33
34 void print_commit(struct commit *commit)
35 {
36         struct commitinfo *info;
37         char *tmp;
38         int cols = 2;
39
40         info = cgit_parse_commit(commit);
41         htmlf("<tr%s><td>",
42                 ctx.qry.showmsg ? " class='logheader'" : "");
43         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);
46         cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE);
47         html_link_close();
48         htmlf("</td><td%s>",
49                 ctx.qry.showmsg ? " class='logsubject'" : "");
50         cgit_commit_link(info->subject, NULL, NULL, ctx.qry.head,
51                          sha1_to_hex(commit->object.sha1));
52         html("</td><td>");
53         html_txt(info->author);
54         if (ctx.repo->enable_log_filecount) {
55                 files = 0;
56                 add_lines = 0;
57                 rem_lines = 0;
58                 cgit_diff_commit(commit, inspect_files);
59                 html("</td><td>");
60                 htmlf("%d", files);
61                 if (ctx.repo->enable_log_linecount) {
62                         html("</td><td>");
63                         htmlf("-%d/+%d", rem_lines, add_lines);
64                 }
65         }
66         html("</td></tr>\n");
67         if (ctx.qry.showmsg) {
68                 if (ctx.repo->enable_log_filecount) {
69                         cols++;
70                         if (ctx.repo->enable_log_linecount)
71                                 cols++;
72                 }
73                 htmlf("<tr class='nohover'><td/><td colspan='%d' class='logmsg'>",
74                         cols);
75                 html_txt(info->msg);
76                 html("</td></tr>\n");
77         }
78         cgit_free_commitinfo(info);
79 }
80
81
82 void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern,
83                     char *path, int pager)
84 {
85         struct rev_info rev;
86         struct commit *commit;
87         const char *argv[] = {NULL, tip, NULL, NULL, NULL};
88         int argc = 2;
89         int i, columns = 3;
90
91         if (!tip)
92                 argv[1] = ctx.qry.head;
93
94         if (grep && pattern && (!strcmp(grep, "grep") ||
95                                 !strcmp(grep, "author") ||
96                                 !strcmp(grep, "committer")))
97                 argv[argc++] = fmt("--%s=%s", grep, pattern);
98
99         if (path) {
100                 argv[argc++] = "--";
101                 argv[argc++] = path;
102         }
103         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;
108         setup_revisions(argc, argv, &rev, NULL);
109         rev.grep_filter.regflags |= REG_ICASE;
110         compile_grep_patterns(&rev.grep_filter);
111         prepare_revision_walk(&rev);
112
113         if (pager)
114                 html("<table class='list nowrap'>");
115
116         html("<tr class='nohover'><th class='left'>Age</th>"
117               "<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>");
126         if (ctx.repo->enable_log_filecount) {
127                 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                 }
133         }
134         html("</tr>\n");
135
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++) {
147                 print_commit(commit);
148                 free(commit->buffer);
149                 commit->buffer = NULL;
150                 free_commit_list(commit->parents);
151                 commit->parents = NULL;
152         }
153         if (pager) {
154                 htmlf("</table><div class='pager'>",
155                      columns);
156                 if (ofs > 0) {
157                         cgit_log_link("[prev]", NULL, NULL, ctx.qry.head,
158                                       ctx.qry.sha1, ctx.qry.path,
159                                       ofs - cnt, ctx.qry.grep,
160                                       ctx.qry.search, ctx.qry.showmsg);
161                         html("&nbsp;");
162                 }
163                 if ((commit = get_revision(&rev)) != NULL) {
164                         cgit_log_link("[next]", NULL, NULL, ctx.qry.head,
165                                       ctx.qry.sha1, ctx.qry.path,
166                                       ofs + cnt, ctx.qry.grep,
167                                       ctx.qry.search, ctx.qry.showmsg);
168                 }
169                 html("</div>");
170         } 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,
173                               NULL, NULL, ctx.qry.showmsg);
174                 html("</td></tr>\n");
175         }
176 }