Skip to content
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

Merged

Conversation

sebastinez
Copy link
Member

This allows us to get the additions and deletions for each file in a diff.

Comment on lines 301 to 303
hunks: _,
stats: _,
eof,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
hunks: _,
stats: _,
eof,
eof, ..

I'd say we just do this :)

_ => None,
}
}
pub fn stats(&self) -> FileStats {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub fn stats(&self) -> FileStats {
pub fn stats(&self) -> FileStats {

New line please 🙏

let mut additions = 0;
let mut deletions = 0;

match &self {
Copy link
Collaborator

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.

Copy link
Member Author

@sebastinez sebastinez Oct 2, 2023

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 => {
Copy link
Collaborator

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.

Copy link
Member Author

@sebastinez sebastinez Oct 2, 2023

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.

@sebastinez sebastinez force-pushed the sebastinez/add-line-stats-per-file branch from 41fb18e to 232d503 Compare October 2, 2023 06:44
FintanH
FintanH previously approved these changes Oct 2, 2023
Copy link
Collaborator

@FintanH FintanH left a 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 👍

Comment on lines 108 to 109
additions:2,
deletions:1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
additions:2,
deletions:1
additions: 2,
deletions: 1

Copy link
Member Author

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>
@sebastinez sebastinez force-pushed the sebastinez/add-line-stats-per-file branch from 232d503 to 097d013 Compare October 2, 2023 09:29
@FintanH FintanH merged commit e7e059e into radicle-dev:main Oct 2, 2023
12 checks passed
@sebastinez sebastinez deleted the sebastinez/add-line-stats-per-file branch October 2, 2023 10:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants