mirror of
https://github.com/uutils/diffutils.git
synced 2026-06-10 15:48:59 -07:00
Initial commit
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
/target
|
||||
Cargo.lock
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
[package]
|
||||
name = "unified-diff"
|
||||
version = "0.1.0"
|
||||
authors = [
|
||||
"Michael Howell <michael@notriddle.com>",
|
||||
"The Rust Project Developers"
|
||||
]
|
||||
edition = "2018"
|
||||
|
||||
[[bin]]
|
||||
name = "unified-diff"
|
||||
|
||||
[dependencies]
|
||||
diff = "0.1.10"
|
||||
@@ -0,0 +1,39 @@
|
||||
A GNU unified diff generator. Oracle tested against GNU patch 2.7.6
|
||||
|
||||
Based on the incomplete diff generator in https://github.com/rust-lang/rust/blob/master/src/tools/compiletest/src/runtest.rs,
|
||||
but it implements a different format.
|
||||
|
||||
```
|
||||
~/unified-diff$ cargo run Cargo.lock Cargo.toml
|
||||
Finished dev [unoptimized + debuginfo] target(s) in 0.00s
|
||||
Running `target/debug/unified-diff Cargo.lock Cargo.toml`
|
||||
--- Cargo.lock
|
||||
+++ Cargo.toml
|
||||
@@ -1,14 +1,14 @@
|
||||
-# This file is automatically @generated by Cargo.
|
||||
-# It is not intended for manual editing.
|
||||
-[[package]]
|
||||
-name = "diff"
|
||||
-version = "0.1.12"
|
||||
-source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
-checksum = "0e25ea47919b1560c4e3b7fe0aaab9becf5b84a10325ddf7db0f0ba5e1026499"
|
||||
-
|
||||
-[[package]]
|
||||
+[package]
|
||||
name = "unified-diff"
|
||||
version = "0.1.0"
|
||||
-dependencies = [
|
||||
- "diff",
|
||||
+authors = [
|
||||
+ "Michael Howell <michael@notriddle.com>",
|
||||
+ "The Rust Project Developers"
|
||||
]
|
||||
+edition = "2018"
|
||||
+
|
||||
+[[bin]]
|
||||
+name = "unified-diff"
|
||||
+
|
||||
+[dependencies]
|
||||
+diff = "0.1.10"
|
||||
```
|
||||
|
||||
+595
File diff suppressed because it is too large
Load Diff
+55
@@ -0,0 +1,55 @@
|
||||
// Sample program. Do not use.
|
||||
use std::env;
|
||||
use std::fs;
|
||||
use std::io::{self, Write};
|
||||
use std::process;
|
||||
fn main() {
|
||||
let mut o = env::args_os();
|
||||
// parse CLI
|
||||
let exe = match o.next() {
|
||||
Some(from) => from,
|
||||
None => {
|
||||
eprintln!("Usage: [exe] [from] [to]");
|
||||
process::exit(1);
|
||||
}
|
||||
};
|
||||
let from = match o.next() {
|
||||
Some(from) => from,
|
||||
None => {
|
||||
eprintln!("Usage: {} [from] [to]", exe.to_string_lossy());
|
||||
process::exit(1);
|
||||
}
|
||||
};
|
||||
let to = match o.next() {
|
||||
Some(from) => from,
|
||||
None => {
|
||||
eprintln!("Usage: {} [from] [to]", exe.to_string_lossy());
|
||||
process::exit(1);
|
||||
}
|
||||
};
|
||||
// read files
|
||||
let from_content = match fs::read(&from) {
|
||||
Ok(from_content) => from_content,
|
||||
Err(e) => {
|
||||
eprintln!("Failed to read from-file: {}", e);
|
||||
process::exit(2);
|
||||
}
|
||||
};
|
||||
let to_content = match fs::read(&to) {
|
||||
Ok(to_content) => to_content,
|
||||
Err(e) => {
|
||||
eprintln!("Failed to read to-file: {}", e);
|
||||
process::exit(2);
|
||||
}
|
||||
};
|
||||
// run diff
|
||||
io::stdout()
|
||||
.write_all(&unified_diff::diff(
|
||||
&from_content,
|
||||
&from.to_string_lossy(),
|
||||
&to_content,
|
||||
&to.to_string_lossy(),
|
||||
3,
|
||||
))
|
||||
.unwrap();
|
||||
}
|
||||
Reference in New Issue
Block a user