X-Git-Url: https://gitweb.ps.run/ps-cgit/blobdiff_plain/6821d8ea4a64d15b8f284d1af01ab184ef1e76c3..9a8d39c668b98464bac97d4e5442966de63f97b2:/ui-log.c
diff --git a/ui-log.c b/ui-log.c
index ee93653..0d86fd5 100644
--- a/ui-log.c
+++ b/ui-log.c
@@ -9,6 +9,7 @@
#include "cgit.h"
#include "html.h"
#include "ui-shared.h"
+#include "vector.h"
int files, add_lines, rem_lines;
@@ -76,11 +77,30 @@ void show_commit_decorations(struct commit *commit)
}
}
-void print_commit(struct commit *commit)
+void print_commit(struct commit *commit, struct rev_info *revs)
{
struct commitinfo *info;
char *tmp;
int cols = 2;
+ struct strbuf graphbuf = STRBUF_INIT;
+
+ if (ctx.repo->enable_log_filecount) {
+ cols++;
+ if (ctx.repo->enable_log_linecount)
+ cols++;
+ }
+
+ if (revs->graph) {
+ /* Advance graph until current commit */
+ while (!graph_next_line(revs->graph, &graphbuf)) {
+ /* Print graph segment in otherwise empty table row */
+ html("
| ");
+ html(graphbuf.buf);
+ htmlf(" | |
\n", cols);
+ strbuf_setlen(&graphbuf, 0);
+ }
+ /* Current commit's graph segment is now ready in graphbuf */
+ }
info = cgit_parse_commit(commit);
htmlf("| ",
@@ -90,8 +110,17 @@ void print_commit(struct commit *commit)
html_link_open(tmp, NULL, NULL);
cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE);
html_link_close();
- htmlf(" | ",
- ctx.qry.showmsg ? " class='logsubject'" : "");
+ html(" | ");
+
+ if (revs->graph) {
+ /* Print graph segment for current commit */
+ html("");
+ html(graphbuf.buf);
+ html(" | ");
+ strbuf_setlen(&graphbuf, 0);
+ }
+
+ htmlf("", ctx.qry.showmsg ? " class='logsubject'" : "");
cgit_commit_link(info->subject, NULL, NULL, ctx.qry.head,
sha1_to_hex(commit->object.sha1), ctx.qry.vpath, 0);
show_commit_decorations(commit);
@@ -101,7 +130,7 @@ void print_commit(struct commit *commit)
files = 0;
add_lines = 0;
rem_lines = 0;
- cgit_diff_commit(commit, inspect_files);
+ cgit_diff_commit(commit, inspect_files, ctx.qry.vpath);
html(" | ");
htmlf("%d", files);
if (ctx.repo->enable_log_linecount) {
@@ -110,17 +139,60 @@ void print_commit(struct commit *commit)
}
}
html(" |
\n");
- if (ctx.qry.showmsg) {
- if (ctx.repo->enable_log_filecount) {
- cols++;
- if (ctx.repo->enable_log_linecount)
- cols++;
+
+ if (revs->graph || ctx.qry.showmsg) { /* Print a second table row */
+ struct strbuf msgbuf = STRBUF_INIT;
+ html(" | "); /* Empty 'Age' column */
+
+ if (ctx.qry.showmsg) {
+ /* Concatenate commit message + notes in msgbuf */
+ if (info->msg && *(info->msg)) {
+ strbuf_addstr(&msgbuf, info->msg);
+ strbuf_addch(&msgbuf, '\n');
+ }
+ format_note(NULL, commit->object.sha1, &msgbuf,
+ PAGE_ENCODING,
+ NOTES_SHOW_HEADER | NOTES_INDENT);
+ strbuf_addch(&msgbuf, '\n');
+ strbuf_ltrim(&msgbuf);
+ }
+
+ 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("");
+ 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(" | \n");
}
- htmlf("
| ",
- cols);
- html_txt(info->msg);
+
+ /* Print msgbuf into remainder of table row */
+ htmlf(" | \n", cols,
+ ctx.qry.showmsg ? " class='logmsg'" : "");
+ html_txt(msgbuf.buf);
html(" |
\n");
+ strbuf_release(&msgbuf);
}
+
+ strbuf_release(&graphbuf);
cgit_free_commitinfo(info);
}
@@ -136,38 +208,90 @@ static const char *disambiguate_ref(const char *ref)
return ref;
}
+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;
+}
+
void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern,
char *path, int pager)
{
struct rev_info rev;
struct commit *commit;
- const char *argv[] = {NULL, NULL, NULL, NULL, NULL};
- int argc = 2;
+ struct vector vec = VECTOR_INIT(char *);
int i, columns = 3;
+ char *arg;
+
+ /* First argv is NULL */
+ vector_push(&vec, NULL, 0);
if (!tip)
tip = ctx.qry.head;
+ tip = disambiguate_ref(tip);
+ vector_push(&vec, &tip, 0);
- argv[1] = disambiguate_ref(tip);
-
- if (grep && pattern) {
+ if (grep && pattern && *pattern) {
+ pattern = xstrdup(pattern);
if (!strcmp(grep, "grep") || !strcmp(grep, "author") ||
- !strcmp(grep, "committer"))
- argv[argc++] = fmt("--%s=%s", grep, pattern);
- if (!strcmp(grep, "range"))
- argv[1] = pattern;
+ !strcmp(grep, "committer")) {
+ arg = fmt("--%s=%s", grep, pattern);
+ vector_push(&vec, &arg, 0);
+ }
+ if (!strcmp(grep, "range")) {
+ /* 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).
+ */
+ vec.count--;
+ while ((arg = next_token(&pattern))) {
+ if (*arg == '-') {
+ fprintf(stderr, "Bad range expr: %s\n",
+ arg);
+ break;
+ }
+ vector_push(&vec, &arg, 0);
+ }
+ }
+ }
+ if (ctx.repo->enable_commit_graph) {
+ static const char *graph_arg = "--graph";
+ vector_push(&vec, &graph_arg, 0);
}
if (path) {
- argv[argc++] = "--";
- argv[argc++] = path;
+ arg = "--";
+ vector_push(&vec, &arg, 0);
+ vector_push(&vec, &path, 0);
}
+
+ /* Make sure the vector is NULL-terminated */
+ vector_push(&vec, NULL, 0);
+ vec.count--;
+
init_revisions(&rev, NULL);
rev.abbrev = DEFAULT_ABBREV;
rev.commit_format = CMIT_FMT_DEFAULT;
rev.verbose_header = 1;
rev.show_root_diff = 0;
- setup_revisions(argc, argv, &rev, NULL);
+ setup_revisions(vec.count, vec.data, &rev, NULL);
load_ref_decorations(DECORATE_FULL_REFS);
rev.show_decorations = 1;
rev.grep_filter.regflags |= REG_ICASE;
@@ -177,8 +301,10 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern
if (pager)
html("");
- html("| Age | "
- "Commit message");
+ html(" |
|---|
| Age | ");
+ if (ctx.repo->enable_commit_graph)
+ html(" | ");
+ html("Commit message");
if (pager) {
html(" (");
cgit_log_link(ctx.qry.showmsg ? "Collapse" : "Expand", NULL,
@@ -209,15 +335,14 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern
}
for (i = 0; i < cnt && (commit = get_revision(&rev)) != NULL; i++) {
- print_commit(commit);
+ print_commit(commit, &rev);
free(commit->buffer);
commit->buffer = NULL;
free_commit_list(commit->parents);
commit->parents = NULL;
}
if (pager) {
- htmlf(" |
|---|