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

Re: [GSoC RFC PATCH] graph: add --graph-max option to limit displayed columns

From
Karthik Nayak <karthik.188@gmail.com>
Date
Mar 16, 2026, 17:04 UTC
Message-ID
<CAOLa=ZSsC7zpfpRx8pShcqGEv_2_NMrKzJHCgTSaO=0Dg0xakg@mail.gmail.com>
In-Reply-To
<20260316133426.117684-1-pabloosabaterr@gmail.com>
Pablo Sabater <pabloosabaterr@gmail.com> writes:
Show 7 quoted lines
> When there are multiple branches, --graph-max modifies the maximum
> amount of columns that will be displayed.
>
> Add "--graph-max=<n>" option to cap how many columns will be shown,
> columns after the limit are replaced with a single '.'. Changes only
> the output rendering.
>

The first sentence seems to talk about the option like it already exists, when the second para introduces it. It would be nice if the first para explained the problem we're trying to solve and why and the second para then dove into the solution space.

Do you think '--graph-max' signifies that we're talking about the maximum columns to display?

> Define MINIMUM_GRAPH_COLUMNS constant to validate the option value.
What does this mean? Validate how?
> The commit character '*' is always shown no matter what the limit is.

I think overall a little more explanation in the commit message makes it easier to understand the context and also helps reviewers!

Shouldn't we also talk about the todo and the commit (c12172d2ea (Add history graph API, 2008-05-04)) in which it was added?

Show 11 quoted lines
>
> Signed-off-by: Pablo Sabater <pabloosabaterr@gmail.com>
> ---
>
> This addresses the TODO at graph.c:
>
>   TODO:
>       - Limit the number of columns, similar to the way gitk does.
>         If we reach more than a specified number of columns, omit
>         sections of some columns.
>

One question to ask is, is this even needed anymore and does it really make sense to add it?

The TODO was added back in 2008, that's ~16 years ago and was not touched till now. So perhaps no one needs it? If so, maybe the smarter option is to simply remove the TODO?

Or do you see a usecase where this is useful? If so, it would be nice to talk about that in the commit message.

> About the design of how this would have to be:
>
> - Should '--graph-max' by itself be enough to implicitly work like '--graph' so
>   'git log --graph-max=3' works without needing to write '--graph'?

My preference would be not to have implicit behavior but also at the same time guide the user in the right path, so:

     $ git log --graph-max=4
     fatal: --graph-max used without --graph
