-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ use super::{ | |
DiffFile, | ||
EofNewLine, | ||
FileMode, | ||
FileStats, | ||
Hunk, | ||
Hunks, | ||
Line, | ||
|
@@ -152,6 +153,8 @@ impl TryFrom<git2::Patch<'_>> for DiffContent { | |
let mut hunks = Vec::new(); | ||
let mut old_missing_eof = false; | ||
let mut new_missing_eof = false; | ||
let mut additions = 0; | ||
let mut deletions = 0; | ||
|
||
for h in 0..patch.num_hunks() { | ||
let (hunk, hunk_lines) = patch.hunk(h)?; | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. Ah you are calculating them here. I checked There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we want the individual |
||
additions += 1; | ||
}, | ||
git2::DiffLineType::Deletion => { | ||
deletions += 1; | ||
}, | ||
git2::DiffLineType::AddEOFNL => { | ||
additions += 1; | ||
old_missing_eof = true; | ||
continue; | ||
}, | ||
git2::DiffLineType::DeleteEOFNL => { | ||
deletions += 1; | ||
new_missing_eof = true; | ||
continue; | ||
}, | ||
|
@@ -194,6 +205,10 @@ impl TryFrom<git2::Patch<'_>> for DiffContent { | |
}; | ||
Ok(DiffContent::Plain { | ||
hunks: Hunks(hunks), | ||
stats: FileStats { | ||
additions, | ||
deletions, | ||
}, | ||
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.
Wait, why are we calculating the stats here if it's contained in
DiffContent::Plain
? 🤔I think we want to see ifgit2
can provide the stats per file and get them from there when we create theDiffContent
(in theTryFrom
impls underdiff::git
).So we should just match and return:
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 ✅