diff options
| author | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2026-11-05 22:59:19 +0100 |
|---|---|---|
| committer | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2026-11-05 23:00:58 +0100 |
| commit | b40bac62a475e2145deb77e0d70c5b5582f62305 (patch) | |
| tree | 4c1d71db9214a4e858b3dccfc654ebd1a808f653 /pkgs/by-name/ro/rollup/src/main.rs | |
| parent | modules/nix: Disable `auto-optimise-store` (diff) | |
| download | nixos-config-b40bac62a475e2145deb77e0d70c5b5582f62305.zip | |
It's both easier, and the filterdiff command actually removed renames
with similarity 100%. This patch also greatly reduces the parsing code.
Diffstat (limited to 'pkgs/by-name/ro/rollup/src/main.rs')
| -rw-r--r-- | pkgs/by-name/ro/rollup/src/main.rs | 58 |
1 files changed, 34 insertions, 24 deletions
diff --git a/pkgs/by-name/ro/rollup/src/main.rs b/pkgs/by-name/ro/rollup/src/main.rs index 4083259f..71a54049 100644 --- a/pkgs/by-name/ro/rollup/src/main.rs +++ b/pkgs/by-name/ro/rollup/src/main.rs @@ -27,7 +27,7 @@ struct Cli { } macro_rules! git { - (@base for $finalizer:ident in $to:expr; $($args:literal),*) => { + (@_base for $finalizer:ident in $to:expr; $($args:expr),*) => { Command::new("git") .args([ "-C", @@ -38,34 +38,38 @@ macro_rules! git { .stdout(Stdio::piped()) .stderr(Stdio::piped()) .$finalizer() - .context(concat!("Failed to run `git", $($args),*, "`"))? + .with_context(|| format!("Failed to run {}", git!(@_fmt_cmd $($args),*)))? }; - (@handle_status $status:expr; $($args:literal),*) => {{ - if !$status.success() { - bail!(concat!("`git", $($args),*, "` failed!")) + (@_handle_status $output:expr; $($args:expr),*) => {{ + if !$output.status.success() { + bail!("{} failed!", git!(@_fmt_cmd $($args),*)) } + if !$output.stderr.is_empty() { + let stderr = String::from_utf8($output.stderr).expect("git should always produce utf8"); + bail!("{} returned some errors:\n{stderr}", git!(@_fmt_cmd $($args),*)); + } + }}; + (@_fmt_cmd $($args:expr),*) => {{ + let all = ["git", $($args),*].join(" "); + format!("`{}`", all) }}; - (@get_output in $to:expr; $($args:literal),*) => {{ - let output = git!(@base for output in $to; $($args),*); - git!(@handle_status output.status; $($args),*); + (in $to:expr; $($args:expr),*) => {{ + let output = git!(@_base for output in $to; $($args),*); + git!(@_handle_status output; $($args),*); let stdout = String::from_utf8(output.stdout).expect("git should always produce utf8"); let stderr = String::from_utf8(output.stderr).expect("git should always produce utf8"); (stdout, stderr) }}; - (in $to:expr; $($args:literal),*) => {{ - let status = git!(@base for status in $to; $($args),*); - git!(@handle_status status; $($args),*); - }}; - (@set_stdin_to $stdin:expr; in $to:expr; $($args:literal),*) => {{ - let mut child = git!(@base for spawn in $to; $($args),*); + (@set_stdin_to $stdin:expr; in $to:expr; $($args:expr),*) => {{ + let mut child = git!(@_base for spawn in $to; $($args),*); let mut stdin = child.stdin.take().expect("is piped"); write!(stdin, "{}", $stdin)?; drop(stdin); let output = child.wait_with_output() - .context(concat!("Failed to run `git", $($args),*, "`"))?; - git!(@handle_status output.status; $($args),*); + .with_context(|| format!("Failed to run `{}`", git!(@_fmt_cmd $($args),*)))?; + git!(@_handle_status output; $($args),*); let stdout = String::from_utf8(output.stdout).expect("git should always produce utf8"); let stderr = String::from_utf8(output.stderr).expect("git should always produce utf8"); @@ -85,7 +89,7 @@ fn main() -> Result<()> { eprintln!("Successfully parsed all {} patch files.", patches.len()); { - let (stdout, _) = git!(@get_output in args.to; "status", "--porcelain"); + let (stdout, _) = git!(in args.to; "status", "--porcelain"); if !stdout.is_empty() { bail!( "`--to` (`{}`) workspace is dirty, refusing to continue.", @@ -109,10 +113,12 @@ fn main() -> Result<()> { bail!("A file was added, that already existed. This should be impossible.") } final_diffs.push(file_diff.to_owned()); + // eprintln!(" > Keeping add of `{}`", path.display()); } FileDiff::Remove { path, .. } => { if args.to.join(path).exists() { final_diffs.push(file_diff.to_owned()); + // eprintln!(" > Keeping remove of `{}`", path.display()); } else { eprintln!( " > Dropping remove of `{}`, as the file does not exist in the rollup target.", @@ -120,7 +126,8 @@ fn main() -> Result<()> { ); } } - FileDiff::Rename { from, to, .. } => { + FileDiff::RenameNoChange { from, to, .. } + | FileDiff::RenameWithChange { from, to, .. } => { if args.to.join(from).exists() { if args.to.join(to).exists() { bail!( @@ -130,6 +137,7 @@ fn main() -> Result<()> { ) } final_diffs.push(file_diff.to_owned()); + // eprintln!(" > Keeping rename of `{}` to `{}`", from.display(), to.display()); } else { eprintln!( " > Dropping rename from `{}` to `{}`, as the from file does not exist in the rollup target.", @@ -151,17 +159,19 @@ fn main() -> Result<()> { } } + if final_diffs.is_empty() { + eprintln!(" -> Patch is empty after dropping, skipping it.",); + continue; + } + let filtered_patch = Patch { files: final_diffs, - commit_message: patch.commit_message.clone(), + ..patch.to_owned() }; - git!(@set_stdin_to filtered_patch; in args.to; "apply", "-"); + git!(@set_stdin_to filtered_patch; in args.to; "apply", "-", "--whitespace=nowarn"); git!(in args.to; "add", "."); - let (_, stderr) = git!(@set_stdin_to filtered_patch.commit_message; in args.to; "commit", "--file=-", "--quiet"); - if !stderr.is_empty() { - bail!("git commit returned some errors: \n{stderr}"); - } + git!(@set_stdin_to filtered_patch.commit_message; in args.to; "commit", "--file=-", format!("--date={}", filtered_patch.date).as_str(), "--quiet"); } Ok(()) |
