@@ -107,8 +107,17 @@ impl<'cfg> PathSource<'cfg> {
107
107
fn _list_files ( & self , pkg : & Package ) -> CargoResult < Vec < PathBuf > > {
108
108
let root = pkg. root ( ) ;
109
109
let no_include_option = pkg. manifest ( ) . include ( ) . is_empty ( ) ;
110
+ let git_repo = if no_include_option {
111
+ self . discover_git_repo ( root) ?
112
+ } else {
113
+ None
114
+ } ;
110
115
111
116
let mut exclude_builder = GitignoreBuilder :: new ( root) ;
117
+ if no_include_option && git_repo. is_none ( ) {
118
+ // no include option and not git repo discovered (see rust-lang/cargo#7183).
119
+ exclude_builder. add_line ( None , ".*" ) ?;
120
+ }
112
121
for rule in pkg. manifest ( ) . exclude ( ) {
113
122
exclude_builder. add_line ( None , rule) ?;
114
123
}
@@ -160,23 +169,16 @@ impl<'cfg> PathSource<'cfg> {
160
169
161
170
// Attempt Git-prepopulate only if no `include` (see rust-lang/cargo#4135).
162
171
if no_include_option {
163
- if let Some ( result ) = self . discover_git_and_list_files ( pkg , root , & mut filter ) ? {
164
- return Ok ( result ) ;
172
+ if let Some ( repo ) = git_repo {
173
+ return self . list_files_git ( pkg , & repo , & mut filter ) ;
165
174
}
166
- // no include option and not git repo discovered (see rust-lang/cargo#7183).
167
- return self . list_files_walk_except_dot_files_and_dirs ( pkg, & mut filter) ;
168
175
}
169
176
self . list_files_walk ( pkg, & mut filter)
170
177
}
171
178
172
- // Returns `Some(_)` if found sibling `Cargo.toml` and `.git` directory;
173
- // otherwise, caller should fall back on full file list.
174
- fn discover_git_and_list_files (
175
- & self ,
176
- pkg : & Package ,
177
- root : & Path ,
178
- filter : & mut dyn FnMut ( & Path , bool ) -> CargoResult < bool > ,
179
- ) -> CargoResult < Option < Vec < PathBuf > > > {
179
+ /// Returns `Some(git2::Repository)` if found sibling `Cargo.toml` and `.git`
180
+ /// directory; otherwise, caller should fall back on full file list.
181
+ fn discover_git_repo ( & self , root : & Path ) -> CargoResult < Option < git2:: Repository > > {
180
182
let repo = match git2:: Repository :: discover ( root) {
181
183
Ok ( repo) => repo,
182
184
Err ( e) => {
@@ -211,7 +213,7 @@ impl<'cfg> PathSource<'cfg> {
211
213
} ;
212
214
let manifest_path = repo_relative_path. join ( "Cargo.toml" ) ;
213
215
if index. get_path ( & manifest_path, 0 ) . is_some ( ) {
214
- return Ok ( Some ( self . list_files_git ( pkg , & repo, filter ) ? ) ) ;
216
+ return Ok ( Some ( repo) ) ;
215
217
}
216
218
// Package Cargo.toml is not in git, don't use git to guide our selection.
217
219
Ok ( None )
@@ -355,27 +357,6 @@ impl<'cfg> PathSource<'cfg> {
355
357
}
356
358
}
357
359
358
- fn list_files_walk_except_dot_files_and_dirs (
359
- & self ,
360
- pkg : & Package ,
361
- filter : & mut dyn FnMut ( & Path , bool ) -> CargoResult < bool > ,
362
- ) -> CargoResult < Vec < PathBuf > > {
363
- let root = pkg. root ( ) ;
364
- let mut exclude_dot_files_dir_builder = GitignoreBuilder :: new ( root) ;
365
- exclude_dot_files_dir_builder. add_line ( None , ".*" ) ?;
366
- let ignore_dot_files_and_dirs = exclude_dot_files_dir_builder. build ( ) ?;
367
-
368
- let mut filter_ignore_dot_files_and_dirs =
369
- |path : & Path , is_dir : bool | -> CargoResult < bool > {
370
- let relative_path = path. strip_prefix ( root) ?;
371
- match ignore_dot_files_and_dirs. matched_path_or_any_parents ( relative_path, is_dir) {
372
- Match :: Ignore ( _) => Ok ( false ) ,
373
- _ => filter ( path, is_dir) ,
374
- }
375
- } ;
376
- self . list_files_walk ( pkg, & mut filter_ignore_dot_files_and_dirs)
377
- }
378
-
379
360
fn list_files_walk (
380
361
& self ,
381
362
pkg : & Package ,
0 commit comments