blob: 31331ef4c35028ab6fbcfe7cf5cf8cb49c875cad [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 Hjemli2101e262006-12-15 18:17:36 +010011void print_commit(struct commit *commit)
Lars Hjemlid14c5f62006-12-11 17:04:19 +010012{
Lars Hjemlid14c5f62006-12-11 17:04:19 +010013 char buf[32];
Lars Hjemli2101e262006-12-15 18:17:36 +010014 struct commitinfo *info;
15 struct tm *time;
Lars Hjemlid14c5f62006-12-11 17:04:19 +010016
Lars Hjemli2101e262006-12-15 18:17:36 +010017 info = cgit_parse_commit(commit);
18 time = gmtime(&commit->date);
Lars Hjemlid14c5f62006-12-11 17:04:19 +010019 html("<tr><td>");
20 strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", time);
21 html_txt(buf);
22 html("</td><td>");
23 char *qry = fmt("id=%s", sha1_to_hex(commit->object.sha1));
24 char *url = cgit_pageurl(cgit_query_repo, "view", qry);
25 html_link_open(url, NULL, NULL);
Lars Hjemli2101e262006-12-15 18:17:36 +010026 html_txt(info->subject);
Lars Hjemlid14c5f62006-12-11 17:04:19 +010027 html_link_close();
28 html("</td><td>");
Lars Hjemli2101e262006-12-15 18:17:36 +010029 html_txt(info->author);
Lars Hjemli06fe0c22006-12-13 00:13:27 +010030 html("</td><td><a href='");
31 html_attr(cgit_pageurl(cgit_query_repo, "tree",
32 fmt("id=%s",
33 sha1_to_hex(commit->tree->object.sha1))));
34 html("'>tree</a>");
Lars Hjemlid14c5f62006-12-11 17:04:19 +010035 html("</td></tr>\n");
Lars Hjemli2101e262006-12-15 18:17:36 +010036 free(info->author);
37 free(info->committer);
38 free(info->subject);
39 free(info);
Lars Hjemlid14c5f62006-12-11 17:04:19 +010040}
41
Lars Hjemli2101e262006-12-15 18:17:36 +010042
Lars Hjemlid14c5f62006-12-11 17:04:19 +010043void cgit_print_log(const char *tip, int ofs, int cnt)
44{
45 struct rev_info rev;
46 struct commit *commit;
47 const char *argv[2] = {NULL, tip};
Lars Hjemli420712a2006-12-14 00:40:34 +010048 int i;
Lars Hjemlid14c5f62006-12-11 17:04:19 +010049
50 init_revisions(&rev, NULL);
51 rev.abbrev = DEFAULT_ABBREV;
52 rev.commit_format = CMIT_FMT_DEFAULT;
53 rev.verbose_header = 1;
54 rev.show_root_diff = 0;
55 setup_revisions(2, argv, &rev, NULL);
56 prepare_revision_walk(&rev);
57
58 html("<h2>Log</h2>");
59 html("<table class='list'>");
Lars Hjemli06fe0c22006-12-13 00:13:27 +010060 html("<tr><th>Date</th><th>Message</th><th>Author</th><th>Link</th></tr>\n");
Lars Hjemli420712a2006-12-14 00:40:34 +010061
62 if (ofs<0)
63 ofs = 0;
64
65 for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; i++) {
66 free(commit->buffer);
67 commit->buffer = NULL;
68 free_commit_list(commit->parents);
69 commit->parents = NULL;
70 }
71
72 for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) {
Lars Hjemli2101e262006-12-15 18:17:36 +010073 print_commit(commit);
Lars Hjemlid14c5f62006-12-11 17:04:19 +010074 free(commit->buffer);
75 commit->buffer = NULL;
76 free_commit_list(commit->parents);
77 commit->parents = NULL;
78 }
79 html("</table>\n");
Lars Hjemli420712a2006-12-14 00:40:34 +010080
81 html("<div class='pager'>");
82 if (ofs > 0) {
83 html("&nbsp;<a href='");
84 html(cgit_pageurl(cgit_query_repo, cgit_query_page,
85 fmt("h=%s&ofs=%d", tip, ofs-cnt)));
86 html("'>[prev]</a>&nbsp;");
87 }
88
89 if ((commit = get_revision(&rev)) != NULL) {
90 html("&nbsp;<a href='");
91 html(cgit_pageurl(cgit_query_repo, "log",
92 fmt("h=%s&ofs=%d", tip, ofs+cnt)));
93 html("'>[next]</a>&nbsp;");
94 }
95 html("</div>");
Lars Hjemlid14c5f62006-12-11 17:04:19 +010096}
97