Skip to content
This repository has been archived by the owner on Jul 27, 2023. It is now read-only.

Add a associated function to surf::diff::Diff that allows us to generate source::commit::Stats over two commits #205

Open
sebastinez opened this issue Jul 7, 2022 · 6 comments
Assignees
Labels
enhancement New feature or request

Comments

@sebastinez
Copy link
Member

Hello everyone,

So I wanted to propose here, that we should add an associated function to surf::diff::Diff that would allow us to generate a source::commit::Stats.

Currently it is possible to generate a surf::diff::Diff through e.g.

pub fn diff(&self, from: Oid, to: Oid) -> Result<Diff, Error> {

But we don't have any function that would calculate the amount of additions and deletions that happened between those commits.

I'm thinking we should be able to convert the additions, deletions loops from here

pub fn commit(browser: &mut Browser<'_>, sha1: git2::Oid) -> Result<Commit, Error> {

into the mentioned associated function.

@sebastinez sebastinez added the enhancement New feature or request label Jul 7, 2022
@sebastinez sebastinez changed the title Add a stats associated function to surf::diff::Diff Add a associated function to surf::diff::Diff that allows us to generate source::commit::Stats over two commits Jul 7, 2022
@FintanH
Copy link
Collaborator

FintanH commented Jul 7, 2022

Ya, that makes sense to me. So we would actually move the source::commit::Stats type into surf::diff. I'm wondering if it would make sense to calculate the Stats while building the Diff, so it just becomes associated data rather than an associated computation. The proposed function would just be an accessor then :)

@sebastinez
Copy link
Member Author

I'm wondering if it would make sense to calculate the Stats while building the Diff.

Yeah that sounds great to me 👍 Would provide a PR for that

@FintanH
Copy link
Collaborator

FintanH commented Jul 7, 2022

Thanks, @sebastinez! Appreciate the suggestion and the follow-up 😊

@sebastinez
Copy link
Member Author

sebastinez commented Jul 8, 2022

I'm wondering if it would make sense to calculate the Stats while building the Diff, so it just becomes associated data rather than an associated computation.

I did some more thinking maybe if we leave it as an associated computation, one could opt in if needed.
Also I like the structure of the surf::diff::Diff and wouldn't change it.

@FintanH
Copy link
Collaborator

FintanH commented Jul 8, 2022

I did some more thinking maybe if we leave it as an associated computation, one could opt in if needed.

What's the con of not having it?

I would think it's cheap to carry in the diff itself as a sub-struct since it's only two u64's. Is there something I'm missing?

@cloudhead
Copy link
Contributor

Yeah since it's really cheap I don't think it's so useful to be able to opt-out?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants