@@ -75,6 +75,8 @@ impl GitGraph {
7575
7676 let head = HeadInfo :: new ( & repository. head ( ) . map_err ( |err| err. message ( ) . to_string ( ) ) ?) ?;
7777
78+ // commits will hold the CommitInfo for all commits covered
79+ // indices maps git object id to an index into commits.
7880 let mut commits = Vec :: new ( ) ;
7981 let mut indices = HashMap :: new ( ) ;
8082 let mut idx = 0 ;
@@ -115,22 +117,26 @@ impl GitGraph {
115117 forward,
116118 ) ;
117119
120+ // Remove commits not on a branch. This will give all commits a new index.
118121 let filtered_commits: Vec < CommitInfo > = commits
119122 . into_iter ( )
120123 . filter ( |info| info. branch_trace . is_some ( ) )
121124 . collect ( ) ;
122125
126+ // Create indices from git object id into the filtered commits
123127 let filtered_indices: HashMap < Oid , usize > = filtered_commits
124128 . iter ( )
125129 . enumerate ( )
126130 . map ( |( idx, info) | ( info. oid , idx) )
127131 . collect ( ) ;
128132
133+ // Map from old index to new index. None, if old index was removed
129134 let index_map: HashMap < usize , Option < & usize > > = indices
130135 . iter ( )
131136 . map ( |( oid, index) | ( * index, filtered_indices. get ( oid) ) )
132137 . collect ( ) ;
133138
139+ // Update branch.range from old to new index. Shrink if endpoints were removed.
134140 for branch in all_branches. iter_mut ( ) {
135141 if let Some ( mut start_idx) = branch. range . 0 {
136142 let mut idx0 = index_map[ & start_idx] ;
0 commit comments