Skip to content

Conversation

cruessler
Copy link
Contributor

This PR adds Repository::blame_file(), reusing the existing feature flag blame. This is the minimal API I was able to come up with.

Open questions

  • The proposed API offers no way for the consumer to influence how odb, cache and resource_cache get created. Is this the correct choice?
  • As opposed to other APIs, e. g. Repository::references, this API is not Platform-based, but directly calls the underlying function. Is this something that should be changed/needs to be changed? What are the trade-offs involved?
  • There’s other APIs that provide a recorder-based API, such as gix_diff::tree, allowing consumers to process the API’s output one-by-one while also allowing them to cancel it after each piece of output. Is that something we might want for gix_blame::file() and, if so, would we have to account for that in this initial version of Repository::blame_file()?
  • Is there anything that needs to be done in order for the tests in gix/tests/gix/repository/blame.rs to be run on CI? I’m asking because the code I added is behind a feature flag.

@Byron Byron marked this pull request as draft September 6, 2025 13:42
Copy link
Member

@Byron Byron left a comment

Choose a reason for hiding this comment

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

Thanks a lot for tackling this! Note that I put the PR back into draft while CI is failing and there are questions.

This PR adds Repository::blame_file(), reusing the existing feature flag blame. This is the minimal API I was able to come up with.

I think this works, the feature-flag usage is great, and the API is exactly what it should be - minimal and to the point. If there are other uses that need more control, they can easily use gix_blame directly, or one could offer a blame_opt() of sort that has more parameters.

Open questions

  • The proposed API offers no way for the consumer to influence how odb, cache and resource_cache get created. Is this the correct choice?
    A good start, let's keep it simple until there is demand.
  • As opposed to other APIs, e. g. Repository::references, this API is not Platform-based, but directly calls the underlying function. Is this something that should be changed/needs to be changed? What are the trade-offs involved?

It's not obvious to me how a platform would be helpful here, which probably means there should be none.

  • There’s other APIs that provide a recorder-based API, such as gix_diff::tree, allowing consumers to process the API’s output one-by-one while also allowing them to cancel it after each piece of output. Is that something we might want for gix_blame::file() and, if so, would we have to account for that in this initial version of Repository::blame_file()?

We talked about the final-fancy version of gix-blame which would be far more complex, but while we don't have it, we should keep it simple.

  • Is there anything that needs to be done in order for the tests in gix/tests/gix/repository/blame.rs to be run on CI? I’m asking because the code I added is behind a feature flag.

Let's skip the tests, they seem redundant.

@@ -0,0 +1,43 @@
#[cfg(feature = "blame")]
Copy link
Member

Choose a reason for hiding this comment

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

Since the whole module is behind a feature toggle, that toggle doesn't need to be used inside of it anymore.

Copy link
Member

Choose a reason for hiding this comment

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

I don't know if I'd test anything here as the method itself is really just a forwarding. Probably it's good to avoid duplication unless we know what specific thing we should test.

In theory, we could start adding doc-tests, then redundancy doesn't matter as the purpose is to inform the user, but it's by no means an obligation as they are quite cumbersome to make look nice.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These tests indeed duplicate tests found elsewhere. I mainly added them to make sure that the whole gix::Repository::blame_file API could be used only relying on imports from gix. Feel free to remove them if you think they’re redundant!

Comment on lines 14 to 21
pub enum Error {
#[error(transparent)]
CommitGraphIfEnabled(#[from] commit_graph_if_enabled::Error),
#[error(transparent)]
DiffResourceCache(#[from] diff_resource_cache::Error),
#[error(transparent)]
Blame(#[from] gix_blame::Error),
}
Copy link
Member

Choose a reason for hiding this comment

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

In the absence of custom 'connected' blame related types, I think this whole module should be in gix::repository::blame, with the error type 'where the other errors types are' - there is pattern for this.

Alternatively gix_blame::Outcome would have to be turned into a duplicate structure with a reference to repo: &Repository, which doesn't seem worth it - it's the bane of the gix crate as it always has to repeat whole types just to add some convenience.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I’ve moved the enum, following the example of diff_tree_to_tree::Error and others. Was that correct?

@cruessler cruessler force-pushed the add-blame-file-on-repository branch from 75c4156 to cdb1100 Compare September 6, 2025 16:53
@cruessler
Copy link
Contributor Author

From my side, this PR is now ready for review!

@Byron Byron marked this pull request as ready for review September 7, 2025 08:03
@Byron Byron force-pushed the add-blame-file-on-repository branch from d32ce8a to 3c54e5b Compare September 7, 2025 08:09
@Byron
Copy link
Member

Byron commented Sep 7, 2025

That's perfect, thanks so much!

And yes, the test is definitely good to see how to access the return type, and I am grateful that you moved them instead of removing them as originally suggested.

@Byron Byron enabled auto-merge September 7, 2025 08:10
@Byron Byron merged commit bd47fb5 into GitoxideLabs:main Sep 7, 2025
25 checks passed
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