diff options
author | Teddy Wing | 2020-09-16 22:45:52 +0200 |
---|---|---|
committer | Teddy Wing | 2020-09-16 22:45:52 +0200 |
commit | b6002fee979606986458449b8ffe6d290dbba8d1 (patch) | |
tree | 5a59f36e485ca2ba8f4fc6334c6e03677e42d380 | |
parent | 6fdf7b121bcddbc0328703f34fdb0fee71e03dc8 (diff) | |
download | git-todo-b6002fee979606986458449b8ffe6d290dbba8d1.tar.bz2 |
write_since(): Handle errors in `diff.foreach()` callback
* Ignore lines that don't parse to UTF-8. Might want to figure out how
to support other encodings.
* Ignore lines that don't have a `path`.
* Panic on write errors.
-rw-r--r-- | src/lib.rs | 22 |
1 files changed, 12 insertions, 10 deletions
@@ -41,16 +41,18 @@ impl Todos<'_> { // ); if let Some(line_number) = line.new_lineno() { - let l = std::str::from_utf8(line.content()).unwrap(); - - if l.contains("TODO") { - write!( - write_to, - "{}:{}:{}", - delta.new_file().path().unwrap().display(), - line_number, - l, - ).unwrap(); + if let Ok(l) = std::str::from_utf8(line.content()) { + if l.contains("TODO") { + if let Some(path) = delta.new_file().path() { + write!( + write_to, + "{}:{}:{}", + path.display(), + line_number, + l, + ).expect("write error"); + } + } } } |