@@ -15,9 +15,9 @@ use crate::error::*;
15
15
use crate :: git:: Git ;
16
16
use crate :: sess:: { DependencySource , Session } ;
17
17
use glob:: Pattern ;
18
+ use std:: collections:: HashSet ;
18
19
use std:: path:: Path ;
19
20
use std:: path:: PathBuf ;
20
- use std:: collections:: HashSet ;
21
21
use tempfile:: TempDir ;
22
22
23
23
/// A patch linkage
@@ -152,17 +152,17 @@ pub fn run(sess: &Session, matches: &ArgMatches) -> Result<()> {
152
152
// 1. file links over directory links eg 'a/file -> c/file' before 'b/ -> c/'
153
153
// 2. subdirs (deeper paths) first eg 'a/aa/ -> c/aa' before 'a/ab -> c/'
154
154
let mut sorted_links: Vec < _ > = patch_links. clone ( ) ;
155
- sorted_links. sort_by ( |a, b| {
155
+ sorted_links. sort_by ( |a, b| {
156
156
let a_is_file = a. to_prefix . is_file ( ) ;
157
157
let b_is_file = b. to_prefix . is_file ( ) ;
158
158
159
159
if a_is_file != b_is_file {
160
160
return b_is_file. cmp ( & a_is_file) ;
161
161
}
162
-
162
+
163
163
let a_depth = a. to_prefix . iter ( ) . count ( ) ;
164
164
let b_depth = b. to_prefix . iter ( ) . count ( ) ;
165
-
165
+
166
166
b_depth. cmp ( & a_depth)
167
167
} ) ;
168
168
@@ -175,17 +175,20 @@ pub fn run(sess: &Session, matches: &ArgMatches) -> Result<()> {
175
175
. filter ( |path| path. starts_with ( & patch_link. to_prefix ) ) // subdir?
176
176
. cloned ( )
177
177
. collect ( ) ;
178
-
179
- seen_paths. insert ( patch_link. to_prefix . clone ( ) ) ;
178
+
179
+ seen_paths. insert ( patch_link. to_prefix . clone ( ) ) ;
180
180
}
181
181
let git = Git :: new ( tmp_path, & sess. config . git ) ;
182
182
183
183
match matches. subcommand ( ) {
184
184
Some ( ( "diff" , matches) ) => {
185
185
// Apply patches
186
- sorted_links. clone ( ) . into_iter ( ) . try_for_each ( |patch_link| {
187
- apply_patches ( & rt, git, vendor_package. name . clone ( ) , patch_link) . map ( |_| ( ) )
188
- } ) ?;
186
+ sorted_links
187
+ . clone ( )
188
+ . into_iter ( )
189
+ . try_for_each ( |patch_link| {
190
+ apply_patches ( & rt, git, vendor_package. name . clone ( ) , patch_link) . map ( |_| ( ) )
191
+ } ) ?;
189
192
190
193
// Stage applied patches to clean working tree
191
194
rt. block_on ( git. add_all ( ) ) ?;
@@ -399,12 +402,13 @@ pub fn apply_patches(
399
402
} )
400
403
. and_then ( |_| {
401
404
git. spawn_with ( |c| {
402
- let is_file = patch_link. from_prefix
405
+ let is_file = patch_link
406
+ . from_prefix
403
407
. clone ( )
404
408
. prefix_paths ( git. path )
405
409
. unwrap ( )
406
410
. is_file ( ) ;
407
-
411
+
408
412
let current_patch_target = if is_file {
409
413
patch_link. from_prefix . parent ( ) . unwrap ( ) . to_str ( ) . unwrap ( )
410
414
} else {
@@ -572,7 +576,6 @@ pub fn gen_format_patch(
572
576
target_dir : impl AsRef < Path > ,
573
577
message : Option < & String > ,
574
578
) -> Result < ( ) > {
575
-
576
579
// Local git
577
580
let to_path = patch_link
578
581
. to_prefix
@@ -606,21 +609,28 @@ pub fn gen_format_patch(
606
609
// If the patch link maps a file, we operate in the file's parent directory
607
610
// Therefore, only get the diff for that file.
608
611
let include_pathspec = if !to_path. is_dir ( ) {
609
- patch_link. to_prefix . file_name ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) . to_string ( )
612
+ patch_link
613
+ . to_prefix
614
+ . file_name ( )
615
+ . unwrap ( )
616
+ . to_str ( )
617
+ . unwrap ( )
618
+ . to_string ( )
610
619
} else {
611
620
"." . to_string ( )
612
621
} ;
613
-
622
+
614
623
// Build the exclude pathspec to diff only the applicable files
615
- let exclude_pathspecs: Vec < String > = patch_link. exclude . iter ( ) . map ( |path| {
616
- format ! ( ":!{}" , path. to_str( ) . unwrap( ) )
617
- } )
618
- . collect ( ) ;
619
-
624
+ let exclude_pathspecs: Vec < String > = patch_link
625
+ . exclude
626
+ . iter ( )
627
+ . map ( |path| format ! ( ":!{}" , path. to_str( ) . unwrap( ) ) )
628
+ . collect ( ) ;
629
+
620
630
let mut diff_args = vec ! [
621
631
"diff" . to_string( ) ,
622
632
"--relative" . to_string( ) ,
623
- "--cached" . to_string( )
633
+ "--cached" . to_string( ) ,
624
634
] ;
625
635
626
636
diff_args. push ( include_pathspec) ;
@@ -630,13 +640,7 @@ pub fn gen_format_patch(
630
640
631
641
// Get staged changes in dependency
632
642
let get_diff_cached = rt
633
- . block_on ( async {
634
- git_parent
635
- . spawn_with ( |c| {
636
- c. args ( & diff_args)
637
- } )
638
- . await
639
- } )
643
+ . block_on ( async { git_parent. spawn_with ( |c| c. args ( & diff_args) ) . await } )
640
644
. map_err ( |cause| Error :: chain ( "Failed to generate diff" , cause) ) ?;
641
645
642
646
if !get_diff_cached. is_empty ( ) {
0 commit comments