b3rr10 / diff-rs Goto Github PK
View Code? Open in Web Editor NEWSimple diff output in Rust
License: MIT License
Simple diff output in Rust
License: MIT License
Maybe the functions in the printer.rs
module could return a String
instead of printing the content, so that unit-tests can be added.
The println!(...)
method would then be found on the main.rs
module.
The idea is to have full code coverage in this module as well.
Parser analyse a diff content and return a list of files with the changes with line numbers, the modifier marker and so on.
File:
If not a diff (patch), do nothing and output to stdout
Actually the struct File
has only one filename. Another filename field should be added and the Printer
should also be able to show two filenames when file.modifier == MODIFIER::RENAMED
I will try to replace my printer implementation with the mre/prettyprinter crate. But first, I have to fork and modify it for our usage.
When printing a diff, one should be able to look the line number of the old as well as the new file. E.g.
1 1 This line is on both files
2 This line is only on the old file
3 2 This line is on both files but in a different "line"
3 This file is only on the new file
When the diff header is renamed from...
, the hunk may not have any header index...
, so the parser will fail. One option is to have a default commit_id
for those cases...
do_parse!(
... >>
commit_id: opt!(...) >>
.... >>
(commit_id.unwrap_or_else(default_value))
)
Add the flag -v
for verbosity to see debug messages in the console. Maybe we can add 2 or three levels of verbosity (-vv
and -vvv
) to show different outputs.
diff_rs panic if you use it as diff-pager in gitconfig:
pager = $PROJECT_DIR/diff.rs/target/release/diff_rs
Backtrace:
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: "Error parsing file. Remaining is not empty. Remaining: \"\\u{1b}[1;33mindex 5ce557a..cd16654 100644\\u{1b}[m\\n\\u{1b}[1;33m--- a/README.md\\u{1b}[m\\n\\u{1b}[1;33m+++ b/README.md\\u{1b}[m\\n\\u{1b}[1;35m@@ -13,7 +13,7 @@\\u{1b}[m \\u{1b}[mA more beautiful and readable diff output for ...\\u{1b}[m\\n Install it in different ways:\\u{1b}[m\\n \\u{1b}[m\\n ```\\u{1b}[m\\n\\u{1b}[1;31m-cargo install diff.rs\\u{1b}[m\\n\\u{1b}[1;32m+\\u{1b}[m\\u{1b}[1;32mcargo install diff_rs\\u{1b}[m\\n ```\\u{1b}[m\\n \\u{1b}[m\\n or directly over github:\\u{1b}[m\\n\""', src/libcore/result.rs:999:5
stack backtrace:
0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
at src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:39
1: std::sys_common::backtrace::_print
at src/libstd/sys_common/backtrace.rs:71
2: std::panicking::default_hook::{{closure}}
at src/libstd/sys_common/backtrace.rs:59
at src/libstd/panicking.rs:197
3: std::panicking::default_hook
at src/libstd/panicking.rs:211
4: std::panicking::rust_panic_with_hook
at src/libstd/panicking.rs:474
5: std::panicking::continue_panic_fmt
at src/libstd/panicking.rs:381
6: rust_begin_unwind
at src/libstd/panicking.rs:308
7: core::panicking::panic_fmt
at src/libcore/panicking.rs:85
8: core::result::unwrap_failed
9: diff_rs::parser::parse_content
10: diff_rs::main
11: std::rt::lang_start::{{closure}}
12: std::panicking::try::do_call
at src/libstd/rt.rs:49
at src/libstd/panicking.rs:293
13: __rust_maybe_catch_panic
at src/libpanic_unwind/lib.rs:85
14: std::rt::lang_start_internal
at src/libstd/panicking.rs:272
at src/libstd/panic.rs:388
at src/libstd/rt.rs:48
15: main
16: __libc_start_main
17: _start
Result<...>
enum
for combining error types and be able to propagate errors through the program (Enum with errors that implements From<>
for every error type)unwrap()
with ?
ExampleA declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.