surf: Add stats property to each DiffContent::Plain#145
surf: Add stats property to each DiffContent::Plain#145FintanH merged 1 commit intoradicle-dev:mainfrom
stats property to each DiffContent::Plain#145Conversation
radicle-surf/src/diff.rs
Outdated
| hunks: _, | ||
| stats: _, | ||
| eof, |
There was a problem hiding this comment.
| hunks: _, | |
| stats: _, | |
| eof, | |
| eof, .. |
I'd say we just do this :)
radicle-surf/src/diff.rs
Outdated
| _ => None, | ||
| } | ||
| } | ||
| pub fn stats(&self) -> FileStats { |
There was a problem hiding this comment.
| pub fn stats(&self) -> FileStats { | |
| pub fn stats(&self) -> FileStats { |
New line please 🙏
| let mut additions = 0; | ||
| let mut deletions = 0; | ||
|
|
||
| match &self { |
There was a problem hiding this comment.
Wait, why are we calculating the stats here if it's contained in DiffContent::Plain? 🤔
I think we want to see if git2 can provide the stats per file and get them from there when we create the DiffContent (in the TryFrom impls under diff::git).
So we should just match and return:
DiffContent::Plain { stats, .. } => Some(stats),
DiffContent::Empty => None,
DiffContent::Binary => None,I'd return an Option because stats don't make sense for the other two.
There was a problem hiding this comment.
Yeah that works, seems like it did the job twice 😁
Done ✅
| old_missing_eof = true; | ||
| continue; | ||
| }, | ||
| git2::DiffLineType::Addition => { |
There was a problem hiding this comment.
Ah you are calculating them here. I checked DiffFile too and there were no individual stats.
There was a problem hiding this comment.
I don't think we want the individual stats to show up in the DiffFile since we are interested in the changes introduced by a specific diff which is specified by DiffContent.
While the DiffFile only relates to a specific blob.
41fb18e to
232d503
Compare
FintanH
left a comment
There was a problem hiding this comment.
Just a little fix and then happy to merge 👍
radicle-surf/t/src/diff.rs
Outdated
| additions:2, | ||
| deletions:1 |
There was a problem hiding this comment.
| additions:2, | |
| deletions:1 | |
| additions: 2, | |
| deletions: 1 |
There was a problem hiding this comment.
Thanks for the catch, is resolved 👍
This allows us to get the additions and deletions for each file in a diff. Signed-off-by: Sebastian Martinez <me@sebastinez.dev>
232d503 to
097d013
Compare
This allows us to get the additions and deletions for each file in a diff.