From 726649a09a951398c23d7e3ffc38ae6368adacca Mon Sep 17 00:00:00 2001 From: Peer Sommerlund Date: Thu, 9 Jul 2026 05:54:25 +0200 Subject: [PATCH 1/4] Check for topology order --- CHANGELOG.md | 4 ++++ src/print/unicode.rs | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3597c51..c2bf794 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [unreleased] +### Added + +- panic if commits are not in topology order. + ## [0.7.4] - 2026-07-08 diff --git a/src/print/unicode.rs b/src/print/unicode.rs index efd4d65..9bb856c 100644 --- a/src/print/unicode.rs +++ b/src/print/unicode.rs @@ -383,6 +383,14 @@ fn draw_parent_lines( continue; }; + // If parent is above commit the user did not sort commits by toppology + if *par_idx < layout.commit_index_start() { + log::error!("Commit {:?} parent[{}] {:?} was walked before its child. Gleisbau require topology order on commits.", + tracks.commits[idx].oid, p, par_oid, + ); + panic!("Commit not in toplogy order"); + } + // index_map is from relative commit index to row let Some(&par_idx_map) = index_map.get(*par_idx - layout.commit_index_start()) else { // Parent was outside layout From 5b57b11d68ace71247a9a51c0eddf81b146d26bc Mon Sep 17 00:00:00 2001 From: Peer Sommerlund Date: Sun, 2 Aug 2026 22:42:57 +0200 Subject: [PATCH 2/4] Fix grid height computation in legacy api --- CHANGELOG.md | 4 ++++ src/print/unicode.rs | 32 ++++++++++++++++++++++++-------- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c2bf794..1d9e085 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - panic if commits are not in topology order. +### Fixed + +- panic when wrapping text caused an increase of output rows. + ## [0.7.4] - 2026-07-08 diff --git a/src/print/unicode.rs b/src/print/unicode.rs index 9bb856c..dbb805d 100644 --- a/src/print/unicode.rs +++ b/src/print/unicode.rs @@ -110,11 +110,7 @@ pub fn print_unicode(graph: &GitGraph, settings: &Settings) -> Result usize { 2 * max_column + 1 } -/// Iterates through commits to compute text lines, blank line inserts, and the index map. +/** Compute text lines for commits in layout, and a map from commit to text line. + +If the graph needs more rows for a commit than the text does, insert None as +lines to fill the remaining rows for that commit. +If the text needs more rows than the graph for a commit, simply add more lines +and increase offset to next entry in index_map. +*/ fn build_commit_lines_and_map( settings: &Settings, repository: &Repository, @@ -153,8 +155,8 @@ fn build_commit_lines_and_map( inserts: &HashMap, ) -> Result< ( - Vec>, - Vec, // index_map: from (commit index relative to layout) to grid row + Vec>, // text_lines + Vec, // index_map: from (commit index relative to layout) to grid row ), String, > { @@ -323,6 +325,16 @@ fn draw_graph_lines( .expect("All commits in range has precomputed visuals"); let column = branch_visual.column.unwrap(); let idx_map = index_map[idx - layout.commit_index_start()]; + if idx_map >= grid.height { + // Item outside range of grid, exit loop + log::error!( + "Layout commit +{} at row {} is outside Grid range [0,{}]", + idx - layout.commit_index_start(), + idx_map, + grid.height - 1, + ); + panic!("commit point outside grid"); + } // Draw commit point (DOT or CIRCLE) grid.set( @@ -534,6 +546,10 @@ fn get_inserts( // layout is too far down, so it includes index that are not // in TrackMap. Provide an empty render plan for that row. inserts.insert(idx, vec![vec![]]); + log::debug!( + "commit index {:?} was missing from tracks.commits -> zero height insert", + idx, + ); continue; }; // Get the visual column assigned to the branch of this commit. Unwrap is safe here From fe04f15cbc16ec327f4bf030731e6be219408c5b Mon Sep 17 00:00:00 2001 From: Peer Sommerlund Date: Wed, 5 Aug 2026 22:46:23 +0200 Subject: [PATCH 3/4] Clippy cleanup --- src/layout.rs | 2 +- src/print/format.rs | 2 +- src/track.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/layout.rs b/src/layout.rs index 802e2d9..e4458ff 100644 --- a/src/layout.rs +++ b/src/layout.rs @@ -165,7 +165,7 @@ pub fn layout_track_range( range: Range, settings: &Settings, ) -> Result { - log::trace!("layout_track_range(_,({},{}),_)", &range.start, &range.end); + log::trace!("layout_track_range(_,({},{}),_)", range.start, range.end); let mut branch_visuals = Vec::new(); let mut track_visual_map = HashMap::new(); diff --git a/src/print/format.rs b/src/print/format.rs index 69262ad..d7e0dae 100644 --- a/src/print/format.rs +++ b/src/print/format.rs @@ -418,7 +418,7 @@ pub fn format_commit_metadata( if let Some(color) = hash_color { write!(out, "commit {}", id.to_string().fixed(color)) } else { - write!(out, "commit {}", &id) + write!(out, "commit {}", id) } .map_err(|err| err.to_string())?; diff --git a/src/track.rs b/src/track.rs index 577b2a1..5bf4a96 100644 --- a/src/track.rs +++ b/src/track.rs @@ -428,7 +428,7 @@ impl Builder { log::error!( "Commit #{} {:?} has parent[{}] which points back at commit #{} {:?}", commit_index, - &id, + id, p, parent_index, parent_oid, From 3cef24f8c40e9ba4da77a085cf91a95e213f1560 Mon Sep 17 00:00:00 2001 From: Peer Sommerlund Date: Thu, 6 Aug 2026 05:51:26 +0200 Subject: [PATCH 4/4] Improve print::unicode docs - Fix row-column mixup. - Mention extra lines due to text wrapping. - More clear comparison of coordinate systems. --- CHANGELOG.md | 1 + src/print/unicode.rs | 15 ++++++++------- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d9e085..5ce87e7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - panic when wrapping text caused an increase of output rows. +- print::unicode docs swapped row and column. ## [0.7.4] - 2026-07-08 diff --git a/src/print/unicode.rs b/src/print/unicode.rs index dbb805d..a7206f6 100644 --- a/src/print/unicode.rs +++ b/src/print/unicode.rs @@ -1,10 +1,11 @@ /*! Create graphs in Unicode format with ANSI X3.64 / ISO 6429 colour codes Terminals usuallly have very tall characters, so to get a square ratio -we need to double the number of rows. Although unicode allows drawing +we need to double the number of columns. Although unicode allows drawing of lines, it does not support parallel lines inside the same symbol. To fix this we add extra "inserts", extra lines per commit as needed -to draw lines without unwanted overlap. +to draw lines without unwanted overlap. Extra lines can also be added if +needed due to wrapping of long commit messages. The main functions are: - [print_unicode] - Legacy API. Prints both graph and commit text from a [GitGraph] @@ -12,11 +13,11 @@ The main functions are: ## Coordinate system -The final output is rendered onto a private 2D struct 'Grid' before printing. -This is in the final coordinate system including extra columns and rows. -[TrackLayout] uses the abstract coordinate system of commit row and -track column, so you need to keep track of which coordinate system a -function uses. +Note that there are two different coordinate systems used: +- Abstract: One row per commit, one column per track. Used by [TrackLayout] +- Terminal: Many rows per commit due to inserts or wrapping, two columns per + track. Used internally for the final print to a terminal. + */ use std::cmp::max;