Skip to content

Commit

Permalink
Code formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
JanLikar committed Aug 25, 2024
1 parent fd003d0 commit a5325ac
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 13 deletions.
2 changes: 1 addition & 1 deletion cargo-clone-core/src/cloner_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
use std::{env, path::PathBuf};

use anyhow::Context;
use cargo::CargoResult;
use cargo::util::context::GlobalContext;
use cargo::CargoResult;

use crate::{Cloner, ClonerSource};

Expand Down
28 changes: 18 additions & 10 deletions cargo-clone-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,18 @@ use anyhow::{bail, Context};

use cargo::core::dependency::Dependency;
use cargo::core::Package;
use cargo::sources::registry::IndexSummary;
use cargo::sources::source::QueryKind;
use cargo::sources::source::Source;
use cargo::sources::{PathSource, SourceConfigMap};
use cargo::sources::registry::IndexSummary;
use cargo::util::cache_lock::CacheLockMode;
use cargo::util::context::GlobalContext;
use semver::VersionReq;

use walkdir::WalkDir;

// Re-export cargo types.
pub use cargo::{
core::SourceId,
util::CargoResult,
};
pub use cargo::{core::SourceId, util::CargoResult};

/// Rust crate.
#[derive(PartialEq, Eq, Debug)]
Expand Down Expand Up @@ -80,7 +77,9 @@ impl Cloner {
/// Clone the specified crate from registry or git repository.
/// The crate is cloned in the directory specified by the [`ClonerBuilder`].
pub fn clone_in_dir(&self, crate_: &Crate) -> CargoResult<()> {
let _lock = self.context.acquire_package_cache_lock(CacheLockMode::DownloadExclusive)?;
let _lock = self
.context
.acquire_package_cache_lock(CacheLockMode::DownloadExclusive)?;

let mut src = get_source(&self.srcid, &self.context)?;

Expand All @@ -90,7 +89,9 @@ impl Cloner {
/// Clone the specified crates from registry or git repository.
/// Each crate is cloned in a subdirectory named as the crate name.
pub fn clone(&self, crates: &[Crate]) -> CargoResult<()> {
let _lock = self.context.acquire_package_cache_lock(CacheLockMode::DownloadExclusive)?;
let _lock = self
.context
.acquire_package_cache_lock(CacheLockMode::DownloadExclusive)?;

let mut src = get_source(&self.srcid, &self.context)?;

Expand Down Expand Up @@ -154,7 +155,10 @@ impl Cloner {
}
}

fn get_source<'a>(srcid: &SourceId, context: &'a GlobalContext) -> CargoResult<Box<dyn Source + 'a>> {
fn get_source<'a>(
srcid: &SourceId,
context: &'a GlobalContext,
) -> CargoResult<Box<dyn Source + 'a>> {
let mut source = if srcid.is_path() {
let path = srcid.url().to_file_path().expect("path must be valid");
Box::new(PathSource::new(&path, *srcid, context))
Expand Down Expand Up @@ -188,8 +192,12 @@ where
}
}

let latest = summaries.iter()
.filter_map(|idxs| match idxs { IndexSummary::Candidate(s) => Some(s), _ => None})
let latest = summaries
.iter()
.filter_map(|idxs| match idxs {
IndexSummary::Candidate(s) => Some(s),
_ => None,
})
.max_by_key(|s| s.version());

match latest {
Expand Down
2 changes: 1 addition & 1 deletion cargo-clone-core/src/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use cargo::{core::SourceId, util::IntoUrl, CargoResult};
use cargo::util::GlobalContext;
use cargo::{core::SourceId, util::IntoUrl, CargoResult};
use url::Url;

/// Where to clone the crate from.
Expand Down
4 changes: 3 additions & 1 deletion cargo-clone/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ pub fn execute(opts: &CloneOpt) -> Result<()> {
.collect::<Result<Vec<cargo_clone_core::Crate>>>()?;

let context = cargo_context(opts)?;
let mut cloner_builder = ClonerBuilder::new().with_source(source).with_context(context);
let mut cloner_builder = ClonerBuilder::new()
.with_source(source)
.with_context(context);
let directory = opts.directory.as_deref();
if let Some(directory) = directory {
cloner_builder = cloner_builder.with_directory(directory);
Expand Down

0 comments on commit a5325ac

Please sign in to comment.