@@ -82,8 +82,6 @@ static void graph_show_line_prefix(const struct diff_options *diffopt)
8282static const char * * column_colors ;
8383static unsigned short column_colors_max ;
8484
85- static unsigned int max_lanes = 15 ;
86-
8785static void parse_graph_colors_config (struct strvec * colors , const char * string )
8886{
8987 const char * end , * start ;
@@ -319,9 +317,13 @@ struct git_graph {
319317 struct strbuf prefix_buf ;
320318};
321319
322- static inline int graph_needs_truncation (int lane )
320+ static inline int graph_needs_truncation (struct git_graph * graph , int lane )
323321{
324- return lane >= max_lanes ;
322+ int max = graph -> revs -> graph_max_lanes ;
323+ /*
324+ * Ignore values <= 0, meaning no limit.
325+ */
326+ return max > 0 && lane >= max ;
325327}
326328
327329static const char * diff_output_prefix_callback (struct diff_options * opt , void * data )
@@ -614,7 +616,7 @@ static void graph_update_columns(struct git_graph *graph)
614616{
615617 struct commit_list * parent ;
616618 int max_new_columns ;
617- int i , seen_this , is_commit_in_columns , max ;
619+ int i , seen_this , is_commit_in_columns ;
618620
619621 /*
620622 * Swap graph->columns with graph->new_columns
@@ -704,12 +706,17 @@ static void graph_update_columns(struct git_graph *graph)
704706 }
705707
706708 /*
707- * Cap to the hard-coded limit.
708- * Allow commits from merges to align to the merged lane.
709+ * If graph_max_lanes is set, cap the width
709710 */
710- max = max_lanes * 2 + 2 ;
711- if (graph -> width > max )
712- graph -> width = max ;
711+ if (graph -> revs -> graph_max_lanes > 0 ) {
712+ /*
713+ * Width is column index while a lane is half that.
714+ * Allow commits from merges to align to the merged lane.
715+ */
716+ int max_width = graph -> revs -> graph_max_lanes * 2 + 2 ;
717+ if (graph -> width > max_width )
718+ graph -> width = max_width ;
719+ }
713720
714721 /*
715722 * Shrink mapping_size to be the minimum necessary
@@ -861,7 +868,7 @@ static void graph_output_padding_line(struct git_graph *graph,
861868 * Output a padding row, that leaves all branch lines unchanged
862869 */
863870 for (i = 0 ; i < graph -> num_new_columns ; i ++ ) {
864- if (graph_needs_truncation (i ))
871+ if (graph_needs_truncation (graph , i ))
865872 break ;
866873 graph_line_write_column (line , & graph -> new_columns [i ], '|' );
867874 graph_line_addch (line , ' ' );
@@ -920,7 +927,7 @@ static void graph_output_pre_commit_line(struct git_graph *graph,
920927 seen_this = 1 ;
921928 graph_line_write_column (line , col , '|' );
922929 graph_line_addchars (line , ' ' , graph -> expansion_row );
923- } else if (seen_this && graph_needs_truncation (i )) {
930+ } else if (seen_this && graph_needs_truncation (graph , i )) {
924931 break ;
925932 } else if (seen_this && (graph -> expansion_row == 0 )) {
926933 /*
@@ -1018,7 +1025,7 @@ static void graph_draw_octopus_merge(struct git_graph *graph, struct graph_line
10181025 * Commit is at commit_index, each iteration move one lane to
10191026 * the right from the commit.
10201027 */
1021- if (graph_needs_truncation (graph -> commit_index + 1 + i ))
1028+ if (graph_needs_truncation (graph , graph -> commit_index + 1 + i ))
10221029 break ;
10231030
10241031 graph_line_write_column (line , col , (i == dashed_parents - 1 ) ? '.' : '-' );
@@ -1055,14 +1062,14 @@ static void graph_output_commit_line(struct git_graph *graph, struct graph_line
10551062 seen_this = 1 ;
10561063 graph_output_commit_char (graph , line );
10571064
1058- if (graph_needs_truncation (i )) {
1065+ if (graph_needs_truncation (graph , i )) {
10591066 graph_line_addch (line , ' ' );
10601067 break ;
10611068 }
10621069
10631070 if (graph -> num_parents > 2 )
10641071 graph_draw_octopus_merge (graph , line );
1065- } else if (graph_needs_truncation (i )) {
1072+ } else if (graph_needs_truncation (graph , i )) {
10661073 seen_this = 1 ;
10671074 break ;
10681075 } else if (seen_this && (graph -> edges_added > 1 )) {
@@ -1112,7 +1119,7 @@ static void graph_output_commit_line(struct git_graph *graph, struct graph_line
11121119 * padding lane.
11131120 */
11141121 if (graph -> num_parents > 1 ) {
1115- if (!graph_needs_truncation (graph -> commit_index )) {
1122+ if (!graph_needs_truncation (graph , graph -> commit_index )) {
11161123 graph_update_state (graph , GRAPH_POST_MERGE );
11171124 } else {
11181125 struct commit_list * p = first_interesting_parent (graph );
@@ -1128,7 +1135,7 @@ static void graph_output_commit_line(struct git_graph *graph, struct graph_line
11281135
11291136 lane = graph_find_new_column_by_commit (graph , p -> item );
11301137
1131- if (!graph_needs_truncation (lane ))
1138+ if (!graph_needs_truncation (graph , lane ))
11321139 graph_update_state (graph , GRAPH_POST_MERGE );
11331140 else if (graph_is_mapping_correct (graph ))
11341141 graph_update_state (graph , GRAPH_PADDING );
@@ -1192,7 +1199,7 @@ static void graph_output_post_merge_line(struct git_graph *graph, struct graph_l
11921199 * comparable with i. Don't truncate if there are
11931200 * no more lanes to print (end of the lane)
11941201 */
1195- if (graph_needs_truncation (j / 2 + i ) &&
1202+ if (graph_needs_truncation (graph , j / 2 + i ) &&
11961203 j / 2 + i <= graph -> num_columns ) {
11971204 if ((j + i * 2 ) % 2 != 0 )
11981205 graph_line_addch (line , ' ' );
@@ -1205,7 +1212,7 @@ static void graph_output_post_merge_line(struct git_graph *graph, struct graph_l
12051212 * Check if the next lane needs truncation
12061213 * to avoid having the padding doubled
12071214 */
1208- if (graph_needs_truncation ((j + 1 ) / 2 + i ) &&
1215+ if (graph_needs_truncation (graph , (j + 1 ) / 2 + i ) &&
12091216 j < graph -> num_parents - 1 ) {
12101217 truncated = 1 ;
12111218 break ;
@@ -1220,7 +1227,7 @@ static void graph_output_post_merge_line(struct git_graph *graph, struct graph_l
12201227 break ;
12211228 if (graph -> edges_added == 0 )
12221229 graph_line_addch (line , ' ' );
1223- } else if (graph_needs_truncation (i )) {
1230+ } else if (graph_needs_truncation (graph , i )) {
12241231 break ;
12251232 } else if (seen_this ) {
12261233 if (graph -> edges_added > 0 )
@@ -1231,7 +1238,7 @@ static void graph_output_post_merge_line(struct git_graph *graph, struct graph_l
12311238 * If it's between two lanes and next would be truncated,
12321239 * don't add space padding.
12331240 */
1234- if (!graph_needs_truncation (i + 1 ))
1241+ if (!graph_needs_truncation (graph , i + 1 ))
12351242 graph_line_addch (line , ' ' );
12361243 } else {
12371244 graph_line_write_column (line , col , '|' );
@@ -1380,7 +1387,7 @@ static void graph_output_collapsing_line(struct git_graph *graph, struct graph_l
13801387 for (i = 0 ; i < graph -> mapping_size ; i ++ ) {
13811388 int target = graph -> mapping [i ];
13821389
1383- if (!truncated && graph_needs_truncation (i / 2 )) {
1390+ if (!truncated && graph_needs_truncation (graph , i / 2 )) {
13841391 truncated = 1 ;
13851392 }
13861393
@@ -1480,7 +1487,7 @@ static void graph_padding_line(struct git_graph *graph, struct strbuf *sb)
14801487 for (i = 0 ; i < graph -> num_columns ; i ++ ) {
14811488 struct column * col = & graph -> columns [i ];
14821489
1483- if (graph_needs_truncation (i ))
1490+ if (graph_needs_truncation (graph , i ))
14841491 break ;
14851492
14861493 graph_line_write_column (& line , col , '|' );
0 commit comments