Show 5 quoted lines
> - graph_max_columns by default is set to 0, meaning no limit, and any other
>   positive value becomes a limit. Is this a good design? it cannot be negative,
>   shouldn't it be a uint32_t instead, I left it as a int because of the other
>   variables like this that are int. like skip_count, max_count, etc.
> - Is '--graph-max' a good name?
I would argue against it. Perhaps '--graph-col-limit'? It's a bit handy though.
> - Is '.' a good char for truncation?
Trying it out:
$ git log --graph --oneline --graph-max=3
| * ba1c21d343 odb: split `struct odb_source` into separate header
| *   b1af291b4a Merge branch 'ps/object-info-bits-cleanup' into ps/odb-sources
| |\
| * \   703c97519d Merge branch 'ps/odb-for-each-object' into ps/odb-sources
| |\ \
* | \ .   d0413b31dd Merge branch 'hn/status-compare-with-push'
|\ \ \ .
| * | .   68791d7506 status: clarify how status.compareBranches deduplicates
| * | .   3ea95ac9c5 (gitster/hn/status-compare-with-push) status: add
status.compareBranches config for multiple branch comparisons
| * | .   04f47265c1 refactor format_branch_comparison in preparation
| * | .     2aa9b75b43 Merge branch 'jk/remote-tracking-ref-leakfix'
into hn/status-compare-with-push
| |\ \ .
* | \ .       03161747b4 Merge branch 'ds/for-each-repo-w-worktree'
|\ \ \ .
| * | .       e87493b9b4 for-each-repo: simplify passing of parameters
| * | .       2ef539bcee for-each-repo: work correctly in a worktree
| * | .       5f031fe4f1 run-command: extract sanitize_repo_env helper
| * | .       c5e62e1aa0 for-each-repo: test outside of repo context
* | | .       67006b9db8 The 15th batch
* | | .         99da934835 Merge branch 'sp/send-email-validate-charset'
|\ \ \ .
| * | .         c52f085a47 (gitster/sp/send-email-validate-charset)
send-email: validate charset name in 8bit encoding prompt
vs
$ git log --graph --oneline
| * ba1c21d343 odb: split `struct odb_source` into separate header
| *   b1af291b4a Merge branch 'ps/object-info-bits-cleanup' into ps/odb-sources
| |\
| * \   703c97519d Merge branch 'ps/odb-for-each-object' into ps/odb-sources
| |\ \
* | \ \   d0413b31dd Merge branch 'hn/status-compare-with-push'
|\ \ \ \
| * | | | 68791d7506 status: clarify how status.compareBranches deduplicates
| * | | | 3ea95ac9c5 (gitster/hn/status-compare-with-push) status: add
status.compareBranches config for multiple branch comparisons
| * | | | 04f47265c1 refactor format_branch_comparison in preparation
| * | | |   2aa9b75b43 Merge branch 'jk/remote-tracking-ref-leakfix'
into hn/status-compare-with-push
| |\ \ \ \
* | \ \ \ \   03161747b4 Merge branch 'ds/for-each-repo-w-worktree'
|\ \ \ \ \ \
| * | | | | | e87493b9b4 for-each-repo: simplify passing of parameters
| * | | | | | 2ef539bcee for-each-repo: work correctly in a worktree
| * | | | | | 5f031fe4f1 run-command: extract sanitize_repo_env helper
| * | | | | | c5e62e1aa0 for-each-repo: test outside of repo context
* | | | | | | 67006b9db8 The 15th batch
* | | | | | |   99da934835 Merge branch 'sp/send-email-validate-charset'
|\ \ \ \ \ \ \
| * | | | | | | c52f085a47 (gitster/sp/send-email-validate-charset)
send-email: validate charset name in 8bit encoding prompt
So we still keep the spaces, but only remove the column indicator
Show 41 quoted lines
> - Should '/' to outside branches be shown?
> - What should it be done when a commit is in a column that is truncated?
>
> known limitations:
>
> - Post merge lines have some trouble with the padding.
>
> I added two tests for example, but I will add better test coverage as design
> choices are more clear. testing on the Git repo itself is a good example also.
>
>  graph.c                      | 52 +++++++++++++++++++++++++++------
>  graph.h                      |  2 ++
>  revision.c                   |  7 +++++
>  revision.h                   |  1 +
>  t/t4215-log-skewed-merges.sh | 56 ++++++++++++++++++++++++++++++++++++
>  5 files changed, 109 insertions(+), 9 deletions(-)
>
> diff --git a/graph.c b/graph.c
> index 26f6fbf000..7ae0ab61b7 100644
> --- a/graph.c
> +++ b/graph.c
> @@ -42,14 +42,6 @@ static void graph_padding_line(struct git_graph *graph, struct strbuf *sb);
>  static void graph_show_strbuf(struct git_graph *graph,
>  			      FILE *file,
>  			      struct strbuf const *sb);
> -
> -/*
> - * TODO:
> - * - Limit the number of columns, similar to the way gitk does.
> - *   If we reach more than a specified number of columns, omit
> - *   sections of some columns.
> - */
> -
>  struct column {
>  	/*
>  	 * The parent commit of this column.
> @@ -317,6 +309,12 @@ struct git_graph {
>  	struct strbuf prefix_buf;
>  };
>
> +static int graph_is_truncated(struct git_graph *graph, int col)
Isn't this more of `graphs_needs_truncation()`?
Show 135 quoted lines
> +{
> +	int max = graph->revs->graph_max_columns;
> +	return max > 0 && col >= max;
> +}
> +
>  static const char *diff_output_prefix_callback(struct diff_options *opt, void *data)
>  {
>  	struct git_graph *graph = data;
> @@ -846,6 +844,10 @@ static void graph_output_padding_line(struct git_graph *graph,
>  	 * Output a padding row, that leaves all branch lines unchanged
>  	 */
>  	for (i = 0; i < graph->num_new_columns; i++) {
> +		if (graph_is_truncated(graph, i)) {
> +			graph_line_addstr(line, ". ");
> +			break;
> +		}
>  		graph_line_write_column(line, &graph->new_columns[i], '|');
>  		graph_line_addch(line, ' ');
>  	}
> @@ -903,6 +905,9 @@ static void graph_output_pre_commit_line(struct git_graph *graph,
>  			seen_this = 1;
>  			graph_line_write_column(line, col, '|');
>  			graph_line_addchars(line, ' ', graph->expansion_row);
> +		} else if (seen_this && graph_is_truncated(graph, i)) {
> +			graph_line_addstr(line, ". ");
> +			break;
>  		} else if (seen_this && (graph->expansion_row == 0)) {
>  			/*
>  			 * This is the first line of the pre-commit output.
> @@ -1013,6 +1018,7 @@ static void graph_output_commit_line(struct git_graph *graph, struct graph_line
>  	 * children that we have already processed.)
>  	 */
>  	seen_this = 0;
> +
>  	for (i = 0; i <= graph->num_columns; i++) {
>  		struct column *col = &graph->columns[i];
>  		struct commit *col_commit;
> @@ -1028,8 +1034,14 @@ static void graph_output_commit_line(struct git_graph *graph, struct graph_line
>  			seen_this = 1;
>  			graph_output_commit_char(graph, line);
>
> +			if (graph_is_truncated(graph, i))
> +				break;
> +
>  			if (graph->num_parents > 2)
>  				graph_draw_octopus_merge(graph, line);
> +		} else if (seen_this && graph_is_truncated(graph, i)) {
> +			graph_line_addstr(line, ". ");
> +			break;
>  		} else if (seen_this && (graph->edges_added > 1)) {
>  			graph_line_write_column(line, col, '\\');
>  		} else if (seen_this && (graph->edges_added == 1)) {
> @@ -1109,9 +1121,15 @@ static void graph_output_post_merge_line(struct git_graph *graph, struct graph_l
>  			int par_column;
>  			int idx = graph->merge_layout;
>  			char c;
> +			int truncated = 0;
>  			seen_this = 1;
>
>  			for (j = 0; j < graph->num_parents; j++) {
> +				if (graph_is_truncated(graph, i + j)) {
> +					graph_line_addstr(line, ". ");
> +					truncated = 1;
> +					break;
> +				}
>  				par_column = graph_find_new_column_by_commit(graph, parents->item);
>  				assert(par_column >= 0);
>
> @@ -1125,10 +1143,15 @@ static void graph_output_post_merge_line(struct git_graph *graph, struct graph_l
>  				}
>  				parents = next_interesting_parent(graph, parents);
>  			}
> +			if (truncated)
> +				break;
>  			if (graph->edges_added == 0)
>  				graph_line_addch(line, ' ');
> -
>  		} else if (seen_this) {
> +			if (graph_is_truncated(graph, i)) {
> +				graph_line_addstr(line, ". ");
> +				break;
> +			}
>  			if (graph->edges_added > 0)
>  				graph_line_write_column(line, col, '\\');
>  			else
> @@ -1279,6 +1302,12 @@ static void graph_output_collapsing_line(struct git_graph *graph, struct graph_l
>  	 */
>  	for (i = 0; i < graph->mapping_size; i++) {
>  		int target = graph->mapping[i];
> +
> +		if (graph_is_truncated(graph, i / 2)) {
> +			graph_line_addstr(line, ". ");
> +			break;
> +		}
> +
>  		if (target < 0)
>  			graph_line_addch(line, ' ');
>  		else if (target * 2 == i)
> @@ -1372,6 +1401,11 @@ static void graph_padding_line(struct git_graph *graph, struct strbuf *sb)
>  	for (i = 0; i < graph->num_columns; i++) {
>  		struct column *col = &graph->columns[i];
>
> +		if (graph_is_truncated(graph, i)) {
> +			graph_line_addch(&line, '.');
> +			break;
> +		}
> +
>  		graph_line_write_column(&line, col, '|');
>
>  		if (col->commit == graph->commit && graph->num_parents > 2) {
> diff --git a/graph.h b/graph.h
> index 3fd1dcb2e9..9a4551dd29 100644
> --- a/graph.h
> +++ b/graph.h
> @@ -262,4 +262,6 @@ void graph_show_commit_msg(struct git_graph *graph,
>  			   FILE *file,
>  			   struct strbuf const *sb);
>
> +#define MINIMUM_GRAPH_COLUMNS 1
> +
>  #endif /* GRAPH_H */
> diff --git a/revision.c b/revision.c
> index 31808e3df0..ba5088be14 100644
> --- a/revision.c
> +++ b/revision.c
> @@ -2605,6 +2605,13 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
>  	} else if (!strcmp(arg, "--no-graph")) {
>  		graph_clear(revs->graph);
>  		revs->graph = NULL;
> +	} else if (skip_prefix(arg, "--graph-max=", &optarg)) {
> +		revs->graph_max_columns = strtoul(optarg, NULL, 10);
> +		if (revs->graph_max_columns < MINIMUM_GRAPH_COLUMNS) {
> +			die(_("minimum columns is %d, unable to set below %d"),
> +			MINIMUM_GRAPH_COLUMNS,
> +			revs->graph_max_columns);
Shouldn't we allow users to set 0? That combined with an unsigned int
would:
1. remove the need for MINIMUM_GRAPH_COLUMNS
2. allow users to specify that they do not want a column limit
Show 14 quoted lines
> +		}
>  	} else if (!strcmp(arg, "--encode-email-headers")) {
>  		revs->encode_email_headers = 1;
>  	} else if (!strcmp(arg, "--no-encode-email-headers")) {
> diff --git a/revision.h b/revision.h
> index 69242ecb18..6442129c14 100644
> --- a/revision.h
> +++ b/revision.h
> @@ -304,6 +304,7 @@ struct rev_info {
>
>  	/* Display history graph */
>  	struct git_graph *graph;
> +	int graph_max_columns;
>
I think it makes sense to make this an unsigned int.
Show 69 quoted lines
>  	/* special limits */
>  	int skip_count;
> diff --git a/t/t4215-log-skewed-merges.sh b/t/t4215-log-skewed-merges.sh
> index 28d0779a8c..6266de4e2b 100755
> --- a/t/t4215-log-skewed-merges.sh
> +++ b/t/t4215-log-skewed-merges.sh
> @@ -370,4 +370,60 @@ test_expect_success 'log --graph with multiple tips' '
>  	EOF
>  '
>
> +test_expect_success 'log --graph --graph-max=2 only two columns' '
> +	check_graph --graph-max=2 M_7 <<-\EOF
> +	*-.   7_M4
> +	|\ .
> +	| | * 7_G
> +	| | * 7_F
> +	| * . 7_E
> +	| * . 7_D
> +	* | . 7_C
> +	| |/
> +	|/|
> +	* | 7_B
> +	|/
> +	* 7_A
> +	EOF
> +'
> +
> +test_expect_success 'log --graph --graph-max=3 only three columns' '
> +	check_graph --graph-max=3 M_1 M_3 M_5 M_7 <<-\EOF
> +	*   7_M1
> +	|\
> +	| | *   7_M2
> +	| | |.
> +	| | | * 7_H
> +	| | | | *   7_M3
> +	| | | | .
> +	| | | | | * 7_J
> +	| | | | *   7_I
> +	| | | | | | *   7_M4
> +	| |_|_|_|_|.
> +	|/| | .
> +	| | |_.
> +	| |/|_.
> +	| |/|_.
> +	| |/| .
> +	| | |/.
> +	| | * .     7_G
> +	| | | .
> +	| | |/.
> +	| | |/.
> +	| | * .   7_F
> +	| * | .   7_E
> +	| | |/.
> +	| |/| .
> +	| * | . 7_D
> +	| | |/
> +	| |/|
> +	* | | 7_C
> +	| |/
> +	|/|
> +	* | 7_B
> +	|/
> +	* 7_A
> +	EOF
> +'
> +
>  test_done
> --
> 2.43.0
v
Previous: Pablo SabaterNext: Pablo
Message 2 of 48 in “graph: add --graph-max option to limit displayed columns”
  1. graph: add --graph-max option to limit displayed columnsPablo Sabater, Mar 16, 2026
  2. Karthik NayakMar 16, 2026
  3. PabloMar 16, 2026
  4. graph: add --max-columns option to limit displayed columnsPablo Sabater, Mar 17, 2026
  5. Junio C HamanoMar 18, 2026
  6. PabloMar 18, 2026
  7. Johannes SixtMar 19, 2026
  8. 0/3 graph: add --graph-lane-limit optionPablo Sabater, Mar 22, 2026
  9. 1/3 graph: add --graph-lane-limit optionPablo Sabater, Mar 22, 2026
  10. 2/3 graph: truncate graph visual outputPablo Sabater, Mar 22, 2026
  11. 3/3 graph: add documentation and testing about --graph-lane-limitPablo Sabater, Mar 22, 2026
  12. Junio C HamanoMar 22, 2026
  13. PabloMar 23, 2026
  14. 0/3 graph: add --graph-lane-limit optionPablo Sabater, Mar 23, 2026
  15. 1/3 graph: add --graph-lane-limit optionPablo Sabater, Mar 23, 2026
  16. SZEDER GáborMar 25, 2026
  17. Johannes SixtMar 25, 2026
  18. PabloMar 25, 2026
  19. 2/3 graph: truncate graph visual outputPablo Sabater, Mar 23, 2026
  20. Johannes SixtMar 25, 2026
  21. PabloMar 25, 2026
  22. 3/3 graph: add documentation and tests about --graph-lane-limitPablo Sabater, Mar 23, 2026
  23. Johannes SixtMar 25, 2026
  24. PabloMar 25, 2026
  25. Johannes SixtMar 25, 2026
  26. PabloMar 25, 2026
  27. Johannes SixtMar 25, 2026
  28. PabloMar 25, 2026
  29. 0/2 graph: add --graph-lane-limit optionPablo Sabater, Mar 25, 2026
  30. 1/2 graph: add --graph-lane-limit optionPablo Sabater, Mar 25, 2026
  31. Junio C HamanoMar 25, 2026
  32. PabloMar 27, 2026
  33. PabloMar 27, 2026
  34. Junio C HamanoMar 27, 2026
  35. 2/2 graph: add documentation and tests about --graph-lane-limitPablo Sabater, Mar 25, 2026
  36. 0/3 graph: add --graph-lane-limit optionPablo Sabater, Mar 28, 2026
  37. 1/3 graph: limit the graph width to a hard-coded maxPablo Sabater, Mar 28, 2026
  38. 2/3 graph: add --graph-lane-limit optionPablo Sabater, Mar 28, 2026
  39. 3/3 graph: add truncation mark to capped lanesPablo Sabater, Mar 28, 2026
  40. Junio C HamanoMar 31, 2026
  41. Johannes SixtApr 1, 2026
  42. PabloApr 1, 2026
  43. Junio C HamanoApr 1, 2026
  44. PabloApr 2, 2026
  45. Junio C HamanoApr 2, 2026
  46. Tian YuchenApr 3, 2026
  47. PabloApr 3, 2026
  48. Junio C HamanoApr 3, 2026

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.