@@ -7,24 +7,26 @@ use gitbutler_repo::{
77 rebase:: cherry_rebase_group,
88} ;
99use gitbutler_stack:: { OwnershipClaim , Stack , StackId } ;
10+ use tracing:: instrument;
1011
1112use crate :: VirtualBranchesExt as _;
1213
1314/// Removes a commit from a branch by rebasing all commits _except_ for it
1415/// onto it's parent.
1516///
16- /// if successful, it will update the branch head to the new head commit.
17+ /// If successful, it will update the branch head to the new head commit.
1718///
1819/// It intentionally does **not** update the branch tree. It is a feature
1920/// of the operation that the branch tree will not be updated as it allows
2021/// the user to then re-commit the changes if they wish.
2122///
2223/// This may create conflicted commits above the commit that is getting
2324/// undone.
25+ #[ instrument( level = tracing:: Level :: DEBUG , skip( ctx) ) ]
2426pub ( crate ) fn undo_commit (
2527 ctx : & CommandContext ,
2628 stack_id : StackId ,
27- commit_oid : git2:: Oid ,
29+ commit_to_remove : git2:: Oid ,
2830) -> Result < Stack > {
2931 let vb_state = ctx. project ( ) . virtual_branches ( ) ;
3032
@@ -33,15 +35,15 @@ pub(crate) fn undo_commit(
3335 let UndoResult {
3436 new_head : new_head_commit,
3537 ownership_update,
36- } = inner_undo_commit ( ctx. repo ( ) , stack. head ( ) , commit_oid ) ?;
38+ } = rebase_excluding ( ctx. repo ( ) , stack. head ( ) , commit_to_remove ) ?;
3739
3840 for ownership in ownership_update {
3941 stack. ownership . put ( ownership) ;
4042 }
4143
4244 stack. set_stack_head ( ctx, new_head_commit, None ) ?;
4345
44- let removed_commit = ctx. repo ( ) . find_commit ( commit_oid ) ?;
46+ let removed_commit = ctx. repo ( ) . find_commit ( commit_to_remove ) ?;
4547 stack. replace_head ( ctx, & removed_commit, & removed_commit. parent ( 0 ) ?) ?;
4648
4749 crate :: integration:: update_workspace_commit ( & vb_state, ctx)
@@ -55,7 +57,8 @@ struct UndoResult {
5557 ownership_update : Vec < OwnershipClaim > ,
5658}
5759
58- fn inner_undo_commit (
60+ #[ instrument( level = tracing:: Level :: DEBUG , skip( repository) ) ]
61+ fn rebase_excluding (
5962 repository : & git2:: Repository ,
6063 branch_head_commit : git2:: Oid ,
6164 commit_to_remove : git2:: Oid ,
@@ -82,14 +85,13 @@ fn inner_undo_commit(
8285 . hunks
8386 . iter ( )
8487 . map ( Into :: into)
85- . filter ( |hunk : & Hunk | hunk . start != 0 && hunk. end != 0 )
88+ . filter ( |hunk : & Hunk | ! hunk. is_null ( ) )
8689 . collect :: < Vec < _ > > ( ) ;
8790 if hunks. is_empty ( ) {
8891 return None ;
8992 }
90- Some ( ( file_path, hunks) )
93+ Some ( OwnershipClaim { file_path, hunks } )
9194 } )
92- . map ( |( file_path, hunks) | OwnershipClaim { file_path, hunks } )
9395 . collect :: < Vec < _ > > ( ) ;
9496
9597 // if commit is the head, just set head to the parent
@@ -131,7 +133,7 @@ mod test {
131133 assert_commit_tree_matches, TestingRepository ,
132134 } ;
133135
134- use crate :: undo_commit:: { inner_undo_commit , UndoResult } ;
136+ use crate :: undo_commit:: { rebase_excluding , UndoResult } ;
135137
136138 #[ test]
137139 fn undoing_conflicted_commit_errors ( ) {
@@ -146,7 +148,7 @@ mod test {
146148
147149 // Branch looks like "A -> ConflictedCommit"
148150
149- let result = inner_undo_commit (
151+ let result = rebase_excluding (
150152 & test_repository. repository ,
151153 conflicted_commit. id ( ) ,
152154 conflicted_commit. id ( ) ,
@@ -169,7 +171,7 @@ mod test {
169171 let UndoResult {
170172 new_head,
171173 ownership_update,
172- } = inner_undo_commit ( & test_repository. repository , c. id ( ) , c. id ( ) ) . unwrap ( ) ;
174+ } = rebase_excluding ( & test_repository. repository , c. id ( ) , c. id ( ) ) . unwrap ( ) ;
173175
174176 assert_eq ! ( new_head, b. id( ) , "The new head should be C's parent" ) ;
175177 assert_eq ! (
@@ -208,7 +210,7 @@ mod test {
208210 let UndoResult {
209211 new_head,
210212 ownership_update,
211- } = inner_undo_commit ( & test_repository. repository , c. id ( ) , b. id ( ) ) . unwrap ( ) ;
213+ } = rebase_excluding ( & test_repository. repository , c. id ( ) , b. id ( ) ) . unwrap ( ) ;
212214
213215 let new_head_commit: git2:: Commit =
214216 test_repository. repository . find_commit ( new_head) . unwrap ( ) ;
0 commit comments