Skip to content

Commit dbf1b6a

Browse files
Byronarlosi
andauthored
Simplify pathspec generation in list_files_gix
Co-authored-by: Arlo Siemsen <arkixml@gmail.com>
1 parent ac68aa1 commit dbf1b6a

File tree

1 file changed

+12
-22
lines changed

1 file changed

+12
-22
lines changed

src/cargo/sources/path.rs

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -496,33 +496,23 @@ impl<'gctx> PathSource<'gctx> {
496496
);
497497

498498
let pkg_path = pkg.root();
499-
let mut target_prefix;
500499
let repo_relative_pkg_path = pkg_path.strip_prefix(root).unwrap_or(Path::new(""));
500+
let target_prefix = gix::path::to_unix_separators_on_windows(gix::path::into_bstr(
501+
repo_relative_pkg_path.join("target"),
502+
));
503+
let package_prefix =
504+
gix::path::to_unix_separators_on_windows(gix::path::into_bstr(repo_relative_pkg_path));
501505

502506
let pathspec = {
503-
let mut include = gix::path::to_unix_separators_on_windows(gix::path::into_bstr(
504-
repo_relative_pkg_path,
505-
));
507+
// Include the package root.
508+
let mut include = BString::from(":/");
509+
include.push_str(package_prefix.as_ref());
506510

507-
target_prefix = include.clone();
508-
target_prefix.to_mut().push_str(if include.is_empty() {
509-
"target/"
510-
} else {
511-
"/target/"
512-
});
513-
514-
// The `target` directory is never included if it is in the package root.
515-
let exclude = {
516-
let mut pattern = include.clone();
517-
pattern
518-
.to_mut()
519-
.insert_str(0, if include.is_empty() { ":!" } else { ":!/" });
520-
pattern.to_mut().push_str(b"/target/");
521-
pattern
522-
};
523-
include.to_mut().insert_str(0, ":/");
511+
// Exclude the target directory.
512+
let mut exclude = BString::from(":!");
513+
exclude.push_str(target_prefix.as_ref());
524514

525-
vec![include.into_owned(), exclude.into_owned()]
515+
vec![include, exclude]
526516
};
527517

528518
let mut files = Vec::<PathBuf>::new();

0 commit comments

Comments
 (0)