2006-12-11 16:04:19 +00: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"
|
|
|
|
|
2007-11-05 23:35:12 +00:00
|
|
|
int files, add_lines, rem_lines;
|
2007-05-13 09:27:46 +00:00
|
|
|
|
2007-05-13 15:03:27 +00:00
|
|
|
void count_lines(char *line, int size)
|
|
|
|
{
|
2007-11-05 23:35:12 +00:00
|
|
|
if (size <= 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (line[0] == '+')
|
|
|
|
add_lines++;
|
|
|
|
|
|
|
|
else if (line[0] == '-')
|
|
|
|
rem_lines++;
|
2007-05-13 15:03:27 +00:00
|
|
|
}
|
|
|
|
|
2007-05-13 09:27:46 +00:00
|
|
|
void inspect_files(struct diff_filepair *pair)
|
|
|
|
{
|
|
|
|
files++;
|
2007-05-18 11:55:52 +00:00
|
|
|
if (cgit_repo->enable_log_linecount)
|
|
|
|
cgit_diff_files(pair->one->sha1, pair->two->sha1, count_lines);
|
2007-05-13 09:27:46 +00:00
|
|
|
}
|
|
|
|
|
2006-12-15 17:17:36 +00:00
|
|
|
void print_commit(struct commit *commit)
|
2006-12-11 16:04:19 +00:00
|
|
|
{
|
2006-12-15 17:17:36 +00:00
|
|
|
struct commitinfo *info;
|
2006-12-11 16:04:19 +00:00
|
|
|
|
2006-12-15 17:17:36 +00:00
|
|
|
info = cgit_parse_commit(commit);
|
2006-12-11 16:04:19 +00:00
|
|
|
html("<tr><td>");
|
2007-05-22 21:15:36 +00:00
|
|
|
cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE);
|
2006-12-11 16:04:19 +00:00
|
|
|
html("</td><td>");
|
2008-02-16 10:53:40 +00:00
|
|
|
cgit_commit_link(info->subject, NULL, NULL, ctx.qry.head,
|
2007-06-17 12:53:02 +00:00
|
|
|
sha1_to_hex(commit->object.sha1));
|
2007-05-18 11:55:52 +00:00
|
|
|
if (cgit_repo->enable_log_filecount) {
|
|
|
|
files = 0;
|
2007-11-05 23:35:12 +00:00
|
|
|
add_lines = 0;
|
|
|
|
rem_lines = 0;
|
2007-05-18 11:55:52 +00:00
|
|
|
cgit_diff_commit(commit, inspect_files);
|
|
|
|
html("</td><td class='right'>");
|
|
|
|
htmlf("%d", files);
|
|
|
|
if (cgit_repo->enable_log_linecount) {
|
|
|
|
html("</td><td class='right'>");
|
2007-11-05 23:35:12 +00:00
|
|
|
htmlf("-%d/+%d", rem_lines, add_lines);
|
2007-05-18 11:55:52 +00:00
|
|
|
}
|
|
|
|
}
|
2006-12-11 16:04:19 +00:00
|
|
|
html("</td><td>");
|
2006-12-15 17:17:36 +00:00
|
|
|
html_txt(info->author);
|
2006-12-11 16:04:19 +00:00
|
|
|
html("</td></tr>\n");
|
2006-12-16 13:58:20 +00:00
|
|
|
cgit_free_commitinfo(info);
|
2006-12-11 16:04:19 +00:00
|
|
|
}
|
|
|
|
|
2006-12-15 17:17:36 +00:00
|
|
|
|
2007-10-28 14:23:00 +00:00
|
|
|
void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern, char *path, int pager)
|
2006-12-11 16:04:19 +00:00
|
|
|
{
|
|
|
|
struct rev_info rev;
|
|
|
|
struct commit *commit;
|
2007-05-14 09:10:59 +00:00
|
|
|
const char *argv[] = {NULL, tip, NULL, NULL, NULL};
|
2006-12-28 01:45:28 +00:00
|
|
|
int argc = 2;
|
2006-12-13 23:40:34 +00:00
|
|
|
int i;
|
2007-05-13 09:27:46 +00:00
|
|
|
|
2007-06-17 12:58:45 +00:00
|
|
|
if (!tip)
|
2008-02-16 10:53:40 +00:00
|
|
|
argv[1] = ctx.qry.head;
|
2007-06-17 12:58:45 +00:00
|
|
|
|
2007-10-28 14:23:00 +00:00
|
|
|
if (grep && pattern && (!strcmp(grep, "grep") ||
|
|
|
|
!strcmp(grep, "author") ||
|
|
|
|
!strcmp(grep, "committer")))
|
|
|
|
argv[argc++] = fmt("--%s=%s", grep, pattern);
|
|
|
|
|
2007-05-14 09:10:59 +00:00
|
|
|
if (path) {
|
|
|
|
argv[argc++] = "--";
|
|
|
|
argv[argc++] = path;
|
|
|
|
}
|
2006-12-11 16:04:19 +00: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 01:45:28 +00:00
|
|
|
setup_revisions(argc, argv, &rev, NULL);
|
|
|
|
if (rev.grep_filter) {
|
|
|
|
rev.grep_filter->regflags |= REG_ICASE;
|
|
|
|
compile_grep_patterns(rev.grep_filter);
|
|
|
|
}
|
2006-12-11 16:04:19 +00:00
|
|
|
prepare_revision_walk(&rev);
|
|
|
|
|
2007-11-11 12:04:28 +00:00
|
|
|
html("<table summary='log' class='list nowrap'>");
|
2007-05-22 21:15:36 +00:00
|
|
|
html("<tr class='nohover'><th class='left'>Age</th>"
|
2007-05-18 11:55:52 +00:00
|
|
|
"<th class='left'>Message</th>");
|
|
|
|
|
|
|
|
if (cgit_repo->enable_log_filecount) {
|
2007-11-05 23:35:12 +00:00
|
|
|
html("<th class='right'>Files</th>");
|
2007-05-18 11:55:52 +00:00
|
|
|
if (cgit_repo->enable_log_linecount)
|
2007-11-05 23:35:12 +00:00
|
|
|
html("<th class='right'>Lines</th>");
|
2007-05-18 11:55:52 +00:00
|
|
|
}
|
|
|
|
html("<th class='left'>Author</th></tr>\n");
|
2006-12-13 23:40:34 +00: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 17:17:36 +00:00
|
|
|
print_commit(commit);
|
2006-12-11 16:04:19 +00:00
|
|
|
free(commit->buffer);
|
|
|
|
commit->buffer = NULL;
|
|
|
|
free_commit_list(commit->parents);
|
|
|
|
commit->parents = NULL;
|
|
|
|
}
|
|
|
|
html("</table>\n");
|
2006-12-13 23:40:34 +00:00
|
|
|
|
2007-05-26 01:26:14 +00:00
|
|
|
if (pager) {
|
|
|
|
html("<div class='pager'>");
|
|
|
|
if (ofs > 0) {
|
2008-02-16 10:53:40 +00:00
|
|
|
cgit_log_link("[prev]", NULL, NULL, ctx.qry.head,
|
|
|
|
ctx.qry.sha1, ctx.qry.path,
|
|
|
|
ofs - cnt, ctx.qry.grep,
|
|
|
|
ctx.qry.search);
|
2007-06-29 18:27:41 +00:00
|
|
|
html(" ");
|
2007-05-26 01:26:14 +00:00
|
|
|
}
|
|
|
|
if ((commit = get_revision(&rev)) != NULL) {
|
2008-02-16 10:53:40 +00:00
|
|
|
cgit_log_link("[next]", NULL, NULL, ctx.qry.head,
|
|
|
|
ctx.qry.sha1, ctx.qry.path,
|
|
|
|
ofs + cnt, ctx.qry.grep,
|
|
|
|
ctx.qry.search);
|
2007-05-26 01:26:14 +00:00
|
|
|
}
|
|
|
|
html("</div>");
|
2006-12-13 23:40:34 +00:00
|
|
|
}
|
2006-12-11 16:04:19 +00:00
|
|
|
}
|