-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
surf: Add stats
property to each DiffContent::Plain
#145
surf: Add stats
property to each DiffContent::Plain
#145
Conversation
radicle-surf/src/diff.rs
Outdated
hunks: _, | ||
stats: _, | ||
eof, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that works, seems like it did the job twice 😁
Done ✅
@@ -166,11 +169,19 @@ impl TryFrom<git2::Patch<'_>> for DiffContent { | |||
old_missing_eof = true; | |||
continue; | |||
}, | |||
git2::DiffLineType::Addition => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah you are calculating them here. I checked DiffFile
too and there were no individual stats.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
additions:2, | |
deletions:1 | |
additions: 2, | |
deletions: 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.