-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
1,967 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
[workspace] | ||
members = ["modda-cli"] | ||
members = ["modda-cli", "patch-rs"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
target | ||
Cargo.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# CHANGELOG | ||
|
||
## [Unreleased] | ||
### Changed | ||
|
||
## [v0.7] | ||
### Breaking | ||
- Filename parsing now expects (and renders) a tab character after the filename instead of a space character, before any metadata. Seems like all diff programs actually follow this convention, and git will even render unquoted filenames with spaces, so the previous parsing would produce incorrect results. Thanks [@keith](https://github.com/keith) for reporting. | ||
|
||
### Fixed | ||
- Don't break (hopefully) on diffs with windows-style CRLF line endings. I don't have samples to verify with, but it Seems Like Maybe It Will Do The Right Thing? (it will still ony render diffs with line endings as `\n`. Please open a feature request if you want this.) Thanks [@jacobtread](https://github.com/jacobtread) for reporting. | ||
- Parse (and save) hunk hints after range info instead of (incorrectly) treating them like Context lines. Thanks [@keith](https://github.com/keith) and [@wfraser](https://github.com/wfraser). | ||
|
||
## [v0.6] | ||
### Changed | ||
- Upgrade nom to 0.7! from [@compiler-errors](https://github.com/compiler-errors) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[package] | ||
name = "patch" | ||
version = "0.7.0" | ||
authors = ["phil <[email protected]>"] | ||
description = "Parse patches in the unified diff format" | ||
repository = "https://github.com/uniphil/patch-rs" | ||
readme = "README.md" | ||
keywords = ["patch", "diff", "parse", "nom"] | ||
license = "MIT" | ||
edition = "2018" | ||
|
||
[dependencies] | ||
nom = "7.1.0" | ||
nom_locate = "4.0.0" | ||
chrono = "0.4.19" | ||
|
||
[dev-dependencies] | ||
pretty_assertions = "1.0.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2016 uniphil | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Patch | ||
|
||
[![Checks](https://github.com/uniphil/patch-rs/actions/workflows/checks.yml/badge.svg)](https://github.com/uniphil/patch-rs/actions/workflows/checks.yml) | ||
[![Crates.io Badge](https://img.shields.io/crates/v/patch.svg)](https://crates.io/crates/patch) | ||
[![docs.rs](https://docs.rs/patch/badge.svg)](https://docs.rs/patch) | ||
[![Lines of Code](https://tokei.rs/b1/github/uniphil/patch-rs)](https://github.com/uniphil/patch-rs) | ||
|
||
Rust crate for parsing and producing patch files in the [Unified Format]. | ||
|
||
The parser attempts to be forgiving enough to be compatible with diffs produced | ||
by programs like git. It accomplishes this by ignoring the additional code | ||
context and information provided in the diff by those programs. | ||
|
||
See the **[Documentation]** for more information and for examples. | ||
|
||
[Unified Format]: https://www.gnu.org/software/diffutils/manual/html_node/Unified-Format.html | ||
[Documentation]: https://docs.rs/patch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
//! Demonstrates how to apply a parsed diff to a file | ||
|
||
use patch::{Line, Patch}; | ||
|
||
fn apply(diff: Patch, old: &str) -> String { | ||
let old_lines = old.lines().collect::<Vec<&str>>(); | ||
let mut out: Vec<&str> = vec![]; | ||
let mut old_line = 0; | ||
for hunk in diff.hunks { | ||
while old_line < hunk.old_range.start - 1 { | ||
out.push(old_lines[old_line as usize]); | ||
old_line += 1; | ||
} | ||
old_line += hunk.old_range.count; | ||
for line in hunk.lines { | ||
match line { | ||
Line::Add(s) | Line::Context(s) => out.push(s), | ||
Line::Remove(_) => {} | ||
} | ||
} | ||
} | ||
out.join("\n") | ||
} | ||
|
||
static LAO: &str = "\ | ||
The Way that can be told of is not the eternal Way; | ||
The name that can be named is not the eternal name. | ||
The Nameless is the origin of Heaven and Earth; | ||
The Named is the mother of all things. | ||
Therefore let there always be non-being, | ||
so we may see their subtlety, | ||
And let there always be being, | ||
so we may see their outcome. | ||
The two are the same, | ||
But after they are produced, | ||
they have different names. | ||
"; | ||
|
||
static RAW_DIFF: &str = "\ | ||
--- lao 2002-02-21 23:30:39.942229878 -0800 | ||
+++ tzu 2002-02-21 23:30:50.442260588 -0800 | ||
@@ -1,7 +1,6 @@ | ||
-The Way that can be told of is not the eternal Way; | ||
-The name that can be named is not the eternal name. | ||
The Nameless is the origin of Heaven and Earth; | ||
-The Named is the mother of all things. | ||
+The named is the mother of all things. | ||
+ | ||
Therefore let there always be non-being, | ||
so we may see their subtlety, | ||
And let there always be being, | ||
@@ -9,3 +8,6 @@ | ||
The two are the same, | ||
But after they are produced, | ||
they have different names. | ||
+They both may be called deep and profound. | ||
+Deeper and more profound, | ||
+The door of all subtleties! | ||
"; | ||
|
||
fn main() { | ||
let diff = Patch::from_single(RAW_DIFF).unwrap(); | ||
let new = apply(diff, LAO); | ||
println!("should be tzu:\n\n{}", new); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
with import <nixpkgs> {}; | ||
|
||
stdenv.mkDerivation { | ||
name = "rust"; | ||
buildInputs = [ | ||
cargo | ||
]; | ||
} |
Oops, something went wrong.