@@ -8,6 +8,7 @@ use gitbutler_oplog::SnapshotExt;
88use gitbutler_project:: access:: WorktreeWritePermission ;
99use gitbutler_reference:: { normalize_branch_name, ReferenceName , Refname } ;
1010use gitbutler_repo:: { RepoActionsExt , RepositoryExt } ;
11+ use tracing:: instrument;
1112
1213use super :: BranchManager ;
1314use crate :: {
@@ -19,6 +20,7 @@ use crate::{
1920
2021impl BranchManager < ' _ > {
2122 // to unapply a branch, we need to write the current tree out, then remove those file changes from the wd
23+ #[ instrument( level = tracing:: Level :: DEBUG , skip( self , perm) , err( Debug ) ) ]
2224 pub fn convert_to_real_branch (
2325 & self ,
2426 branch_id : BranchId ,
@@ -52,6 +54,7 @@ impl BranchManager<'_> {
5254 real_branch. reference_name ( )
5355 }
5456
57+ #[ instrument( level = tracing:: Level :: DEBUG , skip( self , perm) , err( Debug ) ) ]
5558 pub ( crate ) fn delete_branch (
5659 & self ,
5760 branch_id : BranchId ,
@@ -88,30 +91,38 @@ impl BranchManager<'_> {
8891
8992 // go through the other applied branches and merge them into the final tree
9093 // then check that out into the working directory
91- let final_tree = applied_statuses
92- . into_iter ( )
93- . filter ( |( branch, _) | branch. id != branch_id)
94- . fold (
95- target_commit. tree ( ) . context ( "failed to get target tree" ) ,
96- |final_tree, status| {
97- let final_tree = final_tree?;
98- let branch = status. 0 ;
99- let files = status
100- . 1
101- . into_iter ( )
102- . map ( |file| ( file. path , file. hunks ) )
103- . collect :: < Vec < ( PathBuf , Vec < VirtualBranchHunk > ) > > ( ) ;
104- let tree_oid =
105- gitbutler_diff:: write:: hunks_onto_oid ( self . ctx , & branch. head , files) ?;
106- let branch_tree = repo. find_tree ( tree_oid) ?;
107- let mut result =
108- repo. merge_trees ( & base_tree, & final_tree, & branch_tree, None ) ?;
109- let final_tree_oid = result. write_tree_to ( repo) ?;
110- repo. find_tree ( final_tree_oid)
111- . context ( "failed to find tree" )
112- } ,
113- ) ?;
94+ let final_tree = {
95+ let _span = tracing:: debug_span!(
96+ "new tree without deleted branch" ,
97+ num_branches = applied_statuses. len( ) - 1
98+ )
99+ . entered ( ) ;
100+ applied_statuses
101+ . into_iter ( )
102+ . filter ( |( branch, _) | branch. id != branch_id)
103+ . fold (
104+ target_commit. tree ( ) . context ( "failed to get target tree" ) ,
105+ |final_tree, status| {
106+ let final_tree = final_tree?;
107+ let branch = status. 0 ;
108+ let files = status
109+ . 1
110+ . into_iter ( )
111+ . map ( |file| ( file. path , file. hunks ) )
112+ . collect :: < Vec < ( PathBuf , Vec < VirtualBranchHunk > ) > > ( ) ;
113+ let tree_oid =
114+ gitbutler_diff:: write:: hunks_onto_oid ( self . ctx , branch. head , files) ?;
115+ let branch_tree = repo. find_tree ( tree_oid) ?;
116+ let mut result =
117+ repo. merge_trees ( & base_tree, & final_tree, & branch_tree, None ) ?;
118+ let final_tree_oid = result. write_tree_to ( repo) ?;
119+ repo. find_tree ( final_tree_oid)
120+ . context ( "failed to find tree" )
121+ } ,
122+ ) ?
123+ } ;
114124
125+ let _span = tracing:: debug_span!( "checkout final tree" ) . entered ( ) ;
115126 // checkout final_tree into the working directory
116127 repo. checkout_tree_builder ( & final_tree)
117128 . force ( )
@@ -128,6 +139,7 @@ impl BranchManager<'_> {
128139}
129140
130141impl BranchManager < ' _ > {
142+ #[ instrument( level = tracing:: Level :: DEBUG , skip( self , vbranch) , err( Debug ) ) ]
131143 fn build_real_branch ( & self , vbranch : & mut Branch ) -> Result < git2:: Branch < ' _ > > {
132144 let repo = self . ctx . repository ( ) ;
133145 let target_commit = repo. find_commit ( vbranch. head ) ?;
0 commit comments