@@ -627,25 +627,35 @@ fn recur_tree(
627627 . truecolor ( branch_color. 0 , branch_color. 1 , branch_color. 2 )
628628 } ;
629629
630- // Get diff stats from LKG ancestor (or parent branch ) to current branch
630+ // Get diff stats from LKG ancestor (or merge-base ) to current branch
631631 let diff_stats = {
632- // Try lkg_parent first, fall back to resolved parent branch
633- let base_ref = branch
634- . lkg_parent
635- . as_deref ( )
636- . unwrap_or ( & branch_status. parent_branch ) ;
637-
638- match git_repo. diff_stats ( base_ref, & branch_status. sha ) {
639- Ok ( ( adds, dels) ) => {
640- let green = dim. apply ( colors:: GREEN ) ;
641- let red = dim. apply ( colors:: RED ) ;
642- format ! (
643- " [{} {}]" ,
644- format!( "+{}" , adds) . truecolor( green. 0 , green. 1 , green. 2 ) ,
645- format!( "-{}" , dels) . truecolor( red. 0 , red. 1 , red. 2 )
646- )
647- }
648- Err ( _) => String :: new ( ) ,
632+ // Determine base ref and whether it's reliable
633+ let ( base_ref, is_reliable) = if let Some ( lkg) = branch. lkg_parent . as_deref ( ) {
634+ ( Some ( lkg. to_string ( ) ) , true )
635+ } else if let Ok ( merge_base) =
636+ git_repo. merge_base ( & branch_status. parent_branch , & branch_status. sha )
637+ {
638+ ( Some ( merge_base) , false ) // merge-base is less reliable
639+ } else {
640+ ( None , false )
641+ } ;
642+
643+ match base_ref {
644+ Some ( base) => match git_repo. diff_stats ( & base, & branch_status. sha ) {
645+ Ok ( ( adds, dels) ) => {
646+ let green = dim. apply ( colors:: GREEN ) ;
647+ let red = dim. apply ( colors:: RED ) ;
648+ let prefix = if is_reliable { "" } else { "~ " } ;
649+ format ! (
650+ " [{}{}{}]" ,
651+ prefix,
652+ format!( "+{}" , adds) . truecolor( green. 0 , green. 1 , green. 2 ) ,
653+ format!( " -{}" , dels) . truecolor( red. 0 , red. 1 , red. 2 )
654+ )
655+ }
656+ Err ( _) => String :: new ( ) ,
657+ } ,
658+ None => String :: new ( ) ,
649659 }
650660 } ;
651661
0 commit comments