Skip to content

surf: Add stats property to each DiffContent::Plain#145

Merged
FintanH merged 1 commit intoradicle-dev:mainfrom
sebastinez:sebastinez/add-line-stats-per-file
Oct 2, 2023
Merged

surf: Add stats property to each DiffContent::Plain#145
FintanH merged 1 commit intoradicle-dev:mainfrom
sebastinez:sebastinez/add-line-stats-per-file

Conversation

@sebastinez
Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor 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 ✅

old_missing_eof = true;
continue;
},
git2::DiffLineType::Addition => {
Copy link
Copy Markdown
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
Copy Markdown
Contributor 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
@sebastinez sebastinez requested a review from FintanH October 2, 2023 06:51
FintanH
FintanH previously approved these changes Oct 2, 2023
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor 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
@sebastinez sebastinez requested a review from FintanH October 2, 2023 09:29
@FintanH FintanH merged commit e7e059e into radicle-dev:main Oct 2, 2023
@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