11use std:: {
22 cell:: { Cell , Ref , RefCell } ,
33 collections:: { BTreeMap , HashMap , VecDeque } ,
4- default,
5- fs,
4+ default, fs,
65 path:: PathBuf ,
76 process:: Command ,
87 rc:: Rc ,
@@ -14,14 +13,8 @@ use serde::{Deserialize, Serialize};
1413
1514use crate :: {
1615 git:: {
17- DEFAULT_REMOTE ,
18- GitTrunk ,
19- after_text,
20- git_branch_exists,
21- git_remote_main,
22- git_sha,
23- git_trunk,
24- is_ancestor,
16+ DEFAULT_REMOTE , GitTrunk , after_text, git_branch_exists, git_remote_main, git_sha,
17+ git_trunk, is_ancestor,
2518 } ,
2619 run_git,
2720} ;
@@ -180,11 +173,13 @@ impl State {
180173 } ;
181174 is_branch_mentioned_in_tree ( branch_name, branch)
182175 }
176+
183177 pub fn get_tree_branch < ' a > ( & ' a self , repo : & str , branch_name : & str ) -> Option < & ' a Branch > {
184178 self . trees
185179 . get ( repo)
186180 . and_then ( |tree| find_branch_by_name ( tree, branch_name) )
187181 }
182+
188183 fn get_tree_branch_mut < ' a > (
189184 & ' a mut self ,
190185 repo : & str ,
@@ -196,10 +191,10 @@ impl State {
196191 }
197192
198193 pub ( crate ) fn plan_restack (
199- & self ,
194+ & ' _ self ,
200195 repo : & str ,
201196 starting_branch : & str ,
202- ) -> Result < Vec < RestackStep > > {
197+ ) -> Result < Vec < RestackStep < ' _ > > > {
203198 tracing:: debug!( "Planning restack for {starting_branch}" ) ;
204199 let trunk = git_trunk ( ) ?;
205200 // Find all the descendents of the starting branch.
@@ -278,11 +273,10 @@ impl State {
278273 if let ( Some ( Branch { name : name_a, .. } ) , Some ( Branch { name : name_b, .. } ) ) = (
279274 self . get_parent_branch_of ( repo, branch_name) ,
280275 self . get_tree_branch ( repo, & parent_branch) ,
281- ) {
282- if name_a == name_b {
283- tracing:: warn!( "Branch {branch_name} is already mounted on {name_a}" ) ;
284- return Ok ( ( ) ) ;
285- }
276+ ) && name_a == name_b
277+ {
278+ tracing:: warn!( "Branch {branch_name} is already mounted on {name_a}" ) ;
279+ return Ok ( ( ) ) ;
286280 }
287281
288282 let current_parent_branch = self . get_parent_branch_of_mut ( repo, branch_name) ;
@@ -349,17 +343,17 @@ impl State {
349343 parent_lkgs. insert ( tree_branch. name . clone ( ) , None ) ;
350344 }
351345 }
352- if is_ancestor ( & parent, & branch) . unwrap_or ( false ) {
353- if let Ok ( new_lkg_parent) = git_sha ( & parent) {
354- tracing :: debug! (
355- lkg_parent = ?new_lkg_parent ,
356- "Branch {} is a descendent of {}" ,
357- branch . yellow ( ) ,
358- parent . yellow( ) ,
359- ) ;
360- // Save the LKG parent for the branch.
361- parent_lkgs . insert ( branch. clone ( ) , Some ( new_lkg_parent ) ) ;
362- }
346+ if is_ancestor ( & parent, & branch) . unwrap_or ( false )
347+ && let Ok ( new_lkg_parent) = git_sha ( & parent)
348+ {
349+ tracing :: debug! (
350+ lkg_parent = ?new_lkg_parent ,
351+ "Branch {} is a descendent of {}" ,
352+ branch . yellow( ) ,
353+ parent . yellow ( ) ,
354+ ) ;
355+ // Save the LKG parent for the branch.
356+ parent_lkgs . insert ( branch . clone ( ) , Some ( new_lkg_parent ) ) ;
363357 }
364358 }
365359 if let Some ( branch) = self . get_tree_branch ( repo, & branch) {
@@ -551,7 +545,7 @@ mod tests {
551545 "/tmp/foo" . to_string( ) ,
552546 super :: Branch {
553547 name: "main" . to_string( ) ,
554- stack_method: Some ( super :: StackMethod :: ApplyMerge ) ,
548+ stack_method: super :: StackMethod :: ApplyMerge ,
555549 note: None ,
556550 lkg_parent: None ,
557551 branches: vec![ ] ,
@@ -574,6 +568,6 @@ mod tests {
574568 assert ! ( state. trees. contains_key( "/tmp/foo" ) ) ;
575569 let tree = state. trees . get ( "/tmp/foo" ) . unwrap ( ) ;
576570 assert_eq ! ( tree. name, "main" ) ;
577- assert_eq ! ( tree. stack_method, Some ( super :: StackMethod :: ApplyMerge ) ) ;
571+ assert_eq ! ( tree. stack_method, super :: StackMethod :: ApplyMerge ) ;
578572 }
579573}
0 commit comments