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

Export git.handleBinary and getSafeRemoteURL #3921

Merged
merged 4 commits into from
Feb 19, 2025
Merged

Conversation

rosecodym
Copy link
Collaborator

@rosecodym rosecodym commented Feb 18, 2025

Description:

This PR exports some functionality from the git source so that it's usable in a (new, under development) git-flavored source that does not need to wrap an entire git source in order to operate.

One is getSafeRemoteURL. This is a straightforward change.

The other is handleBinary. Right now, all git binary file handling is invoked from Git.ScanRepo, which is itself invoked by our various git-flavored sources.

Since the actual binary file handling function handleBinary only used two pieces of information from the "git" source, I just removed its receiver. One of the pieces of information was a flag that caused the function to be skipped entirely; I moved this one to the (two) call sites. The other I just forwarded as an argument.

Checklist:

  • Tests passing (make test-community)?
  • Lint passing (make lint this requires golangci-lint)?

@rosecodym rosecodym requested review from a team as code owners February 18, 2025 20:02
@rosecodym rosecodym changed the title Extract handleBinary Export/free handleBinary Feb 18, 2025
@rosecodym rosecodym changed the title Export/free handleBinary Export git.handleBinary and getSafeRemoteURL Feb 18, 2025
Comment on lines +645 to +652
commitHash := plumbing.NewHash(fullHash)

if s.skipBinaries || feature.ForceSkipBinaries.Load() {
logger.V(5).Info("skipping binary file",
"commit", commitHash.String()[:7],
"path", path)
continue
}
Copy link
Contributor

Choose a reason for hiding this comment

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

If the use of this chunk of code grew to more than two places, would you write a separate function for it?

Copy link
Collaborator Author

@rosecodym rosecodym Feb 19, 2025

Choose a reason for hiding this comment

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

Great question! I would certainly consider it - three is a good threshold for that. In this particular case I might not, though, because the repetitive code is so small and simple. I would still need to invoke the new function from each of these call sites, and doing that wouldn't be more much code than just inlining the logic the way it's done here. And since the extracted function itself wouldn't need much updating, there wouldn't be much of a maintainability benefit to extracting it.

Zooming out, I think the fact that we have to consider these questions is itself a bit of a code smell that suggests that some re-architecture might be warranted. (However, doing that would be substantial, risky effort, so it might not be warranted!)

@rosecodym rosecodym merged commit 160f1a4 into main Feb 19, 2025
13 checks passed
@rosecodym rosecodym deleted the extract-handle-binary branch February 19, 2025 21:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants