From: Johan Herland Date: Tue, 13 Jul 2010 21:40:21 GMT Subject: [CGit RFC/PATCH 5/5] ui-log: Colorize commit graph Message-ID: <1279057221-28036-6-git-send-email-johan@herland.net> In-Reply-To: <1279056219-27096-1-git-send-email-johan@herland.net> 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 tags that apply the desired color using CSS. Signed-off-by: Johan Herland --- 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[] = { + "", + "", + "", + "", + "", + "", + "", +}; + +#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(""); - html_txt(msgbuf.buf); + html(msgbuf.buf); htmlf("\n", cols); strbuf_setlen(&msgbuf, 0); } /* Create graph line + commit info table row */ htmlf("", ctx.qry.showmsg ? " class='logheader'" : ""); html(""); - html_txt(msgbuf.buf); + html(msgbuf.buf); html(""); 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