summaryrefslogtreecommitdiffstats
path: root/pkgs/by-name/ro/rollup/src/parse.rs
diff options
context:
space:
mode:
authorSoispha Peetz <soispha@b-peetz.de>2026-11-27 00:53:37 +0100
committerSoispha Peetz <soispha@b-peetz.de>2026-11-28 23:58:39 +0100
commit5b346eb6795b95b220f95d9fd34240c5f123300a (patch)
treef0516bcc8b8f6e0d9d80d6acb48c88d80070923f /pkgs/by-name/ro/rollup/src/parse.rs
parentpkgs/rollup: Make it easier to add missing .rollup.owner files (diff)
downloadnixos-config-5b346eb6795b95b220f95d9fd34240c5f123300a.zip
pkgs/rollup: Support parsing mode only changes
The only thing, I know of, that is still missing is `GIT binary patch`s.
Diffstat (limited to '')
-rw-r--r--pkgs/by-name/ro/rollup/src/parse.rs66
1 files changed, 63 insertions, 3 deletions
diff --git a/pkgs/by-name/ro/rollup/src/parse.rs b/pkgs/by-name/ro/rollup/src/parse.rs
index 05ef2cb6..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,6 +437,22 @@ 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 {
"-- " => " ",