2006-12-11 16:04:19 +00:00
|
|
|
/* ui-log.c: functions for log output
|
|
|
|
*
|
2014-01-08 14:10:49 +00:00
|
|
|
* Copyright (C) 2006-2014 cgit Development Team <cgit@lists.zx2c4.com>
|
2006-12-11 16:04:19 +00:00
|
|
|
*
|
|
|
|
* Licensed under GNU General Public License v2
|
|
|
|
* (see COPYING for full license text)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "cgit.h"
|
2013-04-06 10:37:59 +00:00
|
|
|
#include "ui-log.h"
|
2008-02-23 21:45:33 +00:00
|
|
|
#include "html.h"
|
2008-03-24 15:50:57 +00:00
|
|
|
#include "ui-shared.h"
|
2013-11-22 12:24:52 +00:00
|
|
|
#include "argv-array.h"
|
2006-12-11 16:04:19 +00:00
|
|
|
|
2007-11-05 23:35:12 +00:00
|
|
|
int files, add_lines, rem_lines;
|
2007-05-13 09:27:46 +00:00
|
|
|
|
2010-11-15 17:39:51 +00:00
|
|
|
/*
|
|
|
|
* The list of available column colors in the commit graph.
|
|
|
|
*/
|
|
|
|
static const char *column_colors_html[] = {
|
|
|
|
"<span class='column1'>",
|
|
|
|
"<span class='column2'>",
|
|
|
|
"<span class='column3'>",
|
|
|
|
"<span class='column4'>",
|
|
|
|
"<span class='column5'>",
|
|
|
|
"<span class='column6'>",
|
|
|
|
"</span>",
|
|
|
|
};
|
|
|
|
|
|
|
|
#define COLUMN_COLORS_HTML_MAX (ARRAY_SIZE(column_colors_html) - 1)
|
|
|
|
|
2013-03-04 07:52:33 +00:00
|
|
|
static void count_lines(char *line, int size)
|
2007-05-13 15:03:27 +00:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
2013-03-04 07:52:33 +00:00
|
|
|
static void inspect_files(struct diff_filepair *pair)
|
2007-05-13 09:27:46 +00:00
|
|
|
{
|
2009-01-31 09:40:40 +00:00
|
|
|
unsigned long old_size = 0;
|
|
|
|
unsigned long new_size = 0;
|
|
|
|
int binary = 0;
|
|
|
|
|
2007-05-13 09:27:46 +00:00
|
|
|
files++;
|
2008-02-16 12:56:09 +00:00
|
|
|
if (ctx.repo->enable_log_linecount)
|
2009-01-31 09:40:40 +00:00
|
|
|
cgit_diff_files(pair->one->sha1, pair->two->sha1, &old_size,
|
2010-06-24 15:52:57 +00:00
|
|
|
&new_size, &binary, 0, ctx.qry.ignorews,
|
|
|
|
count_lines);
|
2007-05-13 09:27:46 +00:00
|
|
|
}
|
|
|
|
|
2009-01-11 11:16:18 +00: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);
|
2013-05-18 14:54:49 +00:00
|
|
|
html("<span class='decoration'>");
|
2009-01-11 11:16:18 +00:00
|
|
|
while (deco) {
|
2014-05-29 15:35:46 +00:00
|
|
|
if (starts_with(deco->name, "refs/heads/")) {
|
2009-01-11 11:16:18 +00:00
|
|
|
strncpy(buf, deco->name + 11, sizeof(buf) - 1);
|
2010-06-11 12:50:47 +00:00
|
|
|
cgit_log_link(buf, NULL, "branch-deco", buf, NULL,
|
|
|
|
ctx.qry.vpath, 0, NULL, NULL,
|
|
|
|
ctx.qry.showmsg);
|
2009-01-11 11:16:18 +00:00
|
|
|
}
|
2014-05-29 15:35:46 +00:00
|
|
|
else if (starts_with(deco->name, "tag: refs/tags/")) {
|
2009-01-11 11:16:18 +00:00
|
|
|
strncpy(buf, deco->name + 15, sizeof(buf) - 1);
|
|
|
|
cgit_tag_link(buf, NULL, "tag-deco", ctx.qry.head, buf);
|
|
|
|
}
|
2014-05-29 15:35:46 +00:00
|
|
|
else if (starts_with(deco->name, "refs/tags/")) {
|
2009-08-16 17:52:27 +00:00
|
|
|
strncpy(buf, deco->name + 10, sizeof(buf) - 1);
|
|
|
|
cgit_tag_link(buf, NULL, "tag-deco", ctx.qry.head, buf);
|
|
|
|
}
|
2014-05-29 15:35:46 +00:00
|
|
|
else if (starts_with(deco->name, "refs/remotes/")) {
|
2012-01-03 15:30:50 +00:00
|
|
|
if (!ctx.repo->enable_remote_branches)
|
|
|
|
goto next;
|
2009-01-11 11:16:18 +00:00
|
|
|
strncpy(buf, deco->name + 13, sizeof(buf) - 1);
|
|
|
|
cgit_log_link(buf, NULL, "remote-deco", NULL,
|
2010-06-11 12:50:47 +00:00
|
|
|
sha1_to_hex(commit->object.sha1),
|
|
|
|
ctx.qry.vpath, 0, NULL, NULL,
|
|
|
|
ctx.qry.showmsg);
|
2009-01-11 11:16:18 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
strncpy(buf, deco->name, sizeof(buf) - 1);
|
|
|
|
cgit_commit_link(buf, NULL, "deco", ctx.qry.head,
|
2010-06-11 12:50:47 +00:00
|
|
|
sha1_to_hex(commit->object.sha1),
|
|
|
|
ctx.qry.vpath, 0);
|
2009-01-11 11:16:18 +00:00
|
|
|
}
|
2012-01-03 15:30:50 +00:00
|
|
|
next:
|
2009-01-11 11:16:18 +00:00
|
|
|
deco = deco->next;
|
|
|
|
}
|
2013-05-18 14:54:49 +00:00
|
|
|
html("</span>");
|
2009-01-11 11:16:18 +00:00
|
|
|
}
|
|
|
|
|
2013-03-04 07:52:33 +00:00
|
|
|
static void print_commit(struct commit *commit, struct rev_info *revs)
|
2006-12-11 16:04:19 +00:00
|
|
|
{
|
2006-12-15 17:17:36 +00:00
|
|
|
struct commitinfo *info;
|
2013-03-05 14:42:14 +00:00
|
|
|
int columns = revs->graph ? 4 : 3;
|
2010-11-15 17:39:50 +00:00
|
|
|
struct strbuf graphbuf = STRBUF_INIT;
|
2010-11-15 17:39:52 +00:00
|
|
|
struct strbuf msgbuf = STRBUF_INIT;
|
2010-11-15 17:39:50 +00:00
|
|
|
|
2011-03-10 16:03:22 +00:00
|
|
|
if (ctx.repo->enable_log_filecount)
|
2013-03-05 14:42:14 +00:00
|
|
|
columns++;
|
2011-03-10 16:03:22 +00:00
|
|
|
if (ctx.repo->enable_log_linecount)
|
2013-03-05 14:42:14 +00:00
|
|
|
columns++;
|
2010-11-15 17:39:50 +00:00
|
|
|
|
|
|
|
if (revs->graph) {
|
|
|
|
/* Advance graph until current commit */
|
|
|
|
while (!graph_next_line(revs->graph, &graphbuf)) {
|
|
|
|
/* Print graph segment in otherwise empty table row */
|
2010-11-15 17:39:53 +00:00
|
|
|
html("<tr class='nohover'><td class='commitgraph'>");
|
2010-11-15 17:39:50 +00:00
|
|
|
html(graphbuf.buf);
|
2013-03-05 14:42:14 +00:00
|
|
|
htmlf("</td><td colspan='%d' /></tr>\n", columns);
|
2010-11-15 17:39:50 +00:00
|
|
|
strbuf_setlen(&graphbuf, 0);
|
|
|
|
}
|
|
|
|
/* Current commit's graph segment is now ready in graphbuf */
|
|
|
|
}
|
2006-12-11 16:04:19 +00:00
|
|
|
|
2006-12-15 17:17:36 +00:00
|
|
|
info = cgit_parse_commit(commit);
|
2010-11-15 17:39:53 +00:00
|
|
|
htmlf("<tr%s>", ctx.qry.showmsg ? " class='logheader'" : "");
|
2010-11-15 17:39:50 +00:00
|
|
|
|
|
|
|
if (revs->graph) {
|
|
|
|
/* Print graph segment for current commit */
|
|
|
|
html("<td class='commitgraph'>");
|
|
|
|
html(graphbuf.buf);
|
|
|
|
html("</td>");
|
|
|
|
strbuf_setlen(&graphbuf, 0);
|
|
|
|
}
|
2010-11-15 17:39:53 +00:00
|
|
|
else {
|
|
|
|
html("<td>");
|
|
|
|
cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE);
|
|
|
|
html("</td>");
|
|
|
|
}
|
2010-11-15 17:39:50 +00:00
|
|
|
|
|
|
|
htmlf("<td%s>", ctx.qry.showmsg ? " class='logsubject'" : "");
|
2010-11-15 17:39:52 +00:00
|
|
|
if (ctx.qry.showmsg) {
|
|
|
|
/* line-wrap long commit subjects instead of truncating them */
|
|
|
|
size_t subject_len = strlen(info->subject);
|
|
|
|
|
|
|
|
if (subject_len > ctx.cfg.max_msg_len &&
|
|
|
|
ctx.cfg.max_msg_len >= 15) {
|
|
|
|
/* symbol for signaling line-wrap (in PAGE_ENCODING) */
|
|
|
|
const char wrap_symbol[] = { ' ', 0xE2, 0x86, 0xB5, 0 };
|
|
|
|
int i = ctx.cfg.max_msg_len - strlen(wrap_symbol);
|
|
|
|
|
|
|
|
/* Rewind i to preceding space character */
|
|
|
|
while (i > 0 && !isspace(info->subject[i]))
|
|
|
|
--i;
|
|
|
|
if (!i) /* Oops, zero spaces. Reset i */
|
|
|
|
i = ctx.cfg.max_msg_len - strlen(wrap_symbol);
|
|
|
|
|
|
|
|
/* add remainder starting at i to msgbuf */
|
|
|
|
strbuf_add(&msgbuf, info->subject + i, subject_len - i);
|
|
|
|
strbuf_trim(&msgbuf);
|
|
|
|
strbuf_add(&msgbuf, "\n\n", 2);
|
|
|
|
|
|
|
|
/* Place wrap_symbol at position i in info->subject */
|
|
|
|
strcpy(info->subject + i, wrap_symbol);
|
|
|
|
}
|
|
|
|
}
|
2008-02-16 10:53:40 +00:00
|
|
|
cgit_commit_link(info->subject, NULL, NULL, ctx.qry.head,
|
2010-06-11 12:50:47 +00:00
|
|
|
sha1_to_hex(commit->object.sha1), ctx.qry.vpath, 0);
|
2009-01-11 11:16:18 +00:00
|
|
|
show_commit_decorations(commit);
|
2008-04-14 20:13:38 +00:00
|
|
|
html("</td><td>");
|
2014-01-13 15:24:40 +00:00
|
|
|
cgit_open_filter(ctx.repo->email_filter, info->author_email, "log");
|
2008-04-14 20:13:38 +00:00
|
|
|
html_txt(info->author);
|
2014-01-13 03:04:52 +00:00
|
|
|
cgit_close_filter(ctx.repo->email_filter);
|
2010-11-15 17:39:53 +00:00
|
|
|
|
|
|
|
if (revs->graph) {
|
|
|
|
html("</td><td>");
|
|
|
|
cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE);
|
|
|
|
}
|
|
|
|
|
2011-03-10 16:03:22 +00:00
|
|
|
if (ctx.repo->enable_log_filecount || ctx.repo->enable_log_linecount) {
|
2007-05-18 11:55:52 +00:00
|
|
|
files = 0;
|
2007-11-05 23:35:12 +00:00
|
|
|
add_lines = 0;
|
|
|
|
rem_lines = 0;
|
2010-09-30 18:15:14 +00:00
|
|
|
cgit_diff_commit(commit, inspect_files, ctx.qry.vpath);
|
2007-05-18 11:55:52 +00:00
|
|
|
}
|
2011-03-10 16:03:22 +00:00
|
|
|
|
|
|
|
if (ctx.repo->enable_log_filecount)
|
|
|
|
htmlf("</td><td>%d", files);
|
|
|
|
if (ctx.repo->enable_log_linecount)
|
|
|
|
htmlf("</td><td>-%d/+%d", rem_lines, add_lines);
|
|
|
|
|
2006-12-11 16:04:19 +00:00
|
|
|
html("</td></tr>\n");
|
2010-11-15 17:39:49 +00:00
|
|
|
|
2010-11-15 17:39:50 +00:00
|
|
|
if (revs->graph || ctx.qry.showmsg) { /* Print a second table row */
|
2010-11-15 17:39:53 +00:00
|
|
|
html("<tr class='nohover'>");
|
2010-11-15 17:39:50 +00:00
|
|
|
|
|
|
|
if (ctx.qry.showmsg) {
|
|
|
|
/* Concatenate commit message + notes in msgbuf */
|
|
|
|
if (info->msg && *(info->msg)) {
|
|
|
|
strbuf_addstr(&msgbuf, info->msg);
|
|
|
|
strbuf_addch(&msgbuf, '\n');
|
|
|
|
}
|
2013-04-08 08:00:22 +00:00
|
|
|
format_display_notes(commit->object.sha1,
|
|
|
|
&msgbuf, PAGE_ENCODING, 0);
|
2010-11-15 17:39:49 +00:00
|
|
|
strbuf_addch(&msgbuf, '\n');
|
2010-11-15 17:39:50 +00:00
|
|
|
strbuf_ltrim(&msgbuf);
|
2010-11-15 17:39:49 +00:00
|
|
|
}
|
2010-07-29 14:32:31 +00:00
|
|
|
|
2010-11-15 17:39:50 +00:00
|
|
|
if (revs->graph) {
|
|
|
|
int lines = 0;
|
|
|
|
|
|
|
|
/* Calculate graph padding */
|
|
|
|
if (ctx.qry.showmsg) {
|
|
|
|
/* Count #lines in commit message + notes */
|
|
|
|
const char *p = msgbuf.buf;
|
|
|
|
lines = 1;
|
|
|
|
while ((p = strchr(p, '\n'))) {
|
|
|
|
p++;
|
|
|
|
lines++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Print graph padding */
|
|
|
|
html("<td class='commitgraph'>");
|
|
|
|
while (lines > 0 || !graph_is_commit_finished(revs->graph)) {
|
|
|
|
if (graphbuf.len)
|
|
|
|
html("\n");
|
|
|
|
strbuf_setlen(&graphbuf, 0);
|
|
|
|
graph_next_line(revs->graph, &graphbuf);
|
|
|
|
html(graphbuf.buf);
|
|
|
|
lines--;
|
|
|
|
}
|
|
|
|
html("</td>\n");
|
2008-11-29 17:39:41 +00:00
|
|
|
}
|
2010-11-15 17:39:53 +00:00
|
|
|
else
|
|
|
|
html("<td/>"); /* Empty 'Age' column */
|
2010-11-15 17:39:49 +00:00
|
|
|
|
2010-11-15 17:39:50 +00:00
|
|
|
/* Print msgbuf into remainder of table row */
|
2013-03-05 14:42:14 +00:00
|
|
|
htmlf("<td colspan='%d'%s>\n", columns - (revs->graph ? 1 : 0),
|
2010-11-15 17:39:50 +00:00
|
|
|
ctx.qry.showmsg ? " class='logmsg'" : "");
|
2010-11-15 17:39:49 +00:00
|
|
|
html_txt(msgbuf.buf);
|
2008-11-29 18:11:26 +00:00
|
|
|
html("</td></tr>\n");
|
2008-11-29 17:39:41 +00:00
|
|
|
}
|
2010-11-15 17:39:49 +00:00
|
|
|
|
2010-11-15 17:39:52 +00:00
|
|
|
strbuf_release(&msgbuf);
|
2010-11-15 17:39:50 +00:00
|
|
|
strbuf_release(&graphbuf);
|
2006-12-16 13:58:20 +00:00
|
|
|
cgit_free_commitinfo(info);
|
2006-12-11 16:04:19 +00:00
|
|
|
}
|
|
|
|
|
2013-04-06 09:28:57 +00:00
|
|
|
static const char *disambiguate_ref(const char *ref, int *must_free_result)
|
2008-12-03 16:34:23 +00:00
|
|
|
{
|
|
|
|
unsigned char sha1[20];
|
2013-04-06 09:28:57 +00:00
|
|
|
struct strbuf longref = STRBUF_INIT;
|
2008-12-03 16:34:23 +00:00
|
|
|
|
2013-04-06 09:28:57 +00:00
|
|
|
strbuf_addf(&longref, "refs/heads/%s", ref);
|
|
|
|
if (get_sha1(longref.buf, sha1) == 0) {
|
|
|
|
*must_free_result = 1;
|
|
|
|
return strbuf_detach(&longref, NULL);
|
|
|
|
}
|
2008-12-03 16:34:23 +00:00
|
|
|
|
2013-04-06 09:28:57 +00:00
|
|
|
*must_free_result = 0;
|
|
|
|
strbuf_release(&longref);
|
2008-12-03 16:34:23 +00:00
|
|
|
return ref;
|
|
|
|
}
|
2006-12-15 17:17:36 +00:00
|
|
|
|
2010-11-09 19:53:36 +00:00
|
|
|
static char *next_token(char **src)
|
|
|
|
{
|
|
|
|
char *result;
|
|
|
|
|
|
|
|
if (!src || !*src)
|
|
|
|
return NULL;
|
|
|
|
while (isspace(**src))
|
|
|
|
(*src)++;
|
|
|
|
if (!**src)
|
|
|
|
return NULL;
|
|
|
|
result = *src;
|
|
|
|
while (**src) {
|
|
|
|
if (isspace(**src)) {
|
|
|
|
**src = '\0';
|
|
|
|
(*src)++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
(*src)++;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2008-04-14 20:13:38 +00:00
|
|
|
void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern,
|
2012-10-13 14:10:30 +00:00
|
|
|
char *path, int pager, int commit_graph, int commit_sort)
|
2006-12-11 16:04:19 +00:00
|
|
|
{
|
|
|
|
struct rev_info rev;
|
|
|
|
struct commit *commit;
|
2013-11-22 12:24:52 +00:00
|
|
|
struct argv_array rev_argv = ARGV_ARRAY_INIT;
|
2013-03-05 14:42:14 +00:00
|
|
|
int i, columns = commit_graph ? 4 : 3;
|
2013-04-06 09:28:57 +00:00
|
|
|
int must_free_tip = 0;
|
2010-11-09 19:53:36 +00:00
|
|
|
|
2013-11-22 12:24:52 +00:00
|
|
|
/* rev_argv.argv[0] will be ignored by setup_revisions */
|
|
|
|
argv_array_push(&rev_argv, "log_rev_setup");
|
2007-05-13 09:27:46 +00:00
|
|
|
|
2007-06-17 12:58:45 +00:00
|
|
|
if (!tip)
|
2008-12-03 16:34:23 +00:00
|
|
|
tip = ctx.qry.head;
|
2013-04-06 09:28:57 +00:00
|
|
|
tip = disambiguate_ref(tip, &must_free_tip);
|
2013-11-22 12:24:52 +00:00
|
|
|
argv_array_push(&rev_argv, tip);
|
2007-06-17 12:58:45 +00:00
|
|
|
|
2010-10-28 15:05:39 +00:00
|
|
|
if (grep && pattern && *pattern) {
|
2010-11-09 19:53:36 +00:00
|
|
|
pattern = xstrdup(pattern);
|
2010-06-19 12:32:37 +00:00
|
|
|
if (!strcmp(grep, "grep") || !strcmp(grep, "author") ||
|
2010-11-09 19:53:36 +00:00
|
|
|
!strcmp(grep, "committer")) {
|
2013-11-22 12:30:58 +00:00
|
|
|
argv_array_pushf(&rev_argv, "--%s=%s", grep, pattern);
|
|
|
|
} else if (!strcmp(grep, "range")) {
|
2013-04-06 09:28:57 +00:00
|
|
|
char *arg;
|
2010-11-09 19:53:36 +00:00
|
|
|
/* Split the pattern at whitespace and add each token
|
|
|
|
* as a revision expression. Do not accept other
|
|
|
|
* rev-list options. Also, replace the previously
|
|
|
|
* pushed tip (it's no longer relevant).
|
|
|
|
*/
|
2013-11-22 12:24:52 +00:00
|
|
|
argv_array_pop(&rev_argv);
|
2010-11-09 19:53:36 +00:00
|
|
|
while ((arg = next_token(&pattern))) {
|
|
|
|
if (*arg == '-') {
|
|
|
|
fprintf(stderr, "Bad range expr: %s\n",
|
|
|
|
arg);
|
|
|
|
break;
|
|
|
|
}
|
2013-11-22 12:24:52 +00:00
|
|
|
argv_array_push(&rev_argv, arg);
|
2010-11-09 19:53:36 +00:00
|
|
|
}
|
|
|
|
}
|
2010-06-19 12:32:37 +00:00
|
|
|
}
|
2010-11-15 17:39:52 +00:00
|
|
|
if (commit_graph) {
|
2013-11-22 12:30:58 +00:00
|
|
|
argv_array_push(&rev_argv, "--graph");
|
|
|
|
argv_array_push(&rev_argv, "--color");
|
2010-11-15 17:39:51 +00:00
|
|
|
graph_set_column_colors(column_colors_html,
|
|
|
|
COLUMN_COLORS_HTML_MAX);
|
2010-11-15 17:39:50 +00:00
|
|
|
}
|
2007-10-28 14:23:00 +00:00
|
|
|
|
2013-11-22 12:30:58 +00:00
|
|
|
if (commit_sort == 1)
|
|
|
|
argv_array_push(&rev_argv, "--date-order");
|
|
|
|
else if (commit_sort == 2)
|
|
|
|
argv_array_push(&rev_argv, "--topo-order");
|
2012-10-13 14:10:30 +00:00
|
|
|
|
ui-log: ignore unhandled arguments
If you search for a bogus range string here:
http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/log/
Using something like "range" and "qwerty123456", it returns an "Internal
Server Error" and the following in the logs:
> [Tue Jun 10 17:45:32 2014] [error] [client 172.21.1.6] fatal:
> ambiguous argument 'qwerty123456': unknown revision or path not in the
> working tree., referer:
> http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/
> [Tue Jun 10 17:45:32 2014] [error] [client 172.21.1.6] Use '--' to
> separate paths from revisions, like this:, referer:
> http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/
> [Tue Jun 10 17:45:32 2014] [error] [client 172.21.1.6] 'git <command>
> [<revision>...] -- [<file>...]', referer:
> http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/
> [Tue Jun 10 17:45:32 2014] [error] [client 172.21.1.6] Premature end
> of script headers: cgit, referer:
> http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/
The cache will kick in, so if you search for the same string again,
it'll show an empty range, so you have to change the bogus strings each
time.
This is because we just pass the arguments straight to Git's revision
parsing machinery which die()s if it cannot parse an argument, printing
the above to stderr and exiting.
The patch below makes it a bit friendlier by just ignoring unhandled
arguments, but I can't see an easy way to report errors when we can't
parse revision arguments without losing the flexibility of supporting
all of the revision specifiers supported by Git.
Reported-by: Konstantin Ryabitsev <mricon@kernel.org>
2014-06-28 13:55:06 +00:00
|
|
|
argv_array_push(&rev_argv, "--");
|
|
|
|
if (path)
|
2013-11-22 12:24:52 +00:00
|
|
|
argv_array_push(&rev_argv, path);
|
2010-11-09 19:53:36 +00:00
|
|
|
|
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;
|
ui-log: ignore unhandled arguments
If you search for a bogus range string here:
http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/log/
Using something like "range" and "qwerty123456", it returns an "Internal
Server Error" and the following in the logs:
> [Tue Jun 10 17:45:32 2014] [error] [client 172.21.1.6] fatal:
> ambiguous argument 'qwerty123456': unknown revision or path not in the
> working tree., referer:
> http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/
> [Tue Jun 10 17:45:32 2014] [error] [client 172.21.1.6] Use '--' to
> separate paths from revisions, like this:, referer:
> http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/
> [Tue Jun 10 17:45:32 2014] [error] [client 172.21.1.6] 'git <command>
> [<revision>...] -- [<file>...]', referer:
> http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/
> [Tue Jun 10 17:45:32 2014] [error] [client 172.21.1.6] Premature end
> of script headers: cgit, referer:
> http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/
The cache will kick in, so if you search for the same string again,
it'll show an empty range, so you have to change the bogus strings each
time.
This is because we just pass the arguments straight to Git's revision
parsing machinery which die()s if it cannot parse an argument, printing
the above to stderr and exiting.
The patch below makes it a bit friendlier by just ignoring unhandled
arguments, but I can't see an easy way to report errors when we can't
parse revision arguments without losing the flexibility of supporting
all of the revision specifiers supported by Git.
Reported-by: Konstantin Ryabitsev <mricon@kernel.org>
2014-06-28 13:55:06 +00:00
|
|
|
rev.ignore_missing = 1;
|
2013-11-22 12:24:52 +00:00
|
|
|
setup_revisions(rev_argv.argc, rev_argv.argv, &rev, NULL);
|
2009-09-13 19:56:45 +00:00
|
|
|
load_ref_decorations(DECORATE_FULL_REFS);
|
2009-01-11 11:16:18 +00:00
|
|
|
rev.show_decorations = 1;
|
2008-10-05 17:19:59 +00:00
|
|
|
rev.grep_filter.regflags |= REG_ICASE;
|
|
|
|
compile_grep_patterns(&rev.grep_filter);
|
2006-12-11 16:04:19 +00:00
|
|
|
prepare_revision_walk(&rev);
|
|
|
|
|
2008-04-14 20:13:38 +00:00
|
|
|
if (pager)
|
|
|
|
html("<table class='list nowrap'>");
|
2007-05-18 11:55:52 +00:00
|
|
|
|
2010-11-15 17:39:53 +00:00
|
|
|
html("<tr class='nohover'>");
|
2010-11-15 17:39:52 +00:00
|
|
|
if (commit_graph)
|
2010-11-15 17:39:50 +00:00
|
|
|
html("<th></th>");
|
2010-11-15 17:39:53 +00:00
|
|
|
else
|
|
|
|
html("<th class='left'>Age</th>");
|
2010-11-15 17:39:50 +00:00
|
|
|
html("<th class='left'>Commit message");
|
2008-11-29 17:39:41 +00:00
|
|
|
if (pager) {
|
|
|
|
html(" (");
|
2009-01-09 22:35:10 +00:00
|
|
|
cgit_log_link(ctx.qry.showmsg ? "Collapse" : "Expand", NULL,
|
|
|
|
NULL, ctx.qry.head, ctx.qry.sha1,
|
2010-06-11 12:50:47 +00:00
|
|
|
ctx.qry.vpath, ctx.qry.ofs, ctx.qry.grep,
|
2008-11-29 17:39:41 +00:00
|
|
|
ctx.qry.search, ctx.qry.showmsg ? 0 : 1);
|
|
|
|
html(")");
|
|
|
|
}
|
|
|
|
html("</th><th class='left'>Author</th>");
|
2010-11-15 17:39:53 +00:00
|
|
|
if (commit_graph)
|
|
|
|
html("<th class='left'>Age</th>");
|
2008-02-16 12:56:09 +00:00
|
|
|
if (ctx.repo->enable_log_filecount) {
|
2008-04-14 20:13:38 +00:00
|
|
|
html("<th class='left'>Files</th>");
|
|
|
|
columns++;
|
2011-03-10 16:03:22 +00:00
|
|
|
}
|
|
|
|
if (ctx.repo->enable_log_linecount) {
|
|
|
|
html("<th class='left'>Lines</th>");
|
|
|
|
columns++;
|
2007-05-18 11:55:52 +00:00
|
|
|
}
|
2008-04-14 20:13:38 +00:00
|
|
|
html("</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++) {
|
2014-07-27 10:56:19 +00:00
|
|
|
free_commit_buffer(commit);
|
2006-12-13 23:40:34 +00:00
|
|
|
free_commit_list(commit->parents);
|
|
|
|
commit->parents = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) {
|
2010-11-15 17:39:50 +00:00
|
|
|
print_commit(commit, &rev);
|
2014-07-27 10:56:19 +00:00
|
|
|
free_commit_buffer(commit);
|
2006-12-11 16:04:19 +00:00
|
|
|
free_commit_list(commit->parents);
|
|
|
|
commit->parents = NULL;
|
|
|
|
}
|
2007-05-26 01:26:14 +00:00
|
|
|
if (pager) {
|
2013-03-07 07:56:22 +00:00
|
|
|
html("</table><ul class='pager'>");
|
2007-05-26 01:26:14 +00:00
|
|
|
if (ofs > 0) {
|
2013-03-07 07:56:22 +00:00
|
|
|
html("<li>");
|
2008-02-16 10:53:40 +00:00
|
|
|
cgit_log_link("[prev]", NULL, NULL, ctx.qry.head,
|
2010-06-11 12:50:47 +00:00
|
|
|
ctx.qry.sha1, ctx.qry.vpath,
|
2008-02-16 10:53:40 +00:00
|
|
|
ofs - cnt, ctx.qry.grep,
|
2008-11-29 17:39:41 +00:00
|
|
|
ctx.qry.search, ctx.qry.showmsg);
|
2013-03-07 07:56:22 +00:00
|
|
|
html("</li>");
|
2007-05-26 01:26:14 +00:00
|
|
|
}
|
|
|
|
if ((commit = get_revision(&rev)) != NULL) {
|
2013-03-07 07:56:22 +00:00
|
|
|
html("<li>");
|
2008-02-16 10:53:40 +00:00
|
|
|
cgit_log_link("[next]", NULL, NULL, ctx.qry.head,
|
2010-06-11 12:50:47 +00:00
|
|
|
ctx.qry.sha1, ctx.qry.vpath,
|
2008-02-16 10:53:40 +00:00
|
|
|
ofs + cnt, ctx.qry.grep,
|
2008-11-29 17:39:41 +00:00
|
|
|
ctx.qry.search, ctx.qry.showmsg);
|
2013-03-07 07:56:22 +00:00
|
|
|
html("</li>");
|
2007-05-26 01:26:14 +00:00
|
|
|
}
|
2013-03-07 07:56:22 +00:00
|
|
|
html("</ul>");
|
2008-04-14 20:13:38 +00:00
|
|
|
} else if ((commit = get_revision(&rev)) != NULL) {
|
2013-03-05 14:42:14 +00:00
|
|
|
htmlf("<tr class='nohover'><td colspan='%d'>", columns);
|
2010-06-11 12:50:47 +00:00
|
|
|
cgit_log_link("[...]", NULL, NULL, ctx.qry.head, NULL,
|
|
|
|
ctx.qry.vpath, 0, NULL, NULL, ctx.qry.showmsg);
|
2008-04-14 20:13:38 +00:00
|
|
|
html("</td></tr>\n");
|
2006-12-13 23:40:34 +00:00
|
|
|
}
|
2013-04-06 09:28:57 +00:00
|
|
|
|
|
|
|
/* If we allocated tip then it is safe to cast away const. */
|
|
|
|
if (must_free_tip)
|
|
|
|
free((char*) tip);
|
2006-12-11 16:04:19 +00:00
|
|
|
}
|