git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[CGit RFC/PATCH 5/5] ui-log: Colorize commit graph

From
Johan Herland <johan@herland.net>
Date
Jul 13, 2010, 21:40 UTC
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 <span> tags that apply the desired color using CSS.

Signed-off-by: Johan Herland <johan@herland.net>
---
 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
Previous: Johan Herland
Message 12 of 12 in “Preparing the graph API for external users”
  1. 0/2 Preparing the graph API for external usersJohan Herland, Jul 13, 2010
  2. 1/2 Make graph_next_line() available in the graph.h APIJohan Herland, Jul 13, 2010
  3. 2/2 Enable custom schemes for column colors in the graph APIJohan Herland, Jul 13, 2010
  4. 0/5 Commit graph on CGit's 'log' viewJohan Herland, Jul 13, 2010
  5. Lars HjemliJul 13, 2010
  6. Johan HerlandJul 14, 2010
  7. Lars HjemliJul 18, 2010
  8. 1/5 ui-stats: Remove unnecessary #includeJohan Herland, Jul 13, 2010
  9. 2/5 ui-log: Move 'Age' column to the right of 'Author', like in gitkJohan Herland, Jul 13, 2010
  10. 3/5 ui-log: Refactor display of commit messagesJohan Herland, Jul 13, 2010
  11. 4/5 ui-log: Implement support for commit graphsJohan Herland, Jul 13, 2010
  12. 5/5 ui-log: Colorize commit graphJohan Herland, Jul 13, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.