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

From: Junio C Hamano <[email-masked]>
Date: Wed, 18 Mar 2026 09:05:17 -0700

Pablo Sabater <[email-masked]> writes:

> Repositories that have many active branches produce very wide
> outputs with 'git log --graph --all', makes it difficult to read.

"making it difficult"?

> Add '--max-columns=<n>' to limit the columns shown. Columns over
> the limit are replaced with a '.' truncation indicator. This only
> affects the visual rendering.

Being an option to "git log", I expect that readers would naturally
take "--max-columns=<n>" to refer to the total display width
consumed by the entire output including the log messages and
possibly patches when the command is run with the "-p" option,
whether the ancestry graph is shown or not.

But somehow I suspect that it is not what is going on here.

If this <n> refers to the width of graph part only, the option name
should hint that fact somehow.  Perhaps include the word "graph" in
it, or something.  As you use the verb "limit" below, perhaps
"--limit-graph-columns=<n>"?

> The commit mark '*' is only shown in two cases:
> - The commit is in a branch inside the limit.
> - The commit is in the first hidden branch, in this case '.'
>   is replaced by '*'.

> Commits on deeper hidden branches do not show '*' but the commit
> subject is still shown, so no information is lost.

Isn't "no information is lost" a huge exaggeration?  We are losing
the ancestry information by not drawing graph lines, aren't we?

> The original idea to limit columns was noted as a TODO in
> c12172d2ea (Add history graph API, 2008-05-04), which mentions
> gitk's behavior. This does not implement gitk-style column
> rearrangement; it only truncates the visual output.

True.  

IIRC, Gitk also allows you to click the chopped arrow-head to jump
to the other end of the omitted ancestry line, which is very useful
but is hard to do on a terminal output that is not interactive.

> git log --graph --all --oneline --max-columns=2
> *   b81d099 (M_1) 7_M1
> |\
> | | * 2d96ba0 (M_3) 7_M2
> | | .

I would call this output consuming 5 columns for graph part, not 2.
For end users, being able to specify 2, i.e., being able to say "I
tolerate wasting display columns to show up to two ancestry lines"
(or "two lanes of ancestry information"), is indeed a lot more
intuitive than having to say "You are allowed to use up to 5 display
columns", so I do not object to an option that takes "2" as its
value and produces the above output, but I am not sure if we want to
have "columns" in the name of such an option; "--limit-graph-lanes=2"?

> - I think --max-columns is a good name, but it does not have --graph
>   prefix, bcs it can only be on --graph I think it's clear enough.

If "git log --max-columns=77" ignores the option because "--graph"
is not given, it would be confusing to the users.

> +	/*
> +	 * If graph_max_columns is set, cap the padding from the branches
> +	 */
> +	if (graph->revs->graph_max_columns > 0) {
> +		int truncation = graph->revs->graph_max_columns * 2 + 2;

This needs a bit more commenting to explain where these magic
numbers come from; they are of the same value 2 but have different
meanings, right?  Like this (only to illustrate the shape, not
suggesting what the contents should read):

		/*
		 * Each ancestry "lane" occupies 2 columns, and
		 * we leave two columns before drawing the commit
		 * title and log message part.
		 */
		int max_column_width = 
			graph->revs->graph_limit_lanes * 2 + 2;

> +
> +	if (revs->graph_max_columns > 0 && !revs->graph)
> +		die(_("option '%s' requires '%s'"), "--max-columns", "--graph");

The naming is so selfish.  Among "git log" options that exists and
that will be added in the future, this design decision declares that
"--graph" is and will remain to be the only one that may want to
specify the maximum number of columns to spend.

If the option is named clearly to be related to the "--graph"
feature, another way to go is to make it imply "--graph".  If the
user says "I want to limit the graph output to consume no more than
10 leftmost columns", it is clear that the user expects the graph to
be shown.