blob: f3b16e71e3a764ffc9a8c6e0485baa209b79d82d [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 Hjemli9d8d9b62006-12-22 00:58:18 +010026 html_ntxt(80, 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 Hjemliaaa24bd2006-12-16 14:58:20 +010031 cgit_free_commitinfo(info);
Lars Hjemlid14c5f62006-12-11 17:04:19 +010032}
33
Lars Hjemli2101e262006-12-15 18:17:36 +010034
Lars Hjemlid14c5f62006-12-11 17:04:19 +010035void cgit_print_log(const char *tip, int ofs, int cnt)
36{
37 struct rev_info rev;
38 struct commit *commit;
39 const char *argv[2] = {NULL, tip};
Lars Hjemli420712a2006-12-14 00:40:34 +010040 int i;
Lars Hjemlid14c5f62006-12-11 17:04:19 +010041
42 init_revisions(&rev, NULL);
43 rev.abbrev = DEFAULT_ABBREV;
44 rev.commit_format = CMIT_FMT_DEFAULT;
45 rev.verbose_header = 1;
46 rev.show_root_diff = 0;
47 setup_revisions(2, argv, &rev, NULL);
48 prepare_revision_walk(&rev);
49
50 html("<h2>Log</h2>");
Lars Hjemli9d8d9b62006-12-22 00:58:18 +010051 html("<table class='list nowrap'>");
Lars Hjemli9c5229e2006-12-16 19:35:31 +010052 html("<tr><th class='left'>Date</th>"
53 "<th class='left'>Message</th>"
54 "<th class='left'>Author</th></tr>\n");
Lars Hjemli420712a2006-12-14 00:40:34 +010055
56 if (ofs<0)
57 ofs = 0;
58
59 for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; i++) {
60 free(commit->buffer);
61 commit->buffer = NULL;
62 free_commit_list(commit->parents);
63 commit->parents = NULL;
64 }
65
66 for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) {
Lars Hjemli2101e262006-12-15 18:17:36 +010067 print_commit(commit);
Lars Hjemlid14c5f62006-12-11 17:04:19 +010068 free(commit->buffer);
69 commit->buffer = NULL;
70 free_commit_list(commit->parents);
71 commit->parents = NULL;
72 }
73 html("</table>\n");
Lars Hjemli420712a2006-12-14 00:40:34 +010074
75 html("<div class='pager'>");
76 if (ofs > 0) {
77 html("&nbsp;<a href='");
78 html(cgit_pageurl(cgit_query_repo, cgit_query_page,
79 fmt("h=%s&ofs=%d", tip, ofs-cnt)));
80 html("'>[prev]</a>&nbsp;");
81 }
82
83 if ((commit = get_revision(&rev)) != NULL) {
84 html("&nbsp;<a href='");
85 html(cgit_pageurl(cgit_query_repo, "log",
86 fmt("h=%s&ofs=%d", tip, ofs+cnt)));
87 html("'>[next]</a>&nbsp;");
88 }
89 html("</div>");
Lars Hjemlid14c5f62006-12-11 17:04:19 +010090}
91