From 060ab41ed83cf61f6c189edac4be126aa41f6591 Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Sun, 11 May 2025 13:55:26 -0400 Subject: [PATCH] refactor(vendor): extract vendor filter to a function --- src/cargo/ops/vendor.rs | 45 +++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/src/cargo/ops/vendor.rs b/src/cargo/ops/vendor.rs index d56bec3b1..7ebad4030 100644 --- a/src/cargo/ops/vendor.rs +++ b/src/cargo/ops/vendor.rs @@ -368,26 +368,9 @@ fn cp_sources( let p = p.as_ref(); let relative = p.strip_prefix(&src).unwrap(); - match relative.to_str() { - // Skip git config files as they're not relevant to builds most of - // the time and if we respect them (e.g. in git) then it'll - // probably mess with the checksums when a vendor dir is checked - // into someone else's source control - Some(".gitattributes" | ".gitignore" | ".git") => continue, - - // Temporary Cargo files - Some(".cargo-ok") => continue, - - // Skip patch-style orig/rej files. Published crates on crates.io - // have `Cargo.toml.orig` which we don't want to use here and - // otherwise these are rarely used as part of the build process. - Some(filename) => { - if filename.ends_with(".orig") || filename.ends_with(".rej") { - continue; - } - } - _ => {} - }; + if !vendor_this(relative) { + continue; + } // Join pathname components individually to make sure that the joined // path uses the correct directory separators everywhere, since @@ -578,3 +561,25 @@ fn copy_and_checksum( .with_context(|| format!("failed to write to {:?}", dst_path))?; } } + +/// Filters files we want to vendor. +/// +/// `relative` is a path relative to the package root. +fn vendor_this(relative: &Path) -> bool { + match relative.to_str() { + // Skip git config files as they're not relevant to builds most of + // the time and if we respect them (e.g. in git) then it'll + // probably mess with the checksums when a vendor dir is checked + // into someone else's source control + Some(".gitattributes" | ".gitignore" | ".git") => false, + + // Temporary Cargo files + Some(".cargo-ok") => false, + + // Skip patch-style orig/rej files. Published crates on crates.io + // have `Cargo.toml.orig` which we don't want to use here and + // otherwise these are rarely used as part of the build process. + Some(p) if p.ends_with(".orig") || p.ends_with(".rej") => false, + _ => true, + } +}