summaryrefslogtreecommitdiffstats
path: root/pkgs
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs')
-rw-r--r--pkgs/by-name/ro/rollup/src/main.rs58
1 files changed, 53 insertions, 5 deletions
diff --git a/pkgs/by-name/ro/rollup/src/main.rs b/pkgs/by-name/ro/rollup/src/main.rs
index cd205586..12cf7dd9 100644
--- a/pkgs/by-name/ro/rollup/src/main.rs
+++ b/pkgs/by-name/ro/rollup/src/main.rs
@@ -1,5 +1,6 @@
use std::{
env::current_dir,
+ fs,
io::Write,
path::PathBuf,
process::{Command, Stdio},
@@ -38,9 +39,27 @@ enum Cmd {
/// Create the patch files (based on the given tag)
Create {
+ /// Which tag to use to mark the already applied patches.
#[arg(default_value = "CONFIG_APPLIED")]
tag: String,
},
+
+ /// First create the patches, and then automatically apply them.
+ CreateApply {
+ /// Which tag to use to mark the already applied patches.
+ #[arg(default_value = "CONFIG_APPLIED")]
+ tag: String,
+
+ /// Which repository to use as a target for the rollup
+ ///
+ /// The repository needs to be clean.
+ #[arg(short, long)]
+ to: PathBuf,
+
+ /// Show debug information related to the parsing of patch files.
+ #[arg(short, long)]
+ debug_parse: bool,
+ },
}
macro_rules! git {
@@ -103,14 +122,43 @@ fn main() -> Result<()> {
patch_files,
to,
debug_parse,
- } => apply_patches(patch_files, to, debug_parse)?,
- Cmd::Create { tag } => create_patches(tag)?,
+ } => {
+ check_to(&to)?;
+ apply_patches(patch_files, to, debug_parse)?
+ }
+ Cmd::Create { tag } => {
+ create_patches(tag)?;
+ }
+ Cmd::CreateApply {
+ tag,
+ to,
+ debug_parse,
+ } => {
+ check_to(&to)?;
+
+ let Some(patches_directory) = create_patches(tag)? else {
+ return Ok(());
+ };
+ let patch_files = {
+ let iter = fs::read_dir(patches_directory)?;
+ let mut output = vec![];
+ for entry in iter {
+ let entry = entry?;
+ if !entry.file_type()?.is_file() {
+ unreachable!("Should not be able to get non-files in patches directory");
+ }
+ output.push(entry.path());
+ }
+ output
+ };
+ apply_patches(patch_files, to, debug_parse)?;
+ }
}
Ok(())
}
-fn create_patches(tag: String) -> Result<()> {
+fn create_patches(tag: String) -> Result<Option<PathBuf>> {
let current_dir = current_dir()?;
let (stdout, _) = git!(in current_dir; "tag", "--contains", "HEAD", tag.as_str());
@@ -119,7 +167,7 @@ fn create_patches(tag: String) -> Result<()> {
"There are no tags to generate. Tag {} already points to HEAD.",
tag
);
- return Ok(());
+ return Ok(None);
}
let mktemp = Command::new("mktemp")
@@ -138,7 +186,7 @@ fn create_patches(tag: String) -> Result<()> {
println!("Patches have been generated here: `{}`", tempdir.display());
- Ok(())
+ Ok(Some(tempdir))
}
fn apply_patches(patch_files: Vec<PathBuf>, to: PathBuf, debug_parse: bool) -> Result<()> {