Use git filter to allow tracking of shallow clone

This commit is contained in:
Wildan M 2025-12-05 07:31:36 +07:00
parent 437fd56743
commit d461f47aee
No known key found for this signature in database
GPG Key ID: 01AC53185C679C79
3 changed files with 35 additions and 28 deletions

View File

@ -1,8 +1,6 @@
[source]
git = "https://gitlab.redox-os.org/redox-os/rust.git"
branch = "redox-2025-10-03"
# due to heavy git operation, this will only clone once and will not refetch
# if you want to refetch or changing the branch, please run `make ucr.rust`
shallow_clone = true
[build]

View File

@ -146,7 +146,10 @@ pub fn fetch(recipe_dir: &Path, recipe: &Recipe, logger: &PtyOut) -> Result<Path
shallow_clone,
}) => {
//TODO: use libgit?
let shallow_clone = *shallow_clone == Some(true);
let shallow_clone = match shallow_clone {
Some(o) => *o,
None => rev.is_some(),
};
if !source_dir.is_dir() {
// Create source.tmp
let source_dir_tmp = recipe_dir.join("source.tmp");
@ -162,15 +165,16 @@ pub fn fetch(recipe_dir: &Path, recipe: &Recipe, logger: &PtyOut) -> Result<Path
command.arg("--branch").arg(branch);
}
if shallow_clone {
command.arg("--depth").arg("1").arg("--shallow-submodules");
command
.arg("--filter=tree:0")
.arg("--also-filter-submodules");
}
command.arg(&source_dir_tmp);
run_command(command, logger)?;
// Move source.tmp to source atomically
rename(&source_dir_tmp, &source_dir)?;
} else if !shallow_clone {
// Don't let this code reset the origin for the cookbook repo
} else {
let source_git_dir = source_dir.join(".git");
if !source_git_dir.is_dir() {
return Err(format!(
@ -205,7 +209,14 @@ pub fn fetch(recipe_dir: &Path, recipe: &Recipe, logger: &PtyOut) -> Result<Path
command.arg("-C").arg(&source_dir);
command.arg("checkout").arg(rev);
run_command(command, logger)?;
} else if !shallow_clone && !is_redox() {
} else if !is_redox() {
//If patches exists, we have to drop it
if patches.len() > 0 {
let mut command = Command::new("git");
command.arg("-C").arg(&source_dir);
command.arg("reset").arg("--hard");
run_command(command, logger)?;
}
//TODO: complicated stuff to check and reset branch to origin
//TODO: redox can't undestand this (got exit status 1)
let mut command = Command::new("bash");
@ -225,23 +236,25 @@ pub fn fetch(recipe_dir: &Path, recipe: &Recipe, logger: &PtyOut) -> Result<Path
run_command(command, logger)?;
}
if !shallow_clone {
// Sync submodules URL
let mut command = Command::new("git");
command.arg("-C").arg(&source_dir);
command.arg("submodule").arg("sync").arg("--recursive");
run_command(command, logger)?;
// Sync submodules URL
let mut command = Command::new("git");
command.arg("-C").arg(&source_dir);
command.arg("submodule").arg("sync").arg("--recursive");
// Update submodules
let mut command = Command::new("git");
command.arg("-C").arg(&source_dir);
command
.arg("submodule")
.arg("update")
.arg("--init")
.arg("--recursive");
run_command(command, logger)?;
run_command(command, logger)?;
// Update submodules
let mut command = Command::new("git");
command.arg("-C").arg(&source_dir);
command
.arg("submodule")
.arg("update")
.arg("--init")
.arg("--recursive");
if shallow_clone {
command.arg("--filter=tree:0");
}
run_command(command, logger)?;
fetch_apply_patches(recipe_dir, patches, script, &source_dir, logger)?;
}

View File

@ -43,8 +43,7 @@ pub enum SourceRecipe {
/// The optional revision of the git repository to use for builds. Please specify for
/// reproducible builds
rev: Option<String>,
/// The optional config to run as shallow fetch. Only use this for heavy git like "rust"
/// This will disable recipe autofetching because of its cost on git server
/// The optional config to clone with treeless clone. Default is true if "rev" added
shallow_clone: Option<bool>,
/// A list of patch files to apply to the source
#[serde(default)]
@ -449,12 +448,9 @@ mod tests {
Recipe {
source: Some(SourceRecipe::Git {
git: "https://gitlab.redox-os.org/redox-os/acid.git".to_string(),
upstream: None,
branch: Some("master".to_string()),
rev: Some("06344744d3d55a5ac9a62a6059cb363d40699bbc".to_string()),
patches: Vec::new(),
script: None,
shallow_clone: None,
..Default::default()
}),
build: BuildRecipe::new(BuildKind::Cargo {
package_path: None,