Use the existing coloring logic in Git's graph code to color the lines between commits in the commit graph. Whereas Git normally uses ANSI color escapes to produce colors, we here use graph_set_column_colors() to replace those with "HTML color escapes" which embed the graph lines in <span> tags that apply the desired color using CSS. Signed-off-by: Johan Herland <johan@xxxxxxxxxxx> --- cgit.css | 24 ++++++++++++++++++++++++ ui-log.c | 29 ++++++++++++++++++++++++----- 2 files changed, 48 insertions(+), 5 deletions(-) diff --git a/cgit.css b/cgit.css index 65da960..e8be2b1 100644 --- a/cgit.css +++ b/cgit.css @@ -158,6 +158,30 @@ table.list td.commitgraph { white-space: pre; } +table.list td.commitgraph .column1 { + color: #a00; +} + +table.list td.commitgraph .column2 { + color: #0a0; +} + +table.list td.commitgraph .column3 { + color: #aa0; +} + +table.list td.commitgraph .column4 { + color: #00a; +} + +table.list td.commitgraph .column5 { + color: #a0a; +} + +table.list td.commitgraph .column6 { + color: #0aa; +} + table.list td.logsubject { font-family: monospace; font-weight: bold; diff --git a/ui-log.c b/ui-log.c index 3cfe3f9..2fc8c7b 100644 --- a/ui-log.c +++ b/ui-log.c @@ -12,6 +12,21 @@ int files, add_lines, rem_lines; +/* + * 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) + void count_lines(char *line, int size) { if (size <= 0) @@ -123,14 +138,14 @@ void print_commit(struct commit *commit, struct rev_info *revs) while (!graph_next_line(revs->graph, &msgbuf)) { /* Create graph line + empty table row */ html("<tr class='nohover'><td class='commitgraph'>"); - html_txt(msgbuf.buf); + html(msgbuf.buf); htmlf("</td><td colspan='%d' /></tr>\n", cols); strbuf_setlen(&msgbuf, 0); } /* Create graph line + commit info table row */ htmlf("<tr%s>", ctx.qry.showmsg ? " class='logheader'" : ""); html("<td class='commitgraph'>"); - html_txt(msgbuf.buf); + html(msgbuf.buf); html("</td>"); strbuf_release(&msgbuf); } @@ -162,7 +177,7 @@ void print_commit(struct commit *commit, struct rev_info *revs) html("\n"); strbuf_setlen(&msgbuf, 0); graph_next_line(revs->graph, &msgbuf); - html_txt(msgbuf.buf); + html(msgbuf.buf); lines--; } @@ -205,7 +220,7 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern { struct rev_info rev; struct commit *commit; - const char *argv[] = {NULL, NULL, NULL, NULL, NULL, NULL}; + const char *argv[] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL}; int argc = 2; int i, columns = 3; @@ -221,8 +236,12 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern if (!strcmp(grep, "range")) argv[1] = pattern; } - if (ctx.repo->enable_commit_graph) + if (ctx.repo->enable_commit_graph) { argv[argc++] = "--graph"; + argv[argc++] = "--color"; + graph_set_column_colors(column_colors_html, + COLUMN_COLORS_HTML_MAX); + } if (path) { argv[argc++] = "--"; -- 1.7.0.4 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html