2006-12-11 17:04:19 +01:00
|
|
|
/* ui-log.c: functions for log output
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 Lars Hjemli
|
|
|
|
*
|
|
|
|
* Licensed under GNU General Public License v2
|
|
|
|
* (see COPYING for full license text)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "cgit.h"
|
2008-02-23 22:45:33 +01:00
|
|
|
#include "html.h"
|
2008-03-24 16:50:57 +01:00
|
|
|
#include "ui-shared.h"
|
2006-12-11 17:04:19 +01:00
|
|
|
|
2007-11-06 00:35:12 +01:00
|
|
|
int files, add_lines, rem_lines;
|
2007-05-13 11:27:46 +02:00
|
|
|
|
2007-05-13 17:03:27 +02:00
|
|
|
void count_lines(char *line, int size)
|
|
|
|
{
|
2007-11-06 00:35:12 +01:00
|
|
|
if (size <= 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (line[0] == '+')
|
|
|
|
add_lines++;
|
|
|
|
|
|
|
|
else if (line[0] == '-')
|
|
|
|
rem_lines++;
|
2007-05-13 17:03:27 +02:00
|
|
|
}
|
|
|
|
|
2007-05-13 11:27:46 +02:00
|
|
|
void inspect_files(struct diff_filepair *pair)
|
|
|
|
{
|
|
|
|
files++;
|
2008-02-16 13:56:09 +01:00
|
|
|
if (ctx.repo->enable_log_linecount)
|
2007-05-18 13:55:52 +02:00
|
|
|
cgit_diff_files(pair->one->sha1, pair->two->sha1, count_lines);
|
2007-05-13 11:27:46 +02:00
|
|
|
}
|
|
|
|
|
2009-01-11 12:16:18 +01:00
|
|
|
void show_commit_decorations(struct commit *commit)
|
|
|
|
{
|
|
|
|
struct name_decoration *deco;
|
|
|
|
static char buf[1024];
|
|
|
|
|
|
|
|
buf[sizeof(buf) - 1] = 0;
|
|
|
|
deco = lookup_decoration(&name_decoration, &commit->object);
|
|
|
|
while (deco) {
|
|
|
|
if (!prefixcmp(deco->name, "refs/heads/")) {
|
|
|
|
strncpy(buf, deco->name + 11, sizeof(buf) - 1);
|
|
|
|
cgit_log_link(buf, NULL, "branch-deco", buf, NULL, NULL,
|
|
|
|
0, NULL, NULL, ctx.qry.showmsg);
|
|
|
|
}
|
|
|
|
else if (!prefixcmp(deco->name, "tag: refs/tags/")) {
|
|
|
|
strncpy(buf, deco->name + 15, sizeof(buf) - 1);
|
|
|
|
cgit_tag_link(buf, NULL, "tag-deco", ctx.qry.head, buf);
|
|
|
|
}
|
|
|
|
else if (!prefixcmp(deco->name, "refs/remotes/")) {
|
|
|
|
strncpy(buf, deco->name + 13, sizeof(buf) - 1);
|
|
|
|
cgit_log_link(buf, NULL, "remote-deco", NULL,
|
|
|
|
sha1_to_hex(commit->object.sha1), NULL,
|
|
|
|
0, NULL, NULL, ctx.qry.showmsg);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
strncpy(buf, deco->name, sizeof(buf) - 1);
|
|
|
|
cgit_commit_link(buf, NULL, "deco", ctx.qry.head,
|
|
|
|
sha1_to_hex(commit->object.sha1));
|
|
|
|
}
|
|
|
|
deco = deco->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-15 18:17:36 +01:00
|
|
|
void print_commit(struct commit *commit)
|
2006-12-11 17:04:19 +01:00
|
|
|
{
|
2006-12-15 18:17:36 +01:00
|
|
|
struct commitinfo *info;
|
2008-04-14 22:23:48 +02:00
|
|
|
char *tmp;
|
2008-11-29 18:58:31 +01:00
|
|
|
int cols = 2;
|
2006-12-11 17:04:19 +01:00
|
|
|
|
2006-12-15 18:17:36 +01:00
|
|
|
info = cgit_parse_commit(commit);
|
2008-11-29 19:11:26 +01:00
|
|
|
htmlf("<tr%s><td>",
|
|
|
|
ctx.qry.showmsg ? " class='logheader'" : "");
|
2008-04-14 22:23:48 +02:00
|
|
|
tmp = fmt("id=%s", sha1_to_hex(commit->object.sha1));
|
|
|
|
tmp = cgit_pageurl(ctx.repo->url, "commit", tmp);
|
|
|
|
html_link_open(tmp, NULL, NULL);
|
2007-05-22 23:15:36 +02:00
|
|
|
cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE);
|
2008-04-14 22:23:48 +02:00
|
|
|
html_link_close();
|
2008-11-29 19:11:26 +01:00
|
|
|
htmlf("</td><td%s>",
|
|
|
|
ctx.qry.showmsg ? " class='logsubject'" : "");
|
2008-02-16 11:53:40 +01:00
|
|
|
cgit_commit_link(info->subject, NULL, NULL, ctx.qry.head,
|
2007-06-17 14:53:02 +02:00
|
|
|
sha1_to_hex(commit->object.sha1));
|
2009-01-11 12:16:18 +01:00
|
|
|
show_commit_decorations(commit);
|
2008-04-14 22:13:38 +02:00
|
|
|
html("</td><td>");
|
|
|
|
html_txt(info->author);
|
2008-02-16 13:56:09 +01:00
|
|
|
if (ctx.repo->enable_log_filecount) {
|
2007-05-18 13:55:52 +02:00
|
|
|
files = 0;
|
2007-11-06 00:35:12 +01:00
|
|
|
add_lines = 0;
|
|
|
|
rem_lines = 0;
|
2007-05-18 13:55:52 +02:00
|
|
|
cgit_diff_commit(commit, inspect_files);
|
2008-04-14 22:13:38 +02:00
|
|
|
html("</td><td>");
|
2007-05-18 13:55:52 +02:00
|
|
|
htmlf("%d", files);
|
2008-02-16 13:56:09 +01:00
|
|
|
if (ctx.repo->enable_log_linecount) {
|
2008-04-14 22:13:38 +02:00
|
|
|
html("</td><td>");
|
2007-11-06 00:35:12 +01:00
|
|
|
htmlf("-%d/+%d", rem_lines, add_lines);
|
2007-05-18 13:55:52 +02:00
|
|
|
}
|
|
|
|
}
|
2006-12-11 17:04:19 +01:00
|
|
|
html("</td></tr>\n");
|
2008-11-29 18:39:41 +01:00
|
|
|
if (ctx.qry.showmsg) {
|
|
|
|
if (ctx.repo->enable_log_filecount) {
|
2008-11-29 18:58:31 +01:00
|
|
|
cols++;
|
2008-11-29 18:39:41 +01:00
|
|
|
if (ctx.repo->enable_log_linecount)
|
2008-11-29 18:58:31 +01:00
|
|
|
cols++;
|
2008-11-29 18:39:41 +01:00
|
|
|
}
|
2008-11-29 19:11:26 +01:00
|
|
|
htmlf("<tr class='nohover'><td/><td colspan='%d' class='logmsg'>",
|
2008-11-29 18:58:31 +01:00
|
|
|
cols);
|
|
|
|
html_txt(info->msg);
|
2008-11-29 19:11:26 +01:00
|
|
|
html("</td></tr>\n");
|
2008-11-29 18:39:41 +01:00
|
|
|
}
|
2006-12-16 14:58:20 +01:00
|
|
|
cgit_free_commitinfo(info);
|
2006-12-11 17:04:19 +01:00
|
|
|
}
|
|
|
|
|
2008-12-03 17:34:23 +01:00
|
|
|
static const char *disambiguate_ref(const char *ref)
|
|
|
|
{
|
|
|
|
unsigned char sha1[20];
|
|
|
|
const char *longref;
|
|
|
|
|
|
|
|
longref = fmt("refs/heads/%s", ref);
|
|
|
|
if (get_sha1(longref, sha1) == 0)
|
|
|
|
return longref;
|
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
2006-12-15 18:17:36 +01:00
|
|
|
|
2008-04-14 22:13:38 +02:00
|
|
|
void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern,
|
|
|
|
char *path, int pager)
|
2006-12-11 17:04:19 +01:00
|
|
|
{
|
|
|
|
struct rev_info rev;
|
|
|
|
struct commit *commit;
|
2008-12-03 17:34:23 +01:00
|
|
|
const char *argv[] = {NULL, NULL, NULL, NULL, NULL};
|
2006-12-28 02:45:28 +01:00
|
|
|
int argc = 2;
|
2008-04-14 22:13:38 +02:00
|
|
|
int i, columns = 3;
|
2007-05-13 11:27:46 +02:00
|
|
|
|
2007-06-17 14:58:45 +02:00
|
|
|
if (!tip)
|
2008-12-03 17:34:23 +01:00
|
|
|
tip = ctx.qry.head;
|
|
|
|
|
|
|
|
argv[1] = disambiguate_ref(tip);
|
2007-06-17 14:58:45 +02:00
|
|
|
|
2007-10-28 15:23:00 +01:00
|
|
|
if (grep && pattern && (!strcmp(grep, "grep") ||
|
|
|
|
!strcmp(grep, "author") ||
|
|
|
|
!strcmp(grep, "committer")))
|
|
|
|
argv[argc++] = fmt("--%s=%s", grep, pattern);
|
|
|
|
|
2007-05-14 11:10:59 +02:00
|
|
|
if (path) {
|
|
|
|
argv[argc++] = "--";
|
|
|
|
argv[argc++] = path;
|
|
|
|
}
|
2006-12-11 17:04:19 +01:00
|
|
|
init_revisions(&rev, NULL);
|
|
|
|
rev.abbrev = DEFAULT_ABBREV;
|
|
|
|
rev.commit_format = CMIT_FMT_DEFAULT;
|
|
|
|
rev.verbose_header = 1;
|
|
|
|
rev.show_root_diff = 0;
|
2006-12-28 02:45:28 +01:00
|
|
|
setup_revisions(argc, argv, &rev, NULL);
|
2009-01-11 12:16:18 +01:00
|
|
|
load_ref_decorations();
|
|
|
|
rev.show_decorations = 1;
|
2008-10-05 19:19:59 +02:00
|
|
|
rev.grep_filter.regflags |= REG_ICASE;
|
|
|
|
compile_grep_patterns(&rev.grep_filter);
|
2006-12-11 17:04:19 +01:00
|
|
|
prepare_revision_walk(&rev);
|
|
|
|
|
2008-04-14 22:13:38 +02:00
|
|
|
if (pager)
|
|
|
|
html("<table class='list nowrap'>");
|
2007-05-18 13:55:52 +02:00
|
|
|
|
2008-04-14 22:13:38 +02:00
|
|
|
html("<tr class='nohover'><th class='left'>Age</th>"
|
2008-11-29 18:39:41 +01:00
|
|
|
"<th class='left'>Commit message");
|
|
|
|
if (pager) {
|
|
|
|
html(" (");
|
|
|
|
cgit_log_link("toggle", NULL, NULL, ctx.qry.head, ctx.qry.sha1,
|
|
|
|
ctx.qry.path, ctx.qry.ofs, ctx.qry.grep,
|
|
|
|
ctx.qry.search, ctx.qry.showmsg ? 0 : 1);
|
|
|
|
html(")");
|
|
|
|
}
|
|
|
|
html("</th><th class='left'>Author</th>");
|
2008-02-16 13:56:09 +01:00
|
|
|
if (ctx.repo->enable_log_filecount) {
|
2008-04-14 22:13:38 +02:00
|
|
|
html("<th class='left'>Files</th>");
|
|
|
|
columns++;
|
|
|
|
if (ctx.repo->enable_log_linecount) {
|
|
|
|
html("<th class='left'>Lines</th>");
|
|
|
|
columns++;
|
|
|
|
}
|
2007-05-18 13:55:52 +02:00
|
|
|
}
|
2008-04-14 22:13:38 +02:00
|
|
|
html("</tr>\n");
|
2006-12-14 00:40:34 +01:00
|
|
|
|
|
|
|
if (ofs<0)
|
|
|
|
ofs = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < ofs && (commit = get_revision(&rev)) != NULL; i++) {
|
|
|
|
free(commit->buffer);
|
|
|
|
commit->buffer = NULL;
|
|
|
|
free_commit_list(commit->parents);
|
|
|
|
commit->parents = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) {
|
2006-12-15 18:17:36 +01:00
|
|
|
print_commit(commit);
|
2006-12-11 17:04:19 +01:00
|
|
|
free(commit->buffer);
|
|
|
|
commit->buffer = NULL;
|
|
|
|
free_commit_list(commit->parents);
|
|
|
|
commit->parents = NULL;
|
|
|
|
}
|
2007-05-26 03:26:14 +02:00
|
|
|
if (pager) {
|
2008-04-14 22:13:38 +02:00
|
|
|
htmlf("</table><div class='pager'>",
|
|
|
|
columns);
|
2007-05-26 03:26:14 +02:00
|
|
|
if (ofs > 0) {
|
2008-02-16 11:53:40 +01:00
|
|
|
cgit_log_link("[prev]", NULL, NULL, ctx.qry.head,
|
|
|
|
ctx.qry.sha1, ctx.qry.path,
|
|
|
|
ofs - cnt, ctx.qry.grep,
|
2008-11-29 18:39:41 +01:00
|
|
|
ctx.qry.search, ctx.qry.showmsg);
|
2007-06-29 20:27:41 +02:00
|
|
|
html(" ");
|
2007-05-26 03:26:14 +02:00
|
|
|
}
|
|
|
|
if ((commit = get_revision(&rev)) != NULL) {
|
2008-02-16 11:53:40 +01:00
|
|
|
cgit_log_link("[next]", NULL, NULL, ctx.qry.head,
|
|
|
|
ctx.qry.sha1, ctx.qry.path,
|
|
|
|
ofs + cnt, ctx.qry.grep,
|
2008-11-29 18:39:41 +01:00
|
|
|
ctx.qry.search, ctx.qry.showmsg);
|
2007-05-26 03:26:14 +02:00
|
|
|
}
|
|
|
|
html("</div>");
|
2008-04-14 22:13:38 +02:00
|
|
|
} else if ((commit = get_revision(&rev)) != NULL) {
|
|
|
|
html("<tr class='nohover'><td colspan='3'>");
|
|
|
|
cgit_log_link("[...]", NULL, NULL, ctx.qry.head, NULL, NULL, 0,
|
2008-11-29 18:39:41 +01:00
|
|
|
NULL, NULL, ctx.qry.showmsg);
|
2008-04-14 22:13:38 +02:00
|
|
|
html("</td></tr>\n");
|
2006-12-14 00:40:34 +01:00
|
|
|
}
|
2006-12-11 17:04:19 +01:00
|
|
|
}
|