Added optional 2nd : delimiter for specifying clone depth

main
Michal 2 years ago
parent 360c669025
commit f10e67c334
No known key found for this signature in database
GPG Key ID: A6A1A4DCB22279B9

@ -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!

@ -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/{}"

@ -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);

@ -68,6 +68,7 @@ pub struct Repo {
pub name: String,
pub url: String,
pub branch: Option<String>,
pub depth: Option<usize>,
pub priority: usize,
}
@ -75,6 +76,7 @@ pub struct Repo {
pub struct SplitRepo {
pub id: String,
pub name: String,
pub depth: Option<usize>,
}
//// Build operation structs

@ -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()

@ -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()));

Loading…
Cancel
Save