Skip to content

Commit

Permalink
Fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
phsauter committed Aug 20, 2024
1 parent 56efab9 commit a78097e
Showing 1 changed file with 31 additions and 27 deletions.
58 changes: 31 additions & 27 deletions src/cmd/vendor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ use crate::error::*;
use crate::git::Git;
use crate::sess::{DependencySource, Session};
use glob::Pattern;
use std::collections::HashSet;
use std::path::Path;
use std::path::PathBuf;
use std::collections::HashSet;
use tempfile::TempDir;

/// A patch linkage
Expand Down Expand Up @@ -152,17 +152,17 @@ pub fn run(sess: &Session, matches: &ArgMatches) -> Result<()> {
// 1. file links over directory links eg 'a/file -> c/file' before 'b/ -> c/'
// 2. subdirs (deeper paths) first eg 'a/aa/ -> c/aa' before 'a/ab -> c/'
let mut sorted_links: Vec<_> = patch_links.clone();
sorted_links.sort_by(|a,b| {
sorted_links.sort_by(|a, b| {
let a_is_file = a.to_prefix.is_file();
let b_is_file = b.to_prefix.is_file();

if a_is_file != b_is_file {
return b_is_file.cmp(&a_is_file);
}

let a_depth = a.to_prefix.iter().count();
let b_depth = b.to_prefix.iter().count();

b_depth.cmp(&a_depth)
});

Expand All @@ -175,17 +175,20 @@ pub fn run(sess: &Session, matches: &ArgMatches) -> Result<()> {
.filter(|path| path.starts_with(&patch_link.to_prefix)) // subdir?
.cloned()
.collect();
seen_paths.insert(patch_link.to_prefix.clone());

seen_paths.insert(patch_link.to_prefix.clone());
}
let git = Git::new(tmp_path, &sess.config.git);

match matches.subcommand() {
Some(("diff", matches)) => {
// Apply patches
sorted_links.clone().into_iter().try_for_each(|patch_link| {
apply_patches(&rt, git, vendor_package.name.clone(), patch_link).map(|_| ())
})?;
sorted_links
.clone()
.into_iter()
.try_for_each(|patch_link| {
apply_patches(&rt, git, vendor_package.name.clone(), patch_link).map(|_| ())
})?;

// Stage applied patches to clean working tree
rt.block_on(git.add_all())?;
Expand Down Expand Up @@ -399,12 +402,13 @@ pub fn apply_patches(
})
.and_then(|_| {
git.spawn_with(|c| {
let is_file = patch_link.from_prefix
let is_file = patch_link
.from_prefix
.clone()
.prefix_paths(git.path)
.unwrap()
.is_file();

let current_patch_target = if is_file {
patch_link.from_prefix.parent().unwrap().to_str().unwrap()
} else {
Expand Down Expand Up @@ -572,7 +576,6 @@ pub fn gen_format_patch(
target_dir: impl AsRef<Path>,
message: Option<&String>,
) -> Result<()> {

// Local git
let to_path = patch_link
.to_prefix
Expand Down Expand Up @@ -606,21 +609,28 @@ pub fn gen_format_patch(
// If the patch link maps a file, we operate in the file's parent directory
// Therefore, only get the diff for that file.
let include_pathspec = if !to_path.is_dir() {
patch_link.to_prefix.file_name().unwrap().to_str().unwrap().to_string()
patch_link
.to_prefix
.file_name()
.unwrap()
.to_str()
.unwrap()
.to_string()
} else {
".".to_string()
};

// Build the exclude pathspec to diff only the applicable files
let exclude_pathspecs: Vec<String> = patch_link.exclude.iter().map(|path| {
format!(":!{}", path.to_str().unwrap())
})
.collect();

let exclude_pathspecs: Vec<String> = patch_link
.exclude
.iter()
.map(|path| format!(":!{}", path.to_str().unwrap()))
.collect();

let mut diff_args = vec![
"diff".to_string(),
"--relative".to_string(),
"--cached".to_string()
"--cached".to_string(),
];

diff_args.push(include_pathspec);
Expand All @@ -630,13 +640,7 @@ pub fn gen_format_patch(

// Get staged changes in dependency
let get_diff_cached = rt
.block_on(async {
git_parent
.spawn_with(|c| {
c.args(&diff_args)
})
.await
})
.block_on(async { git_parent.spawn_with(|c| c.args(&diff_args)).await })
.map_err(|cause| Error::chain("Failed to generate diff", cause))?;

if !get_diff_cached.is_empty() {
Expand Down

0 comments on commit a78097e

Please sign in to comment.