blob: b7da49fda6d239934e542bbc9d15f64c9d3ae07e [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 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 Hjemli9a8f8862006-12-16 00:19:56 +010051 html("<table class='list log'>");
52 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 +010053
54 if (ofs<0)
55 ofs = 0;
56
57 for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; i++) {
58 free(commit->buffer);
59 commit->buffer = NULL;
60 free_commit_list(commit->parents);
61 commit->parents = NULL;
62 }
63
64 for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) {
Lars Hjemli2101e262006-12-15 18:17:36 +010065 print_commit(commit);
Lars Hjemlid14c5f62006-12-11 17:04:19 +010066 free(commit->buffer);
67 commit->buffer = NULL;
68 free_commit_list(commit->parents);
69 commit->parents = NULL;
70 }
71 html("</table>\n");
Lars Hjemli420712a2006-12-14 00:40:34 +010072
73 html("<div class='pager'>");
74 if (ofs > 0) {
75 html("&nbsp;<a href='");
76 html(cgit_pageurl(cgit_query_repo, cgit_query_page,
77 fmt("h=%s&ofs=%d", tip, ofs-cnt)));
78 html("'>[prev]</a>&nbsp;");
79 }
80
81 if ((commit = get_revision(&rev)) != NULL) {
82 html("&nbsp;<a href='");
83 html(cgit_pageurl(cgit_query_repo, "log",
84 fmt("h=%s&ofs=%d", tip, ofs+cnt)));
85 html("'>[next]</a>&nbsp;");
86 }
87 html("</div>");
Lars Hjemlid14c5f62006-12-11 17:04:19 +010088}
89