blob: c52af79ac5ffb876bd4e41211fda907baa0f629b [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));
Lars Hjemli9a8f8862006-12-16 00:19:56 +010024 char *url = cgit_pageurl(cgit_query_repo, "commit", qry);
Lars Hjemlid14c5f62006-12-11 17:04:19 +010025 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 Hjemlid14c5f62006-12-11 17:04:19 +010030 html("</td></tr>\n");
Lars Hjemli2101e262006-12-15 18:17:36 +010031 free(info->author);
32 free(info->committer);
33 free(info->subject);
34 free(info);
Lars Hjemlid14c5f62006-12-11 17:04:19 +010035}
36
Lars Hjemli2101e262006-12-15 18:17:36 +010037
Lars Hjemlid14c5f62006-12-11 17:04:19 +010038void cgit_print_log(const char *tip, int ofs, int cnt)
39{
40 struct rev_info rev;
41 struct commit *commit;
42 const char *argv[2] = {NULL, tip};
Lars Hjemli420712a2006-12-14 00:40:34 +010043 int i;
Lars Hjemlid14c5f62006-12-11 17:04:19 +010044
45 init_revisions(&rev, NULL);
46 rev.abbrev = DEFAULT_ABBREV;
47 rev.commit_format = CMIT_FMT_DEFAULT;
48 rev.verbose_header = 1;
49 rev.show_root_diff = 0;
50 setup_revisions(2, argv, &rev, NULL);
51 prepare_revision_walk(&rev);
52
53 html("<h2>Log</h2>");
Lars Hjemli9a8f8862006-12-16 00:19:56 +010054 html("<table class='list log'>");
55 html("<tr><th class='left'>Date</th><th class='left'>Message</th><th class='left'>Author</th></tr>\n");
Lars Hjemli420712a2006-12-14 00:40:34 +010056
57 if (ofs<0)
58 ofs = 0;
59
60 for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; i++) {
61 free(commit->buffer);
62 commit->buffer = NULL;
63 free_commit_list(commit->parents);
64 commit->parents = NULL;
65 }
66
67 for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) {
Lars Hjemli2101e262006-12-15 18:17:36 +010068 print_commit(commit);
Lars Hjemlid14c5f62006-12-11 17:04:19 +010069 free(commit->buffer);
70 commit->buffer = NULL;
71 free_commit_list(commit->parents);
72 commit->parents = NULL;
73 }
74 html("</table>\n");
Lars Hjemli420712a2006-12-14 00:40:34 +010075
76 html("<div class='pager'>");
77 if (ofs > 0) {
78 html("&nbsp;<a href='");
79 html(cgit_pageurl(cgit_query_repo, cgit_query_page,
80 fmt("h=%s&ofs=%d", tip, ofs-cnt)));
81 html("'>[prev]</a>&nbsp;");
82 }
83
84 if ((commit = get_revision(&rev)) != NULL) {
85 html("&nbsp;<a href='");
86 html(cgit_pageurl(cgit_query_repo, "log",
87 fmt("h=%s&ofs=%d", tip, ofs+cnt)));
88 html("'>[next]</a>&nbsp;");
89 }
90 html("</div>");
Lars Hjemlid14c5f62006-12-11 17:04:19 +010091}
92