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