From f10e67c334f907e1b558b7680c1355a97091f072 Mon Sep 17 00:00:00 2001 From: Michal Date: Sun, 24 Jul 2022 22:00:05 +0100 Subject: [PATCH] Added optional 2nd : delimiter for specifying clone depth --- docs/COMMON_FEATURES.md | 9 +++++---- examples/workspace/mlc.toml | 2 ++ src/internal/read.rs | 24 +++++++++++++++++++++--- src/internal/structs.rs | 2 ++ src/operations/clone.rs | 22 +++++++++++++++++++++- src/operations/info.rs | 2 +- 6 files changed, 52 insertions(+), 9 deletions(-) diff --git a/docs/COMMON_FEATURES.md b/docs/COMMON_FEATURES.md index 315fb88..48a3776 100644 --- a/docs/COMMON_FEATURES.md +++ b/docs/COMMON_FEATURES.md @@ -27,10 +27,10 @@ on_gen = false [repositories] repos = [ - "foo:repo1", + "foo:repo1:2", "foo:repo2/testing", "bar:baz!", - "bar:qux/testing!", + "bar:qux/testing!:1", ] [repositories.urls] @@ -86,10 +86,10 @@ facilitate many packages without having to type each url out a million times. ```toml [repositories] repos = [ - "foo:repo1", + "foo:repo1:2", "foo:repo2/testing", "bar:baz!", - "bar:qux/testing!", + "bar:qux/testing!:1", ] [repositories.urls] @@ -108,6 +108,7 @@ The way this works is simple: I'm glad you asked! - If you want to clone a specific branch, simply use the `/` delimiter. To clone repository `foo` on branch `bar`, use `id:foo/bar`. - If you want a specific package to build first, use instances of `!` to set priority. This is explained later in the [Repository Mode](REPOSITORY_MODE.md) page +- If you want to clone the repository with a specific depth, for example, in the case of a large git repository like `nixpkgs`, you can add a 2nd `:` delimiter and the integer after that will be used as the depth That's literally it! diff --git a/examples/workspace/mlc.toml b/examples/workspace/mlc.toml index 6ddb633..7023d69 100644 --- a/examples/workspace/mlc.toml +++ b/examples/workspace/mlc.toml @@ -12,9 +12,11 @@ repos = [ "crs:malachite/development!", "aur:notop-git", "nms:appendage", + "nix:nixpkgs/nixos-unstable:ass", ] [repositories.urls] crs = "https://github.com/crystal-linux/{}" aur = "https://aur.archlinux.org/{}" nms = "https://github.com/not-my-segfault/{}" +nix = "https://github.com/nixos/{}" diff --git a/src/internal/read.rs b/src/internal/read.rs index 9a33bca..9147655 100644 --- a/src/internal/read.rs +++ b/src/internal/read.rs @@ -43,9 +43,26 @@ pub fn parse_cfg(verbose: bool) -> Config { log!(verbose, "Parsing repo: {:?}", x); // Splits the repo name and index inta a SplitRepo struct let split: Vec<&str> = x.split(':').collect(); - let split_struct = SplitRepo { - id: split[0].parse().unwrap(), - name: split[1].parse().unwrap(), + let split_struct = if split.len() > 2 { + SplitRepo { + id: split[0].parse().unwrap(), + name: split[1].parse().unwrap(), + depth: Some(split[2].parse().unwrap_or_else(|e| { + crash!( + AppExitCode::ConfigParseError, + "Depth must be an integer: {}", + e + ); + // This is unreachable, but rustc complains about it otherwise + std::process::exit(1); + })), + } + } else { + SplitRepo { + id: split[0].parse().unwrap(), + name: split[1].parse().unwrap(), + depth: None, + } }; log!(verbose, "Split repo: {:?}", split_struct); @@ -91,6 +108,7 @@ pub fn parse_cfg(verbose: bool) -> Config { name, url, branch, + depth: split_struct.depth, priority: *priority, }; log!(verbose, "Expanded repo: {:?}", repo); diff --git a/src/internal/structs.rs b/src/internal/structs.rs index 0be443c..9e18d32 100755 --- a/src/internal/structs.rs +++ b/src/internal/structs.rs @@ -68,6 +68,7 @@ pub struct Repo { pub name: String, pub url: String, pub branch: Option, + pub depth: Option, pub priority: usize, } @@ -75,6 +76,7 @@ pub struct Repo { pub struct SplitRepo { pub id: String, pub name: String, + pub depth: Option, } //// Build operation structs diff --git a/src/operations/clone.rs b/src/operations/clone.rs index 2872cec..3a48a52 100644 --- a/src/operations/clone.rs +++ b/src/operations/clone.rs @@ -47,8 +47,23 @@ pub fn clone(verbose: bool) { // Clone all diff repos for r in repo_diff { + let depth = if r.depth.is_some() { + format!("{}", r.depth.as_ref().unwrap()) + } else { + "".to_string() + }; + log!(verbose, "Depth: {:?}", r.depth); log!(verbose, "Cloning {}", r.name); - info!("Cloning ({} mode): {}", config.base.mode, r.name); + if r.depth.is_some() { + info!( + "Cloning ({} mode): {} - Depth: {}", + config.base.mode, + r.name, + r.depth.unwrap() + ); + } else { + info!("Cloning ({} mode): {}", config.base.mode, r.name); + } Command::new("git") .args(&["clone", &r.url, &r.name]) // If a branch is specified, clone that specific branch @@ -57,6 +72,11 @@ pub fn clone(verbose: bool) { } else { vec![] }) + .args(if depth.is_empty() { + vec![] + } else { + vec!["--depth", &depth] + }) .spawn() .unwrap() .wait() diff --git a/src/operations/info.rs b/src/operations/info.rs index 4350276..932c2e0 100644 --- a/src/operations/info.rs +++ b/src/operations/info.rs @@ -159,7 +159,7 @@ pub fn info(verbose: bool) { } } - // Thanks memory management + // Because spinoff requires &'static str, we need to Box these in the heap and then leak them to be able to format the spinner let symbol = Box::new(format!("{}", "✔".bold().green())); let done = Box::new(format!("{}", "Done!".bold()));