@@ -19,7 +19,6 @@ use crate::track::TrackMap;
1919
2020const ORIGIN : & str = "origin/" ;
2121
22-
2322/**
2423 Given a range of commits in a [TrackMap] you can construct a [TrackLayout]
2524 which will assign columns and colours to the tracks.
@@ -35,8 +34,9 @@ pub struct TrackLayout {
3534
3635impl TrackLayout {
3736 pub fn track_visual ( & self , track_inx : usize ) -> Option < & BranchVis > {
38- self . track_visual . get ( & track_inx)
39- . and_then ( |& bv_idx| self . branch_visual . get ( bv_idx) )
37+ self . track_visual
38+ . get ( & track_inx)
39+ . and_then ( |& bv_idx| self . branch_visual . get ( bv_idx) )
4040 }
4141 pub fn track_visual_vec ( & self ) -> & Vec < BranchVis > {
4242 & self . branch_visual
@@ -71,7 +71,7 @@ impl BranchVis {
7171 }
7272 }
7373}
74- /// Generates a TrackLayout by extracting and calculating visual data for
74+ /// Generates a TrackLayout by extracting and calculating visual data for
7575/// branches active within a specific commit range.
7676pub fn layout_track_range (
7777 track_map : & TrackMap ,
@@ -80,16 +80,15 @@ pub fn layout_track_range(
8080) -> Result < TrackLayout , String > {
8181 let mut branch_visuals = Vec :: new ( ) ;
8282 let mut track_visual_map = HashMap :: new ( ) ;
83-
83+
8484 // Counter for color rotation moved here
8585 let mut color_counter = 0 ;
8686
8787 // --- Pass 1: Create initial BranchVis (Colors and Order Groups) ---
8888 for i in range. clone ( ) {
8989 // Find track assigned to commit
9090 let commit = & track_map. commits [ i] ;
91- let Some ( b_idx) = commit. branch_trace
92- else {
91+ let Some ( b_idx) = commit. branch_trace else {
9392 todo ! ( "Decide how to handle commit without track" ) ;
9493 /*
9594 Do I want to show it?
@@ -101,16 +100,12 @@ pub fn layout_track_range(
101100 // If the track does not yet have a visualization, create it
102101 if !track_visual_map. contains_key ( & b_idx) {
103102 let branch_info = & track_map. all_branches [ b_idx] ;
104-
103+
105104 // We increment the counter only when a new visual is needed
106105 color_counter += 1 ;
107106
108- let visual_data = create_branch_visual (
109- color_counter,
110- branch_info,
111- track_map,
112- settings
113- ) ?;
107+ let visual_data =
108+ create_branch_visual ( color_counter, branch_info, track_map, settings) ?;
114109
115110 let vis_idx = branch_visuals. len ( ) ;
116111 branch_visuals. push ( visual_data) ;
@@ -122,7 +117,7 @@ pub fn layout_track_range(
122117 // We iterate through the visuals we just created
123118 for ( b_idx, & vis_idx) in track_visual_map. iter ( ) {
124119 let branch = & track_map. all_branches [ * b_idx] ;
125-
120+
126121 // Resolve Target Order Group
127122 if let Some ( target_idx) = branch. target_branch {
128123 // Check if the target branch has a visual in our current layout
@@ -141,7 +136,7 @@ pub fn layout_track_range(
141136 }
142137 }
143138 }
144-
139+
145140 // Pass 3: The Packing Algorithm
146141 let mut layout = TrackLayout {
147142 source : range,
@@ -152,21 +147,21 @@ pub fn layout_track_range(
152147 BranchOrder :: ShortestFirst ( fwd) => ( true , fwd) ,
153148 BranchOrder :: LongestFirst ( fwd) => ( false , fwd) ,
154149 } ;
155- assign_branch_columns (
156- & track_map,
157- & mut layout,
158- settings,
159- shortest_first,
160- forward) ;
161-
150+ assign_branch_columns ( & track_map, & mut layout, settings, shortest_first, forward) ;
151+
162152 Ok ( layout)
163153}
164154
165155/// Find the index at which a between-branch connection
166156/// has to deviate from the current branch's column.
167157///
168158/// Returns the last index on the current column.
169- pub fn get_deviate_index ( tracks : & TrackMap , layout : & TrackLayout , index : usize , par_index : usize ) -> usize {
159+ pub fn get_deviate_index (
160+ tracks : & TrackMap ,
161+ layout : & TrackLayout ,
162+ index : usize ,
163+ par_index : usize ,
164+ ) -> usize {
170165 let info = & tracks. commits [ index] ;
171166
172167 let par_info = & tracks. commits [ par_index] ;
@@ -207,13 +202,17 @@ fn create_branch_visual(
207202) -> Result < BranchVis , String > {
208203 let mut name_to_color = & branch. name ;
209204
210- // The Logic from trace_branch:
205+ // The Logic from trace_branch:
211206 // If this is a remote branch, check if we should inherit a local color
212207 if branch. name . starts_with ( ORIGIN ) {
213208 let local_name = & branch. name [ 7 ..] ;
214209 // Look for a local branch with the same name in TrackMap
215- if let Some ( local_idx) = track_map. all_branches . iter ( ) . position ( |b| b. name == local_name) {
216- // We can now use the local_name for color calculation
210+ if let Some ( local_idx) = track_map
211+ . all_branches
212+ . iter ( )
213+ . position ( |b| b. name == local_name)
214+ {
215+ // We can now use the local_name for color calculation
217216 name_to_color = & track_map. all_branches [ local_idx] . name ;
218217 }
219218 }
@@ -256,13 +255,14 @@ pub fn assign_branch_columns(
256255 shortest_first : bool ,
257256 forward : bool ,
258257) {
259-
260258 let length_sort_factor = if shortest_first { 1 } else { -1 } ;
261259 let start_sort_factor = if forward { 1 } else { -1 } ;
262260
263261 // Collect keys used to sort branches.
264262 // We only care about branches that have a visual representation in this layout.
265- let mut branches_sort: BranchSort = layout. track_visual . iter ( )
263+ let mut branches_sort: BranchSort = layout
264+ . track_visual
265+ . iter ( )
266266 . map ( |( & branch_idx, & vis_idx) | {
267267 let br = & track_map. all_branches [ branch_idx] ;
268268 let vis = & layout. branch_visual [ vis_idx] ;
@@ -271,8 +271,10 @@ pub fn assign_branch_columns(
271271 vis_idx,
272272 br. range . 0 . unwrap_or ( 0 ) ,
273273 br. range . 1 . unwrap_or ( track_map. commits . len ( ) - 1 ) ,
274- vis. source_order_group . unwrap_or ( settings. branches . order . len ( ) + 1 ) ,
275- vis. target_order_group . unwrap_or ( settings. branches . order . len ( ) + 1 ) ,
274+ vis. source_order_group
275+ . unwrap_or ( settings. branches . order . len ( ) + 1 ) ,
276+ vis. target_order_group
277+ . unwrap_or ( settings. branches . order . len ( ) + 1 ) ,
276278 )
277279 } )
278280 . collect ( ) ;
@@ -308,7 +310,7 @@ fn assign_group_columns(
308310 branches_sort : BranchSort ,
309311 branch_list : & Vec < BranchInfo > ,
310312 layout : & mut TrackLayout ,
311- ) -> Occupation {
313+ ) -> Occupation {
312314 let mut occupied: Occupation = vec ! [ vec![ ] ; order_group_count] ;
313315
314316 for ( b_idx, v_idx, start, end, _, _) in branches_sort {
@@ -324,15 +326,17 @@ fn assign_group_columns(
324326
325327 for i in 0 ..col_count {
326328 let col_idx = if align_right { col_count - i - 1 } else { i } ;
327-
329+
328330 // Check if this column is physically blocked by another branch in this range
329- let is_blocked = group_occ[ col_idx] . iter ( ) . any ( |( s, e) | start <= * e && end >= * s) ;
330-
331+ let is_blocked = group_occ[ col_idx]
332+ . iter ( )
333+ . any ( |( s, e) | start <= * e && end >= * s) ;
334+
331335 if !is_blocked {
332- // Logic check: don't occupy the same column as our merge target
336+ // Logic check: don't occupy the same column as our merge target
333337 // if they overlap at the point of merge
334338 let is_merge_collision = check_merge_collision ( branch_topo, col_idx, layout) ;
335-
339+
336340 if !is_merge_collision {
337341 found_column = col_idx;
338342 break ;
@@ -349,13 +353,9 @@ fn assign_group_columns(
349353 }
350354
351355 occupied
352- }
356+ }
353357
354- fn finalize_absolute_columns (
355- branch_visual_list : & mut Vec < BranchVis > ,
356- occupied : Occupation
357- ) {
358-
358+ fn finalize_absolute_columns ( branch_visual_list : & mut Vec < BranchVis > , occupied : Occupation ) {
359359 // Compute start column of each group
360360 let mut group_offset: Vec < usize > = vec ! [ ] ;
361361 let mut acc = 0 ;
@@ -379,13 +379,15 @@ fn finalize_absolute_columns(
379379/// Helper: Determines if a branch prefers to be on the right side of its group
380380fn should_align_right ( branch : & BranchInfo , v_idx : usize , layout : & TrackLayout ) -> bool {
381381 let this_group = layout. branch_visual [ v_idx] . order_group ;
382-
383- let source_to_right = branch. source_branch
382+
383+ let source_to_right = branch
384+ . source_branch
384385 . and_then ( |s_idx| layout. track_visual . get ( & s_idx) )
385386 . map ( |& sv_idx| layout. branch_visual [ sv_idx] . order_group > this_group)
386387 . unwrap_or ( false ) ;
387388
388- let target_to_right = branch. target_branch
389+ let target_to_right = branch
390+ . target_branch
389391 . and_then ( |t_idx| layout. track_visual . get ( & t_idx) )
390392 . map ( |& tv_idx| layout. branch_visual [ tv_idx] . order_group > this_group)
391393 . unwrap_or ( false ) ;
@@ -398,10 +400,11 @@ fn check_merge_collision(branch: &BranchInfo, col_idx: usize, layout: &TrackLayo
398400 if let Some ( target_idx) = branch. target_branch {
399401 if let Some ( & tv_idx) = layout. track_visual . get ( & target_idx) {
400402 let target_vis = & layout. branch_visual [ tv_idx] ;
401- let this_vis = & layout. branch_visual [ layout. track_visual [ & branch. target_branch . unwrap ( ) ] ] ;
403+ let this_vis =
404+ & layout. branch_visual [ layout. track_visual [ & branch. target_branch . unwrap ( ) ] ] ;
402405
403- if target_vis. order_group == this_vis. order_group
404- && target_vis . column == Some ( col_idx ) {
406+ if target_vis. order_group == this_vis. order_group && target_vis . column == Some ( col_idx )
407+ {
405408 return true ;
406409 }
407410 }
0 commit comments