Implemented second delimiter as rev spec in repo mode

main
Michal 2 years ago
parent 8f046dc2cb
commit d3730fdff5

@ -16,14 +16,9 @@ Without further ado, let's take a look at this example config file.
mode = "workspace" mode = "workspace"
smart_pull = true smart_pull = true
[mode.repository] [mode.workspace]
name = "" git_info = true
build_on_update = false colorblind = true
[mode.repository.signing]
enabled = false
key = ""
on_gen = false
[repositories] [repositories]
repos = [ repos = [
@ -93,8 +88,8 @@ repos = [
] ]
[repositories.urls] [repositories.urls]
foo = "https://example.org/%repo%.git" foo = "https://example.org/{}.git"
bar = "https://example.org/other/%repo%.git" bar = "https://example.org/other/{}.git"
``` ```
The way this works is simple: The way this works is simple:
@ -108,7 +103,10 @@ The way this works is simple:
I'm glad you asked! 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 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 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
The last `:` delimiter is entirely optional, and behaves differently depending on the mode:
- In Repository mode, it defines the desired commit hash/rev/tag to checkout on repository clone
- In Workspace mode, it defines the desired depth to clone the repository, useful with large git repositories, such as `nixpkgs`.
That's literally it! That's literally it!

@ -13,10 +13,12 @@ on_gen = true
[repositories] [repositories]
repos = [ repos = [
"crs:malachite/development", "crs:malachite/development:0a5bdc9",
"mic:apod:v.1.1.2",
"pkg:pfetch!", "pkg:pfetch!",
] ]
[repositories.urls] [repositories.urls]
crs = "https://github.com/crystal-linux/{}" crs = "https://github.com/crystal-linux/{}"
pkg = "https://github.com/crystal-linux/pkgbuild.{}" pkg = "https://github.com/crystal-linux/pkgbuild.{}"
mic = "https://git.tar.black/michal/{}"

@ -11,12 +11,10 @@ repos = [
"crs:amethyst", "crs:amethyst",
"crs:malachite/development!", "crs:malachite/development!",
"aur:notop-git", "aur:notop-git",
"nms:appendage", "nix:nixpkgs/nixos-unstable:1",
"nix:nixpkgs/nixos-unstable:ass",
] ]
[repositories.urls] [repositories.urls]
crs = "https://github.com/crystal-linux/{}" crs = "https://github.com/crystal-linux/{}"
aur = "https://aur.archlinux.org/{}" aur = "https://aur.archlinux.org/{}"
nms = "https://github.com/not-my-segfault/{}"
nix = "https://github.com/nixos/{}" nix = "https://github.com/nixos/{}"

@ -47,21 +47,13 @@ pub fn parse_cfg(verbose: bool) -> Config {
SplitRepo { SplitRepo {
id: split[0].parse().unwrap(), id: split[0].parse().unwrap(),
name: split[1].parse().unwrap(), name: split[1].parse().unwrap(),
depth: Some(split[2].parse().unwrap_or_else(|e| { extra: Some(split[2].parse().unwrap()),
crash!(
AppExitCode::ConfigParseError,
"Depth must be an integer: {}",
e
);
// This is unreachable, but rustc complains about it otherwise
std::process::exit(1);
})),
} }
} else { } else {
SplitRepo { SplitRepo {
id: split[0].parse().unwrap(), id: split[0].parse().unwrap(),
name: split[1].parse().unwrap(), name: split[1].parse().unwrap(),
depth: None, extra: None,
} }
}; };
log!(verbose, "Split repo: {:?}", split_struct); log!(verbose, "Split repo: {:?}", split_struct);
@ -108,7 +100,7 @@ pub fn parse_cfg(verbose: bool) -> Config {
name, name,
url, url,
branch, branch,
depth: split_struct.depth, extra: split_struct.extra,
priority: *priority, priority: *priority,
}; };
log!(verbose, "Expanded repo: {:?}", repo); log!(verbose, "Expanded repo: {:?}", repo);

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

@ -1,3 +1,4 @@
use std::env;
use std::process::Command; use std::process::Command;
use crate::{info, log}; use crate::{info, log};
@ -47,40 +48,100 @@ pub fn clone(verbose: bool) {
// Clone all diff repos // Clone all diff repos
for r in repo_diff { for r in repo_diff {
let depth = if r.depth.is_some() { log!(verbose, "Depth: {:?}", r.extra);
format!("{}", r.depth.as_ref().unwrap())
} else {
"".to_string()
};
log!(verbose, "Depth: {:?}", r.depth);
log!(verbose, "Cloning {}", r.name); log!(verbose, "Cloning {}", r.name);
if r.depth.is_some() { if r.extra.is_some() && config.base.mode == "workspace" {
info!( info!(
"Cloning ({} mode): {} - Depth: {}", "Cloning ({} mode): {} at depth: {}",
config.base.mode, config.base.mode,
r.name, r.name,
r.depth.unwrap() r.extra.as_ref().unwrap()
);
} else if r.extra.is_some() && config.base.mode == "repository" {
info!(
"Cloning ({} mode): {} at {}",
config.base.mode,
r.name,
r.extra.as_ref().unwrap()
); );
} else { } else {
info!("Cloning ({} mode): {}", config.base.mode, r.name); info!("Cloning ({} mode): {}", config.base.mode, r.name);
} }
Command::new("git")
.args(&["clone", &r.url, &r.name]) if r.extra.is_some() && config.base.mode == "workspace" {
// If a branch is specified, clone that specific branch // Clone with specified extra depth
.args(if r.branch.is_some() { Command::new("git")
vec!["-b", r.branch.as_ref().unwrap()] .args(&["clone", &r.url, &r.name])
} else { // If a branch is specified, clone that specific branch
vec![] .args(if r.branch.is_some() {
}) vec!["-b", r.branch.as_ref().unwrap()]
.args(if depth.is_empty() { } else {
vec![] vec![]
})
.args(if r.extra.is_some() {
vec!["--depth", r.extra.as_ref().unwrap()]
} else {
vec![]
})
.spawn()
.unwrap()
.wait()
.unwrap();
} else if config.base.mode == "repository" {
// Clone and checkout specified hash
// Create an empty directory with repo.name and enter it
let root_dir = env::current_dir().unwrap();
// Git clone the repo with the `-n` flag to not immediately checkout the files
Command::new("git")
.args(&["clone", &r.url, &r.name, "-n"])
.args(if r.branch.is_some() {
vec!["-b", r.branch.as_ref().unwrap()]
} else {
vec![]
})
.spawn()
.unwrap()
.wait()
.unwrap();
std::env::set_current_dir(&r.name).unwrap();
log!(verbose, "Entered directory: {}", r.name);
// Git checkout the PKGBUILD from the hash
if r.extra.is_some() {
Command::new("git")
.args(&["checkout", r.extra.as_ref().unwrap(), "PKGBUILD"])
.spawn()
.unwrap()
.wait()
.unwrap();
} else { } else {
vec!["--depth", &depth] Command::new("git")
}) .args(&["checkout", "HEAD", "PKGBUILD"])
.spawn() .spawn()
.unwrap() .unwrap()
.wait() .wait()
.unwrap(); .unwrap();
}
// Return to the root directory
std::env::set_current_dir(root_dir).unwrap();
log!(verbose, "Returned to root directory");
} else {
// Clone normally
Command::new("git")
.args(&["clone", &r.url, &r.name])
.args(if r.branch.is_some() {
vec!["-b", r.branch.as_ref().unwrap()]
} else {
vec![]
})
.spawn()
.unwrap()
.wait()
.unwrap();
}
} }
} }
} }

Loading…
Cancel
Save