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

[PATCH] graph API: use a new color when starting a brand new column

From
ASAdam Simpkins <simpkins@facebook.com>
Date
Aug 18, 2009, 21:41 UTC
Message-ID
<20090818214112.GM8147@facebook.com>

Use a new color for commits that don't have any previously printed children. The following command demonstrates the changes:

  git log --graph --pretty=tformat:'%h %s%n' -7 481c7a6 18b0793

Now the two independent lines of development are displayed with different colors, instead of both using the same color.

Signed-off-by: Adam Simpkins <simpkins@facebook.com>
---
 graph.c |   14 +++++++++++---
 1 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/graph.c b/graph.c
index e466770..f3226ec 100644
--- a/graph.c
+++ b/graph.c
@@ -225,7 +225,12 @@ struct git_graph *graph_init(struct rev_info *opt)
 	graph->num_columns = 0;
 	graph->num_new_columns = 0;
 	graph->mapping_size = 0;
-	graph->default_column_color = 0;
+	/*
+	 * Start the column color at the maximum value, since we'll
+	 * always increment it for the first commit we output.
+	 * This way we start at 0 for the first commit.
+	 */
+	graph->default_column_color = COLUMN_COLORS_MAX - 1;
 
 	/*
 	 * Allocate a reasonably large default number of columns
@@ -499,11 +504,14 @@ static void graph_update_columns(struct git_graph *graph)
 			     parent;
 			     parent = next_interesting_parent(graph, parent)) {
 				/*
-				 * If this is a merge increment the current
+				 * If this is a merge, or the start of a new
+				 * childless column, increment the current
 				 * color.
 				 */
-				if (graph->num_parents > 1)
+				if (graph->num_parents > 1 ||
+				    !is_commit_in_columns) {
 					graph_increment_column_color(graph);
+				}
 				graph_insert_into_new_columns(graph,
 							      parent->item,
 							      &mapping_idx);
-- 
1.6.4.314.g5667f
Message 1 of 1 in “graph API: use a new color when starting a brand new column”
  1. graph API: use a new color when starting a brand new columnAdam Simpkins, Aug 18, 2009

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.