Skip to content
This repository has been archived by the owner on Apr 29, 2024. It is now read-only.

Commit

Permalink
Update radicle-surf to v0.17
Browse files Browse the repository at this point in the history
This commit introduces the `FileStats` struct, that adds the insertions
and deletions for each file to `DiffContent`.

Signed-off-by: Sebastian Martinez <[email protected]>
  • Loading branch information
sebastinez authored and cloudhead committed Oct 11, 2023
1 parent 9a1a216 commit 504a198
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 24 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion radicle-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ nonempty = { version = "0.8" }
# N.b. this is required to use macros, even though it's re-exported
# through radicle
radicle-git-ext = { version = "0.6.0", features = ["serde"] }
radicle-surf = { version = "0.16.0" }
radicle-surf = { version = "0.17.0" }
serde = { version = "1.0" }
serde_json = { version = "1" }
serde_yaml = { version = "0.8" }
Expand Down
23 changes: 5 additions & 18 deletions radicle-cli/src/git/pretty_diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,26 +165,13 @@ impl ToPretty for DiffContent {
Some((f.old.oid, f.new_path.clone())),
),
};

let mut header = header.pretty(hi, &(), repo);
let mut additions = 0;
let mut deletions = 0;

match self {
DiffContent::Plain { hunks, .. } => {
for h in hunks.iter() {
for l in &h.lines {
match l {
Modification::Addition(_) => additions += 1,
Modification::Deletion(_) => deletions += 1,
_ => {}
}
}
}
}
DiffContent::Empty => {}
DiffContent::Binary => {}
}
let (additions, deletions) = if let Some(stats) = self.stats() {
(stats.additions, stats.deletions)
} else {
(0, 0)
};
if deletions > 0 {
header.push(term::label(format!(" -{deletions}")).fg(theme.color("negative.light")));
}
Expand Down
18 changes: 16 additions & 2 deletions radicle-cli/src/git/unified_diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();

while let Some(h) = Hunk::<_>::try_decode(r)? {
let mut additions = 0;
let mut deletions = 0;

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);
}

Expand All @@ -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,
})
Expand Down
2 changes: 1 addition & 1 deletion radicle-httpd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ hyper = { version = "0.14.17", default-features = false }
lexopt = { version = "0.2.1" }
lru = { version = "0.11.0" }
nonempty = { version = "0.8.1", features = ["serialize"] }
radicle-surf = { version = "0.16.0", default-features = false, features = ["serde"] }
radicle-surf = { version = "0.17.0", default-features = false, features = ["serde"] }
serde = { version = "1", features = ["derive"] }
serde_json = { version = "1", features = ["preserve_order"] }
thiserror = { version = "1" }
Expand Down
40 changes: 40 additions & 0 deletions radicle-httpd/src/api/v1/projects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1187,6 +1187,10 @@ mod routes {
},
},
],
"stats": {
"additions": 1,
"deletions": 0,
},
"eof": "noneMissing",
},
"new": {
Expand Down Expand Up @@ -1218,6 +1222,10 @@ mod routes {
},
}
],
"stats": {
"additions": 1,
"deletions": 0,
},
"eof": "noneMissing",
},
"new": {
Expand Down Expand Up @@ -1251,6 +1259,10 @@ mod routes {
},
},
],
"stats": {
"additions": 0,
"deletions": 1,
},
"eof": "noneMissing",
},
"old": {
Expand Down Expand Up @@ -1316,6 +1328,10 @@ mod routes {
},
},
],
"stats": {
"additions": 1,
"deletions": 0,
},
"eof": "noneMissing",
},
"new": {
Expand Down Expand Up @@ -1349,6 +1365,10 @@ mod routes {
},
},
],
"stats": {
"additions": 0,
"deletions": 1,
},
"eof": "noneMissing",
},
"old": {
Expand Down Expand Up @@ -1412,6 +1432,10 @@ mod routes {
},
}
],
"stats": {
"additions": 1,
"deletions": 0,
},
"eof": "noneMissing",
},
"new": {
Expand Down Expand Up @@ -1497,6 +1521,10 @@ mod routes {
},
},
],
"stats": {
"additions": 1,
"deletions": 0,
},
"eof": "noneMissing",
},
"new": {
Expand Down Expand Up @@ -1528,6 +1556,10 @@ mod routes {
},
}
],
"stats": {
"additions": 1,
"deletions": 0,
},
"eof": "noneMissing",
},
"new": {
Expand Down Expand Up @@ -1561,6 +1593,10 @@ mod routes {
},
},
],
"stats": {
"additions": 0,
"deletions": 1,
},
"eof": "noneMissing",
},
"old": {
Expand Down Expand Up @@ -1892,6 +1928,10 @@ mod routes {
},
},
],
"stats": {
"additions": 1,
"deletions": 0,
},
"eof": "noneMissing",
},
"new": {
Expand Down

0 comments on commit 504a198

Please sign in to comment.