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

Support for packed refs #2121

Merged
merged 5 commits into from May 25, 2023
Merged

Support for packed refs #2121

merged 5 commits into from May 25, 2023

Conversation

saquibmian
Copy link
Contributor

This PR also combines git.*Iterator into a git.Repository and make the construction of the ObjectReader internal to it. Now there is a single exported method that takes in the .git path.

This also opens us up to provide the git.Repository#URL method soon.

This PR also combines `git.*Iterator` into a `git.Repository` and make
the construction of the `ObjectReader` internal to it. Now there is a
single exported method that takes in the `.git` path.

This also opens us up to provide the `git.Repository#URL` method soon.
@saquibmian
Copy link
Contributor Author

Sorry for the poor diff, the vast majority of the code has already been reviewed by you two! Let me know if you'd like me to break this apart instead (merging first, then support packed refs).

@bufdev
Copy link
Member

bufdev commented May 25, 2023

@unmultimedio see if you can get through it without @saquibmian having to split anything up

Copy link
Member

@unmultimedio unmultimedio left a comment

Choose a reason for hiding this comment

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

Seems to me like reading commits and tags should be done also in a sync.Once, and all of them should be stored in memory in the repository object?

Also, probably if you have local git history, it'd be a bit easier to separate in commits the iterators interfaces merge, vs the actual packed logic, so the diff is a bit cleaner. If it's not a big deal, it'd help quite a bit.

Comment on lines +260 to +263
// BaseBranch is the base branch of the repository. This is either configured
// via the `OpenRepositoryWithBaseBranch` option, or discovered via the remote
// named `origin`. Therefore, discovery requires that the repository is pushed
// to the remote.
Copy link
Member

Choose a reason for hiding this comment

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

Should we default to main in case it's neither pushed nor configured?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ideally we auto discover as much as we can, but in the cases where we can't, I can see a buf sync --main-branch develop to help with this.

Copy link
Member

Choose a reason for hiding this comment

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

Should this be a flag or a config in buf.yaml? It feels to me like this is a reasonable use-case for extending the config file since we already have BSR repository related config (e.g. name) in the config.

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 think when this came up at some point, we talked about storing refspecs in the buf.yaml and it was shot down? It was before my time, but I remember reading it and now I can't find it.

I think this is not module config, this is sync config. We already somewhat ignore the name in buf.yaml in sync world (because names can change over time), which I think is step in the right direction.

Generally, the less config we have, the more we've won with buf sync.

Copy link
Member

Choose a reason for hiding this comment

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

Fair enough -- I am onboard with this approach :)

private/pkg/git/gittest/gittest.go Outdated Show resolved Hide resolved
if err != nil {
return nil, nil, err
}
if strings.HasPrefix(ref, originBranchRefPrefix) {
Copy link
Member

Choose a reason for hiding this comment

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

So only tags, and branches in remotes named origin will be read, why? If so pls document it (and the why) in the func godoc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is documented in the godoc for ForEachBranch. As for why, it's because we only want to sync state that's been pushed, we don't want to sync state that is local. For tags I haven't found a way to determine if a tag is pushed yet.

Copy link
Member

Choose a reason for hiding this comment

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

If we can execute git commands, we could fetch origin tags and only loop remote tags? Although, outside of this PR scope.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup, but ideally I can find a way to do that without forking out to git.

private/pkg/git/packed_refs.go Outdated Show resolved Hide resolved
private/pkg/git/packed_refs.go Outdated Show resolved Hide resolved
private/pkg/git/testdata/packed-refs Show resolved Hide resolved
private/pkg/git/repository.go Show resolved Hide resolved
private/pkg/git/repository.go Show resolved Hide resolved
private/pkg/git/repository.go Show resolved Hide resolved
@saquibmian
Copy link
Contributor Author

We could definitely read unpacked branches and tags in the sync.Once as well, I mainly didn't want to add too much to this PR. I am planning on caching those as well as all objectReader in one of the later milestones.

Commits/trees/blobs will be cached by the object reader cache, the core algorithm itself is not worth caching as a particular commit tree will likely not be visited more than once.

private/pkg/git/testdata/packed-refs Outdated Show resolved Hide resolved
private/pkg/git/testdata/packed-refs Outdated Show resolved Hide resolved
@saquibmian saquibmian merged commit 0674e84 into main May 25, 2023
6 checks passed
@saquibmian saquibmian deleted the smian/packed-refs branch May 25, 2023 19:42
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.

None yet

4 participants