@@ -231,15 +231,15 @@ fn run(matches: &ArgMatches) -> Result<()> {
231
231
let repo = git2:: Repository :: open_from_env ( ) ?;
232
232
if let Some ( ( subname, submatches) ) = matches. subcommand ( ) {
233
233
match subname {
234
- "--list" => list ( repo, submatches) ,
235
- "--create" => create ( repo, submatches) ,
236
- "--clone" => clone ( repo, submatches) ,
237
- "--rename" => rename ( repo, submatches) ,
238
- "--protect" => protect ( repo, submatches) ,
239
- "--unprotect" => unprotect ( repo, submatches) ,
240
- "--delete" => delete ( repo, submatches) ,
241
- "--cleanup" => cleanup ( repo, submatches) ,
242
- "--describe" => describe ( repo, submatches) ,
234
+ "--list" => list ( & repo, submatches) ,
235
+ "--create" => create ( & repo, submatches) ,
236
+ "--clone" => clone ( & repo, submatches) ,
237
+ "--rename" => rename ( & repo, submatches) ,
238
+ "--protect" => protect ( & repo, submatches) ,
239
+ "--unprotect" => unprotect ( & repo, submatches) ,
240
+ "--delete" => delete ( & repo, submatches) ,
241
+ "--cleanup" => cleanup ( & repo, submatches) ,
242
+ "--describe" => describe ( & repo, submatches) ,
243
243
s => panic ! ( "unhandled branch subcommand {s}" ) ,
244
244
}
245
245
} else {
@@ -316,7 +316,7 @@ fn set_stgit_parent(
316
316
}
317
317
}
318
318
319
- fn list ( repo : git2:: Repository , matches : & ArgMatches ) -> Result < ( ) > {
319
+ fn list ( repo : & git2:: Repository , matches : & ArgMatches ) -> Result < ( ) > {
320
320
let mut branchnames = Vec :: new ( ) ;
321
321
for branch_result in repo. branches ( Some ( git2:: BranchType :: Local ) ) ? {
322
322
let ( branch, _branch_type) = branch_result?;
@@ -328,13 +328,13 @@ fn list(repo: git2::Repository, matches: &ArgMatches) -> Result<()> {
328
328
}
329
329
330
330
branchnames. sort ( ) ;
331
- let branchname_width = branchnames. iter ( ) . map ( |s| s . len ( ) ) . max ( ) ;
331
+ let branchname_width = branchnames. iter ( ) . map ( String :: len) . max ( ) ;
332
332
333
333
let current_branchname = repo. get_branch ( None ) . ok ( ) . and_then ( |branch| {
334
334
branch
335
335
. name ( )
336
336
. ok ( )
337
- . and_then ( |name| name. map ( |s| s . to_string ( ) ) )
337
+ . and_then ( |name| name. map ( ToString :: to_string) )
338
338
} ) ;
339
339
340
340
let config = repo. config ( ) ?;
@@ -354,7 +354,7 @@ fn list(repo: git2::Repository, matches: &ArgMatches) -> Result<()> {
354
354
write ! ( stdout, " " ) ?;
355
355
} ;
356
356
357
- if let Ok ( stack) = Stack :: from_branch ( & repo, Some ( branchname) ) {
357
+ if let Ok ( stack) = Stack :: from_branch ( repo, Some ( branchname) ) {
358
358
color_spec. set_fg ( Some ( termcolor:: Color :: Cyan ) ) ;
359
359
stdout. set_color ( & color_spec) ?;
360
360
write ! ( stdout, "s" ) ?;
@@ -401,7 +401,7 @@ fn list(repo: git2::Repository, matches: &ArgMatches) -> Result<()> {
401
401
Ok ( ( ) )
402
402
}
403
403
404
- fn create ( repo : git2:: Repository , matches : & ArgMatches ) -> Result < ( ) > {
404
+ fn create ( repo : & git2:: Repository , matches : & ArgMatches ) -> Result < ( ) > {
405
405
let new_branchname = get_one_str ( matches, "new-branch" ) . expect ( "required argument" ) ;
406
406
407
407
repo. check_repository_state ( ) ?;
@@ -441,7 +441,7 @@ fn create(repo: git2::Repository, matches: &ArgMatches) -> Result<()> {
441
441
let target_commit = if let Some ( parent_branch) = parent_branch. as_ref ( ) {
442
442
parent_branch. get ( ) . peel_to_commit ( ) ?
443
443
} else if let Some ( committish) = get_one_str ( matches, "committish" ) {
444
- crate :: revspec:: parse_stgit_revision ( & repo, Some ( committish) , None ) ?. peel_to_commit ( ) ?
444
+ crate :: revspec:: parse_stgit_revision ( repo, Some ( committish) , None ) ?. peel_to_commit ( ) ?
445
445
} else {
446
446
repo. head ( ) ?. peel_to_commit ( ) ?
447
447
} ;
@@ -454,7 +454,7 @@ fn create(repo: git2::Repository, matches: &ArgMatches) -> Result<()> {
454
454
455
455
let mut config = repo. config ( ) ?;
456
456
let mut new_branch = repo. branch ( new_branchname, & target_commit, false ) ?;
457
- let stack = match Stack :: initialize ( & repo, Some ( new_branchname) ) {
457
+ let stack = match Stack :: initialize ( repo, Some ( new_branchname) ) {
458
458
Ok ( stack) => stack,
459
459
Err ( e) => {
460
460
new_branch. delete ( ) ?;
@@ -493,7 +493,7 @@ fn create(repo: git2::Repository, matches: &ArgMatches) -> Result<()> {
493
493
}
494
494
}
495
495
496
- fn clone ( repo : git2:: Repository , matches : & ArgMatches ) -> Result < ( ) > {
496
+ fn clone ( repo : & git2:: Repository , matches : & ArgMatches ) -> Result < ( ) > {
497
497
let current_branch = repo. get_branch ( None ) ?;
498
498
let current_branchname = get_branch_name ( & current_branch) ?;
499
499
@@ -510,7 +510,7 @@ fn clone(repo: git2::Repository, matches: &ArgMatches) -> Result<()> {
510
510
repo. check_repository_state ( ) ?;
511
511
statuses. check_conflicts ( ) ?;
512
512
513
- if let Ok ( stack) = Stack :: from_branch ( & repo, None ) {
513
+ if let Ok ( stack) = Stack :: from_branch ( repo, None ) {
514
514
stack. check_head_top_mismatch ( ) ?;
515
515
let state_ref = repo
516
516
. find_reference ( & stack. refname )
@@ -525,7 +525,7 @@ fn clone(repo: git2::Repository, matches: &ArgMatches) -> Result<()> {
525
525
stupid. branch_copy ( None , & new_branchname) ?;
526
526
} else {
527
527
stupid. branch_copy ( None , & new_branchname) ?;
528
- Stack :: initialize ( & repo, Some ( & new_branchname) ) ?;
528
+ Stack :: initialize ( repo, Some ( & new_branchname) ) ?;
529
529
} ;
530
530
531
531
let mut config = repo. config ( ) ?;
@@ -542,11 +542,11 @@ fn clone(repo: git2::Repository, matches: &ArgMatches) -> Result<()> {
542
542
stupid. checkout ( new_branch. name ( ) . unwrap ( ) . unwrap ( ) )
543
543
}
544
544
545
- fn rename ( repo : git2:: Repository , matches : & ArgMatches ) -> Result < ( ) > {
545
+ fn rename ( repo : & git2:: Repository , matches : & ArgMatches ) -> Result < ( ) > {
546
546
let names: Vec < _ > = matches
547
547
. get_many :: < String > ( "branch-any" )
548
548
. unwrap ( )
549
- . map ( |s| s . as_str ( ) )
549
+ . map ( String :: as_str)
550
550
. collect ( ) ;
551
551
let current_branchname;
552
552
let ( old_branchname, new_branchname) = if names. len ( ) == 2 {
@@ -562,7 +562,7 @@ fn rename(repo: git2::Repository, matches: &ArgMatches) -> Result<()> {
562
562
let mut config = repo. config ( ) ?;
563
563
let parent_branchname = get_stgit_parent ( & config, old_branchname) ;
564
564
565
- if let Ok ( stack) = Stack :: from_branch ( & repo, Some ( old_branchname) ) {
565
+ if let Ok ( stack) = Stack :: from_branch ( repo, Some ( old_branchname) ) {
566
566
let state_commit = repo
567
567
. find_reference ( & stack. refname )
568
568
. expect ( "just found this stack state reference" )
@@ -582,19 +582,19 @@ fn rename(repo: git2::Repository, matches: &ArgMatches) -> Result<()> {
582
582
Ok ( ( ) )
583
583
}
584
584
585
- fn protect ( repo : git2:: Repository , matches : & ArgMatches ) -> Result < ( ) > {
586
- let stack = Stack :: from_branch ( & repo, get_one_str ( matches, "branch" ) ) ?;
585
+ fn protect ( repo : & git2:: Repository , matches : & ArgMatches ) -> Result < ( ) > {
586
+ let stack = Stack :: from_branch ( repo, get_one_str ( matches, "branch" ) ) ?;
587
587
let mut config = repo. config ( ) ?;
588
588
stack. set_protected ( & mut config, true )
589
589
}
590
590
591
- fn unprotect ( repo : git2:: Repository , matches : & ArgMatches ) -> Result < ( ) > {
592
- let stack = Stack :: from_branch ( & repo, get_one_str ( matches, "branch" ) ) ?;
591
+ fn unprotect ( repo : & git2:: Repository , matches : & ArgMatches ) -> Result < ( ) > {
592
+ let stack = Stack :: from_branch ( repo, get_one_str ( matches, "branch" ) ) ?;
593
593
let mut config = repo. config ( ) ?;
594
594
stack. set_protected ( & mut config, false )
595
595
}
596
596
597
- fn delete ( repo : git2:: Repository , matches : & ArgMatches ) -> Result < ( ) > {
597
+ fn delete ( repo : & git2:: Repository , matches : & ArgMatches ) -> Result < ( ) > {
598
598
let target_branchname = get_one_str ( matches, "branch-any" ) . expect ( "required argument" ) ;
599
599
let mut target_branch = repo. get_branch ( Some ( target_branchname) ) ?;
600
600
let current_branch = repo. get_branch ( None ) . ok ( ) ;
@@ -605,7 +605,7 @@ fn delete(repo: git2::Repository, matches: &ArgMatches) -> Result<()> {
605
605
606
606
let config = repo. config ( ) ?;
607
607
608
- if let Ok ( stack) = Stack :: from_branch ( & repo, Some ( target_branchname) ) {
608
+ if let Ok ( stack) = Stack :: from_branch ( repo, Some ( target_branchname) ) {
609
609
if stack. is_protected ( & config) {
610
610
return Err ( anyhow ! ( "Delete not permitted: this branch is protected" ) ) ;
611
611
} else if !matches. get_flag ( "force" ) && stack. all_patches ( ) . count ( ) > 0 {
@@ -620,8 +620,8 @@ fn delete(repo: git2::Repository, matches: &ArgMatches) -> Result<()> {
620
620
Ok ( ( ) )
621
621
}
622
622
623
- fn cleanup ( repo : git2:: Repository , matches : & ArgMatches ) -> Result < ( ) > {
624
- let stack = Stack :: from_branch ( & repo, get_one_str ( matches, "branch" ) ) ?;
623
+ fn cleanup ( repo : & git2:: Repository , matches : & ArgMatches ) -> Result < ( ) > {
624
+ let stack = Stack :: from_branch ( repo, get_one_str ( matches, "branch" ) ) ?;
625
625
let config = repo. config ( ) ?;
626
626
if stack. is_protected ( & config) {
627
627
return Err ( anyhow ! ( "Clean up not permitted: this branch is protected" ) ) ;
@@ -634,7 +634,7 @@ fn cleanup(repo: git2::Repository, matches: &ArgMatches) -> Result<()> {
634
634
Ok ( ( ) )
635
635
}
636
636
637
- fn describe ( repo : git2:: Repository , matches : & ArgMatches ) -> Result < ( ) > {
637
+ fn describe ( repo : & git2:: Repository , matches : & ArgMatches ) -> Result < ( ) > {
638
638
let branch = repo. get_branch ( get_one_str ( matches, "branch-any" ) ) ?;
639
639
let description = get_one_str ( matches, "description" ) . expect ( "required argument" ) ;
640
640
let branchname = get_branch_name ( & branch) ?;
0 commit comments