-
Notifications
You must be signed in to change notification settings - Fork 702
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
Conversation
@@ -864,6 +865,21 @@ func getHavesFromRef( | |||
toVisit := maxHavesToVisitPerRef | |||
return walker.ForEach(func(c *object.Commit) error { |
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
8336a5d
to
973deae
Compare
There was a problem hiding this 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 { |
There was a problem hiding this comment.
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.
if *shallows == nil { | |
if shallows == nil { |
There was a problem hiding this comment.
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{}, |
There was a problem hiding this comment.
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".
shallows *map[plumbing.Hash]struct{}, | |
shallows map[plumbing.Hash]struct{}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
*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{}{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(*shallows)[sh] = struct{}{} | |
shallows[sh] = struct{}{} |
} | ||
|
||
// If this is a shallow reference don't try to iterate further | ||
if _, ok := (*shallows)[c.Hash]; ok { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
err = getHavesFromRef(ref, remoteRefs, s, haves, &shallows) | |
err = getHavesFromRef(ref, remoteRefs, s, haves, shallows) |
There was a problem hiding this 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.
973deae
to
254c9e4
Compare
Signed-off-by: Arieh Schneier <15041913+AriehSchneier@users.noreply.github.com>
254c9e4
to
05da5ef
Compare
Closing this in favour of #778 |
Also fixes #207