From 82791c66b54453e7d1135acd3ce34479acade373 Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Sun, 7 Dec 2025 11:10:34 -0800 Subject: [PATCH 1/2] Add an example program that dumps the parsed form --- examples/dump.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 examples/dump.rs diff --git a/examples/dump.rs b/examples/dump.rs new file mode 100644 index 0000000..2dd6856 --- /dev/null +++ b/examples/dump.rs @@ -0,0 +1,20 @@ +//! Print the debug form of a parsed patch. + +use std::{ + env::args, + fs::read_to_string, + io::{stdin, Read}, +}; + +use gitpatch::Patch; + +fn main() { + let mut patch_text = String::new(); + if let Some(filename) = args().nth(1) { + patch_text = read_to_string(filename).unwrap(); + } else { + stdin().read_to_string(&mut patch_text).unwrap(); + }; + let patch = Patch::from_multiple(&patch_text).unwrap(); + println!("{:#?}", patch); +} From ce00ab2e5c62009386e55eaffb1af82b3c973e54 Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Sun, 7 Dec 2025 11:10:34 -0800 Subject: [PATCH 2/2] Add an example that prints out the parsed diff --- examples/reproduce.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 examples/reproduce.rs diff --git a/examples/reproduce.rs b/examples/reproduce.rs new file mode 100644 index 0000000..013703a --- /dev/null +++ b/examples/reproduce.rs @@ -0,0 +1,22 @@ +//! Parse a patch from a file or stdin, then print it out as a patch. + +use std::{ + env::args, + fs::read_to_string, + io::{stdin, Read}, +}; + +use gitpatch::Patch; + +fn main() { + let mut patch_text = String::new(); + if let Some(filename) = args().nth(1) { + patch_text = read_to_string(filename).unwrap(); + } else { + stdin().read_to_string(&mut patch_text).unwrap(); + }; + let patches = Patch::from_multiple(&patch_text).unwrap(); + for patch in patches { + println!("{}", patch); + } +}