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

git: Fix fetching after shallow clone. Fixes #305 #766

Closed

Conversation

AriehSchneier
Copy link
Contributor

@AriehSchneier AriehSchneier commented May 10, 2023

Also fixes #207

@@ -864,6 +865,21 @@ func getHavesFromRef(
toVisit := maxHavesToVisitPerRef
return walker.ForEach(func(c *object.Commit) error {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Another option would be just to completely ignore any errors returned from this walker.ForEach call.

Copy link
Member

@pjbgf pjbgf left a comment

Choose a reason for hiding this comment

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

The boolean is redundant, so I would use struct{} instead for a slight smaller memory profile.

remote.go Outdated Show resolved Hide resolved
remote.go Outdated Show resolved Hide resolved
remote.go Outdated Show resolved Hide resolved
remote.go Outdated Show resolved Hide resolved
remote.go Outdated Show resolved Hide resolved
Copy link
Member

@pjbgf pjbgf left a comment

Choose a reason for hiding this comment

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

Had another go at it and found a few other nits below.

@@ -864,6 +865,21 @@ func getHavesFromRef(
toVisit := maxHavesToVisitPerRef
return walker.ForEach(func(c *object.Commit) error {
haves[c.Hash] = true

// initialise the shallows map
if *shallows == nil {
Copy link
Member

Choose a reason for hiding this comment

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

Deferencing a nil pointer leads to panic.

Suggested change
if *shallows == nil {
if shallows == nil {

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 a private function that we only call in 1 location, it will also contain a value (I would have passed by reference if go had that feature but it doesn't). We need to check whether the location that this variable is pointing to is nil or not. I could change this to if shallows != nil && *shallows != nil { but IMHO that would add an extra unnecessary check.

@@ -837,6 +837,7 @@ func getHavesFromRef(
remoteRefs map[plumbing.Hash]bool,
s storage.Storer,
haves map[plumbing.Hash]bool,
shallows *map[plumbing.Hash]struct{},
Copy link
Member

Choose a reason for hiding this comment

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

This will inevitably be passed "by reference".

Suggested change
shallows *map[plumbing.Hash]struct{},
shallows map[plumbing.Hash]struct{},

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

PS if you test your suggested change you will find that nil will always be passed in and we will recalculate the map for every iteration of range localRefs

Copy link
Member

Choose a reason for hiding this comment

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

You are absolutely right, thanks for sharing the link. 👍

// initialise the shallows map
if *shallows == nil {
shallowList, _ := s.Shallow()
*shallows = make(map[plumbing.Hash]struct{}, len(shallowList))
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
*shallows = make(map[plumbing.Hash]struct{}, len(shallowList))
shallows = make(map[plumbing.Hash]struct{}, len(shallowList))

shallowList, _ := s.Shallow()
*shallows = make(map[plumbing.Hash]struct{}, len(shallowList))
for _, sh := range shallowList {
(*shallows)[sh] = struct{}{}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
(*shallows)[sh] = struct{}{}
shallows[sh] = struct{}{}

}

// If this is a shallow reference don't try to iterate further
if _, ok := (*shallows)[c.Hash]; ok {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if _, ok := (*shallows)[c.Hash]; ok {
if _, ok := shallows[c.Hash]; ok {

@@ -899,7 +918,7 @@ func getHaves(
continue
}

err = getHavesFromRef(ref, remoteRefs, s, haves)
err = getHavesFromRef(ref, remoteRefs, s, haves, &shallows)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
err = getHavesFromRef(ref, remoteRefs, s, haves, &shallows)
err = getHavesFromRef(ref, remoteRefs, s, haves, shallows)

Copy link
Member

@pjbgf pjbgf left a comment

Choose a reason for hiding this comment

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

Had another go at it and found a few other nits below.

Signed-off-by: Arieh Schneier <15041913+AriehSchneier@users.noreply.github.com>
@pjbgf
Copy link
Member

pjbgf commented May 24, 2023

Closing this in favour of #778

@pjbgf pjbgf closed this May 24, 2023
@AriehSchneier AriehSchneier deleted the fix-fetch-after-shallow branch May 27, 2023 09:44
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.

Pull returns object not found
2 participants