Update radicle-surf to v0.17

This commit introduces the `FileStats` struct, that adds the insertions
and deletions for each file to `DiffContent`.

Signed-off-by: Sebastian Martinez <me@sebastinez.dev>
This commit is contained in:
Sebastian Martinez
2023-10-11 14:29:34 +02:00
committed by cloudhead
parent 9a1a216f70
commit 504a198cec
6 changed files with 64 additions and 23 deletions
+15 -1
View File
@@ -3,6 +3,7 @@ use std::fmt;
use std::io;
use std::path::PathBuf;
use radicle_surf::diff::FileStats;
use thiserror::Error;
use radicle::git;
@@ -203,8 +204,17 @@ impl Encode for Diff {
impl Decode for DiffContent {
fn decode(r: &mut impl io::BufRead) -> Result<Self, Error> {
let mut hunks = Vec::default();
let mut additions = 0;
let mut deletions = 0;
while let Some(h) = Hunk::<_>::try_decode(r)? {
while let Some(h) = Hunk::try_decode(r)? {
for l in &h.lines {
match l {
Modification::Addition(_) => additions += 1,
Modification::Deletion(_) => deletions += 1,
_ => {}
}
}
hunks.push(h);
}
@@ -214,6 +224,10 @@ impl Decode for DiffContent {
// TODO: Handle case for binary.
Ok(DiffContent::Plain {
hunks: Hunks::from(hunks),
stats: FileStats {
additions,
deletions,
},
// TODO: Properly handle EndOfLine field
eof: diff::EofNewLine::NoneMissing,
})