diff options
Diffstat (limited to '')
| -rw-r--r-- | pkgs/by-name/ro/rollup/Cargo.lock | 132 | ||||
| -rw-r--r-- | pkgs/by-name/ro/rollup/Cargo.toml | 4 | ||||
| -rw-r--r-- | pkgs/by-name/ro/rollup/src/config.rs | 110 | ||||
| -rw-r--r-- | pkgs/by-name/ro/rollup/src/main.rs | 293 | ||||
| -rw-r--r-- | pkgs/by-name/ro/rollup/src/parse.rs | 68 |
5 files changed, 529 insertions, 78 deletions
diff --git a/pkgs/by-name/ro/rollup/Cargo.lock b/pkgs/by-name/ro/rollup/Cargo.lock index 4184cc11..80336c57 100644 --- a/pkgs/by-name/ro/rollup/Cargo.lock +++ b/pkgs/by-name/ro/rollup/Cargo.lock @@ -54,15 +54,15 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.104" +version = "1.0.105" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "330a5ed07fa54e4702c9d6c4174f74427fc0ef6e214bbd677ae50a5099946470" +checksum = "2cb931c189b85683d69a5cfad41d4d418671e1ac413dd209f3f2fc31e3cfd902" [[package]] name = "clap" -version = "4.6.7" +version = "4.6.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa8876b300ab35ba921adea3dfd70157a46249b33f95c9084ae5709785478946" +checksum = "50066ca966813ca8957ee15361752f19424a8ff620dbe9c8993d9f99d99b04b3" dependencies = [ "clap_builder", "clap_derive", @@ -70,9 +70,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.6.7" +version = "4.6.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec0797fb7aeb1406c84efac526901f7ec3ead2124f946b494e72879d4b54704d" +checksum = "a0ed97c96ef4efb3cc84e09fa388df4463e7cc3224ec38d7b1d9e45749333590" dependencies = [ "anstream", "anstyle", @@ -82,9 +82,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.6.7" +version = "4.6.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9c751b79415d4e559e3d1fcf128e09e720eb673a06d26cf6f392d37d75b66e0" +checksum = "b4c174f11f949b9ca8c60580925e282b9cbd5454750e506f08648b2038080cd7" dependencies = [ "heck", "proc-macro2", @@ -94,9 +94,9 @@ dependencies = [ [[package]] name = "clap_lex" -version = "1.1.1" +version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c133bc6a41be0d194c306b5506d15e6feeea7b1d6604bd3f8310dfb2ca96486" +checksum = "e0921b3876b3a1df8a1c9f912e7f94342458022c2e84288015893d83c4d62a79" [[package]] name = "colorchoice" @@ -111,12 +111,34 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8" [[package]] +name = "equivalent" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00d174d5400e5e8fd687ad1049e2f578285fa914201b1af7e8b112a4546bd826" + +[[package]] +name = "hashbrown" +version = "0.17.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "735eaa21a6a5ffb2e84362faaeb90c05ba8e19797ca30428478cb6ea3a4921bc" + +[[package]] name = "heck" version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" [[package]] +name = "indexmap" +version = "2.14.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc4e190f5d26ca7051642629da2c52fc03bde85a03197c99408dcd291734c855" +dependencies = [ + "equivalent", + "hashbrown", +] + +[[package]] name = "is_terminal_polyfill" version = "1.70.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -163,6 +185,47 @@ dependencies = [ "anyhow", "clap", "pretty_assertions", + "serde", + "toml", +] + +[[package]] +name = "serde" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba" +dependencies = [ + "serde_core", + "serde_derive", +] + +[[package]] +name = "serde_core" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_spanned" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c187e0a369471c550af028cba56d4f4fa2a489ad28151ae95a4d340a2a8b782" +dependencies = [ + "serde_core", ] [[package]] @@ -173,9 +236,9 @@ checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" [[package]] name = "syn" -version = "3.0.9" +version = "3.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d78c8dee4c7bf0e14673097256fed6142ce9d3b85a408189d07482442145823b" +checksum = "4ae9ccbea3a7b0b09443036490c8f34a8b1b760fd345e5c0dae0aac718faea79" dependencies = [ "proc-macro2", "quote", @@ -183,6 +246,45 @@ dependencies = [ ] [[package]] +name = "toml" +version = "1.2.3+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b1f26e9485c1fa43ee89fe76e9f3fb9e2e52bb227f8594b4d687496b83d073" +dependencies = [ + "indexmap", + "serde_core", + "serde_spanned", + "toml_datetime", + "toml_parser", + "toml_writer", + "winnow", +] + +[[package]] +name = "toml_datetime" +version = "1.1.3+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "173f25c883cd2176a2d8212155638c0a60d484a9d84546d270866f40f56b6e49" +dependencies = [ + "serde_core", +] + +[[package]] +name = "toml_parser" +version = "1.1.7+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bb28d6e049a9766c3bd91a8326e6179f5b132dec87906bb97018ef7a2f3431a" +dependencies = [ + "winnow", +] + +[[package]] +name = "toml_writer" +version = "1.2.0+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "009dbb7700f11c55ef83aebbe4c0e9cf1f1ac0844bd8d6f00dc38f302026e13a" + +[[package]] name = "unicode-ident" version = "1.0.27" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -210,6 +312,12 @@ dependencies = [ ] [[package]] +name = "winnow" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c3b93199df0ab874cdf0c6a94f0a0dc3423fe41f1cafb62b8bd7b1deb277aef" + +[[package]] name = "yansi" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" diff --git a/pkgs/by-name/ro/rollup/Cargo.toml b/pkgs/by-name/ro/rollup/Cargo.toml index 51fecd59..7dec4f31 100644 --- a/pkgs/by-name/ro/rollup/Cargo.toml +++ b/pkgs/by-name/ro/rollup/Cargo.toml @@ -17,5 +17,7 @@ homepage = "" [dependencies] clap = { version = "4.6", features = ["derive"] } -anyhow = "1.0.104" +anyhow = "1.0.105" pretty_assertions = "1.4.1" +serde = { version = "1.0.229", features = ["derive"] } +toml = "1.2.3" diff --git a/pkgs/by-name/ro/rollup/src/config.rs b/pkgs/by-name/ro/rollup/src/config.rs new file mode 100644 index 00000000..ead54da0 --- /dev/null +++ b/pkgs/by-name/ro/rollup/src/config.rs @@ -0,0 +1,110 @@ +use std::{ + collections::HashMap, + ffi::OsStr, + fs::{self}, + path::PathBuf, +}; + +use anyhow::{Context, Result, bail}; +use serde::{Deserialize, Serialize}; + +pub(crate) const MAIN_CONFIG_NAME: &str = "rollup.toml"; +pub(crate) const DROP_IN_NAME: &str = ".rollup.owner"; + +#[derive(Serialize, Deserialize, Debug)] +pub(crate) struct MainConfig { + pub(crate) owners: Vec<Owner>, + pub(crate) drop_ins: HashMap<PathBuf, DropInConfig>, +} + +impl MainConfig { + pub(crate) fn get_owner(&self, owner: &str) -> Result<&Owner> { + if let Some(own) = self.owners.iter().find(|o| o.name == owner) { + Ok(own) + } else { + bail!("Failed to find owner with name: `{}`", owner) + } + } +} + +#[derive(Serialize, Deserialize, Debug)] +pub(crate) struct Owner { + pub(crate) name: String, + pub(crate) applies_to: PathBuf, + pub(crate) last_applied_tag: String, +} + +#[derive(Serialize, Deserialize, Debug)] +pub(crate) struct DropInConfig { + pub(crate) owners: Vec<String>, +} + +pub(crate) fn load(root: &PathBuf) -> Result<MainConfig> { + let mut main: MainConfig = { + let path = root.join(MAIN_CONFIG_NAME); + let content = fs::read_to_string(path)?; + toml::from_str(&content).context("Failed to load main config")? + }; + + let drop_ins = collect_drop_ins(root)?; + + for (path, config) in drop_ins { + assert!(main.drop_ins.insert(path, config).is_none()); + } + + Ok(main) +} + +fn collect_drop_ins(path: &PathBuf) -> Result<Vec<(PathBuf, DropInConfig)>> { + let mut output = vec![]; + for entry in fs::read_dir(path)? { + let entry = entry?; + let ft = entry.file_type()?; + + if ft.is_dir() { + output.extend(collect_drop_ins(&entry.path())?); + } else if ft.is_file() && entry.file_name() == OsStr::new(DROP_IN_NAME) { + let drop_in: toml::Value = { + let content = fs::read_to_string(entry.path())?; + toml::from_str(&content).with_context(|| { + format!("Failed to load drop-in: {}", entry.path().display()) + })? + }; + + let drop_in_config = DropInConfig { + owners: { + let Some(owner) = drop_in.get("owner") else { + bail!("Drop in config without `owner` field") + }; + + if owner.is_str() { + vec![owner.as_str().expect("We checked").to_owned()] + } else if owner.is_array() { + let mut output = vec![]; + for v in owner.as_array().expect("We checked") { + if let Some(v) = v.as_str() { + output.push(v.to_owned()) + } else { + bail!("Owner value in arry not string: {}", v); + } + } + output + } else { + bail!("Owner value in drop in config not string or array") + } + }, + }; + + output.push(( + entry + .path() + .parent() + .expect("All drop-ins have a parent") + .to_owned(), + drop_in_config, + )); + } + } + + Ok(output) +} diff --git a/pkgs/by-name/ro/rollup/src/main.rs b/pkgs/by-name/ro/rollup/src/main.rs index 08f18648..7b7343a4 100644 --- a/pkgs/by-name/ro/rollup/src/main.rs +++ b/pkgs/by-name/ro/rollup/src/main.rs @@ -1,20 +1,31 @@ use std::{ + collections::HashMap, env::current_dir, + ffi::OsStr, fs, io::Write, path::{Path, PathBuf}, process::{Command, Stdio}, + sync::RwLock, }; use anyhow::{Context, Result, bail}; use clap::{Parser, Subcommand}; -use crate::parse::{FileDiff, Patch}; +use crate::{ + config::{DROP_IN_NAME, DropInConfig, MAIN_CONFIG_NAME, MainConfig, Owner}, + parse::{FileDiff, Patch}, +}; +mod config; mod parse; #[derive(Parser)] struct Cli { + /// Don't actually do anything, just check' + #[arg(long, global = true)] + dry_run: bool, + #[command(subcommand)] subcommand: Cmd, } @@ -27,10 +38,11 @@ enum Cmd { patch_files: Vec<PathBuf>, /// Which repository to use as a target for the rollup + /// It is specified via the owner, declared in the rollup.toml config. /// /// The repository needs to be clean. #[arg(short, long)] - to: PathBuf, + to: String, /// Show debug information related to the parsing of patch files. #[arg(short, long)] @@ -39,22 +51,23 @@ 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, + /// Which repository to use for the tag to base created tags on. + /// It is specified via the owner, declared in the rollup.toml config. + /// + /// The repository needs to be clean. + #[arg(short, long)] + to: 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 + /// Which repository to use as a target for the rollup and the tag for new + /// patches. + /// It is specified via the owner, declared in the rollup.toml config. /// /// The repository needs to be clean. #[arg(short, long)] - to: PathBuf, + to: String, /// Show debug information related to the parsing of patch files. #[arg(short, long)] @@ -118,8 +131,24 @@ macro_rules! git { }}; } +macro_rules! drop_msg { + ($fmt:literal, $($args:expr),*) => { + eprintln!(" > {}", format!($fmt, $($args),*)); + }; +} + fn main() -> Result<()> { let args = Cli::parse(); + let root = { + let (stdout, _) = git!(in current_dir()?; "rev-parse", "--show-toplevel"); + PathBuf::from(stdout.trim()) + }; + let config = config::load(&root).with_context(|| { + format!( + "Failed to instantiate the config (so loading main file and drop-ins). Started in root: `{}`", + root.display() + ) + })?; match args.subcommand { Cmd::Apply { @@ -127,45 +156,69 @@ fn main() -> Result<()> { to, debug_parse, } => { - check_to(&to)?; - apply_patches(patch_files, to, debug_parse)? + let owner = config.get_owner(&to)?; + check_owner(owner)?; + apply_patches(patch_files, owner, debug_parse, &config, root, args.dry_run)? } - Cmd::Create { tag } => { - create_patches(tag)?; + Cmd::Create { to } => { + let owner = config.get_owner(&to)?; + create_patches(&owner.last_applied_tag, args.dry_run)?; } - Cmd::CreateApply { - tag, - to, - debug_parse, - } => { - check_to(&to)?; + Cmd::CreateApply { to, debug_parse } => { + let owner = config.get_owner(&to)?; + check_owner(owner)?; - let Some(patches_directory) = create_patches(tag)? else { + let Some(patches_directory) = create_patches(&owner.last_applied_tag, args.dry_run)? + else { return Ok(()); }; + let patch_files = { + let iter = fs::read_dir(&patches_directory)?; + let mut output = vec![None; iter.count()]; + 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()); + let path = entry.path(); + let idx: usize = { + let mut file_name = path + .file_name() + .expect("Should all have a filename") + .to_str() + .expect("Should be valid utf8") + .chars(); + let number = file_name.clone().take(4).collect::<String>(); + assert_eq!(file_name.nth(4), Some('-')); + + number.parse().expect("Should parse as usize number") + }; + output[idx - 1] = Some(path); } + output.sort(); output }; - apply_patches(patch_files, to, debug_parse)?; + apply_patches( + patch_files.into_iter().map(|s| s.unwrap()).collect(), + owner, + debug_parse, + &config, + root, + args.dry_run, + )?; } } Ok(()) } -fn create_patches(tag: String) -> Result<Option<PathBuf>> { +fn create_patches(tag: &str, dry_run: bool) -> Result<Option<PathBuf>> { let current_dir = current_dir()?; - let (stdout, _) = git!(in current_dir; "tag", "--contains", "HEAD", tag.as_str()); + let (stdout, _) = git!(in current_dir; "tag", "--contains", "HEAD", tag); if !stdout.is_empty() { println!( "There are no tags to generate. Tag {} already points to HEAD.", @@ -185,15 +238,29 @@ fn create_patches(tag: String) -> Result<Option<PathBuf>> { let tempdir = PathBuf::from(String::from_utf8(mktemp.stdout).unwrap().trim()); git!(in current_dir; "format-patch", format!("{}..", tag).as_str(), "-o", tempdir.display().to_string().as_str()); - git!(in current_dir; "tag", "--delete", tag.as_str()); - git!(in current_dir; "tag", "--annotate", tag.as_str(), "-m", ""); + + if dry_run { + eprintln!("Dry-run is on; Not actually moving patch tag `{tag}` forward.") + } else { + git!(in current_dir; "tag", "--delete", tag); + git!(in current_dir; "tag", "--annotate", tag, "-m", ""); + } println!("Patches have been generated here: `{}`", tempdir.display()); Ok(Some(tempdir)) } -fn apply_patches(patch_files: Vec<PathBuf>, to: PathBuf, debug_parse: bool) -> Result<()> { +fn apply_patches( + patch_files: Vec<PathBuf>, + owner: &Owner, + debug_parse: bool, + config: &MainConfig, + root: PathBuf, + dry_run: bool, +) -> Result<()> { + let applies_to = &owner.applies_to; + let mut patches = vec![]; for file in &patch_files { patches.push(parse::parse_file(file, debug_parse)?); @@ -201,70 +268,73 @@ fn apply_patches(patch_files: Vec<PathBuf>, to: PathBuf, debug_parse: bool) -> R eprintln!("Successfully parsed all {} patch files.", patches.len()); - { - let (stdout, _) = git!(in to; "status", "--porcelain"); - if !stdout.is_empty() { - bail!( - "`--to` (`{}`) workspace is dirty, refusing to continue.", - to.display() - ); - } - } - for (idx, patch) in patches.iter().enumerate() { eprintln!( "Applying {}. patch: `{}`... ", idx + 1, - patch_files[idx].display() + patch_files[idx] + .file_name() + .expect("Has a file name") + .display() ); let mut final_diffs = vec![]; for file_diff in &patch.files { match file_diff { FileDiff::Add { path, .. } => { - if to.join(path).exists() { + if applies_to.join(path).try_exists()? { 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()); + if target_is_owning_path(&config.drop_ins, owner, &root, path, dry_run)? { + final_diffs.push(file_diff.to_owned()); + } } FileDiff::Remove { path, .. } => { - if to.join(path).exists() { + if applies_to.join(path).try_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.", + drop_msg!( + "Dropping remove of `{}`, as the file does not exist in the rollup target.", path.display() ); } } FileDiff::RenameNoChange { from, to, .. } | FileDiff::RenameWithChange { from, to, .. } => { - if to.join(from).exists() { - if to.join(to).exists() { + if applies_to.join(from).try_exists()? { + if applies_to.join(to).try_exists()? { bail!( "A rename (`{}` -> `{}`) tried to rename a path to an already existing path. This should be impossible.", from.display(), to.display() ) + } else { + final_diffs.push(file_diff.to_owned()); } - 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.", + drop_msg!( + "Dropping rename from `{}` to `{}`, as the from file does not exist in the rollup target.", from.display(), to.display() ); } } FileDiff::Change { path, .. } => { - if to.join(path).exists() { + if applies_to.join(path).try_exists()? { final_diffs.push(file_diff.to_owned()); } else { - eprintln!( - " > Dropping change to `{}`, as the file does not exist in the rollup target.", + drop_msg!( + "Dropping change to `{}`, as the file does not exist in the rollup target.", + path.display() + ); + } + } + FileDiff::ModeChange { path, .. } => { + if applies_to.join(path).try_exists()? { + final_diffs.push(file_diff.to_owned()); + } else { + drop_msg!( + "Dropping mode change to `{}`, as the file does not exist in the rollup target.", path.display() ); } @@ -282,15 +352,30 @@ fn apply_patches(patch_files: Vec<PathBuf>, to: PathBuf, debug_parse: bool) -> R ..patch.to_owned() }; - git!(@set_stdin_to filtered_patch; in to; "apply", "-", "--whitespace=nowarn"); - git!(in to; "add", "."); - git!(@set_stdin_to filtered_patch.commit_message; in to; "commit", "--file=-", format!("--date={}", filtered_patch.date).as_str(), "--quiet"); + if dry_run { + eprintln!(" (Dry-run is on; Not applying.)"); + } else { + git!(@set_stdin_to filtered_patch; in applies_to; "apply", "-", "--whitespace=nowarn"); + git!(in applies_to; "add", "."); + git!(@set_stdin_to filtered_patch.commit_message; in applies_to; "commit", "--file=-", format!("--date={}", filtered_patch.date).as_str(), "--quiet"); + } + } + + if dry_run { + let ownerless_paths = PATHS_WITHOUT_OWNERSHIP.read().unwrap(); + if !ownerless_paths.is_empty() { + eprintln!("\n\nPaths without ownership information:"); + for path in &*ownerless_paths { + eprintln!(" - {}", path.display()); + } + } } Ok(()) } -fn check_to(to: &Path) -> Result<()> { +fn check_owner(owner: &Owner) -> Result<()> { + let to = &owner.applies_to; let to = to.join(".git"); // NOTE: We cannot just try to stat() the path, because landlock might be in use and does not @@ -310,5 +395,91 @@ fn check_to(to: &Path) -> Result<()> { bail!("To directory (`{}`) is not readable", to.display()); } + { + let (stdout, _) = git!(in owner.applies_to; "status", "--porcelain"); + if !stdout.is_empty() { + bail!( + "owners (`{}`) workspace (`{}`) is dirty, refusing to continue.", + owner.name, + owner.applies_to.display() + ); + } + } + Ok(()) } + +static PATHS_WITHOUT_OWNERSHIP: RwLock<Vec<PathBuf>> = RwLock::new(vec![]); + +fn target_is_owning_path( + drop_ins: &HashMap<PathBuf, DropInConfig>, + owner: &Owner, + root: &Path, + path: &Path, + dry_run: bool, +) -> Result<bool> { + let file_name = path.file_name().expect("All paths are to files"); + if file_name == OsStr::new(DROP_IN_NAME) || file_name == OsStr::new(MAIN_CONFIG_NAME) { + drop_msg!( + "Not applying change to `{}`, because it's a rollup config or drop in.", + path.display() + ); + + return Ok(false); + } + + if root.join(path).parent() == Some(root) { + // The path is in the root directory, so there can be no drop-in to apply. It is trivially + // included. + // TODO: It would maybe be good to re-think this. <2026-11-23> + return Ok(true); + } + + if let Some(conf) = drop_ins.get(path) + && conf.owners.contains(&owner.name) + { + return Ok(true); + } + + let mut parent: &Path = path; + while let Some(next) = parent.parent() { + // eprintln!("Checking `{}` for drop-ins..", next.display()); + + if let Some(conf) = drop_ins.get(&root.join(next)) { + // eprint!("Found a drop-in for `{}`", next.display()); + if !conf.owners.contains(&owner.name) { + // eprintln!(", but it's for `{}`, so ignoring path.", conf.owner); + drop_msg!( + "Dropping creation of `{}` as `{}` says this dir is for `{}` (but we look for `{}`).", + path.display(), + next.join(DROP_IN_NAME).display(), + conf.owners.join(", "), + owner.name + ); + return Ok(false); + } else { + // eprintln!(", which matches."); + return Ok(true); + } + } + parent = next; + } + + if dry_run { + eprintln!( + "Warning: There was no drop-in config defining path ownership for: `{}`. + Assuming inclusion (only works for --dry-run).", + path.display() + ); + PATHS_WITHOUT_OWNERSHIP + .write() + .unwrap() + .push(path.to_owned()); + Ok(true) + } else { + bail!( + "There was no drop-in config defining path ownership for: `{}`.", + path.display() + ) + } +} diff --git a/pkgs/by-name/ro/rollup/src/parse.rs b/pkgs/by-name/ro/rollup/src/parse.rs index ac30eaa4..a636d661 100644 --- a/pkgs/by-name/ro/rollup/src/parse.rs +++ b/pkgs/by-name/ro/rollup/src/parse.rs @@ -60,6 +60,11 @@ pub(crate) enum FileDiff { diff: String, index: String, }, + ModeChange { + path: PathBuf, + old_mode: String, + new_mode: String, + }, } impl fmt::Display for FileDiff { @@ -120,6 +125,15 @@ impl fmt::Display for FileDiff { writeln!(f, "+++ b/{}", to.display())?; writeln!(f, "{}", diff)?; } + FileDiff::ModeChange { + path, + old_mode, + new_mode, + } => { + writeln!(f, "diff --git a/{} b/{}", path.display(), path.display())?; + writeln!(f, "old mode {}", old_mode)?; + writeln!(f, "new mode {}", new_mode)?; + } } Ok(()) @@ -159,13 +173,31 @@ macro_rules! parser { .. $diff:ident ) => { $( - let $prefix_var = { - let next = $iterator.next().unwrap(); + let next = { + let next = $iterator + .next() + .expect( + concat!( + "iterator '", + stringify!($iterator), + "' did not have a next value" + ) + ); if $debug { eprintln!(" {}", next); } next - }.strip_prefix($prefix).unwrap().to_owned(); + }; + + let $prefix_var = next + .strip_prefix($prefix) + .expect( + format!( + "expected prefix `{}` in line `{}`, but didn't find it.", + $prefix, + next + ).as_str() + ).to_owned(); $( $expr )*; @@ -299,6 +331,8 @@ pub(crate) fn parse_file(file: &Path, debug: bool) -> Result<Patch> { // skip one more to go over the `---` line .skip(1) .peekable(); + let mut git_diff_a = None; + let mut git_diff_b = None; while let Some(line) = iterator.peek() { if debug { eprintln!("{}", line); @@ -314,6 +348,16 @@ pub(crate) fn parse_file(file: &Path, debug: bool) -> Result<Patch> { if skipping_frontmatter { skipping_frontmatter = false; } + + { + let mut parts = line.split(' '); + assert_eq!("diff", parts.next().unwrap()); + assert_eq!("--git", parts.next().unwrap()); + git_diff_a = Some(parts.next().unwrap().strip_prefix("a/").unwrap()); + git_diff_b = Some(parts.next().unwrap().strip_prefix("b/").unwrap()); + assert_eq!(None, parts.next()); + } + iterator.next().unwrap(); continue; } @@ -393,8 +437,24 @@ pub(crate) fn parse_file(file: &Path, debug: bool) -> Result<Patch> { deleted_mode, }) } + line if line.starts_with("old mode") => { + parser! { + iterator, debug, + "old mode " @ old_mode => {()}; + "new mode " @ new_mode => {()}; + ..no_diff + } + assert!(no_diff.is_empty()); + + assert_eq!(git_diff_a, git_diff_b); + patch_files.push(FileDiff::ModeChange { + path: PathBuf::from(git_diff_a.expect("Should have been produced by git")), + old_mode, + new_mode, + }) + } line if *line == "--" || *line == "-- " => { - final_whitespace = Some( match *line { + final_whitespace = Some(match *line { "-- " => " ", "--" => "", _ => unreachable!(), |
