-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
gitparse: Use an object for currentDiff #1573
Conversation
This reverts commit c5f0708.
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.
one question, otherwise looks gucci
@@ -309,8 +309,8 @@ func (c *Parser) FromReader(ctx context.Context, stdOut io.Reader, commitChan ch | |||
if currentCommit == nil { | |||
currentCommit = &Commit{} | |||
} | |||
if currentDiff != nil && currentDiff.Content.Len() > 0 { | |||
currentCommit.Diffs = append(currentCommit.Diffs, *currentDiff) | |||
if currentDiff.Content.Len() > 0 { |
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.
why does making it an object allow us to avoid nil checking? is it just going to default to an empty 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.
Yep. When its initialized it is an empty struct instead of a pointer to 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.
In this case @bill-rich would it be a pointer to nil or a nil pointer? I think the latter?
This is my understanding:
var i *int = nil // i is a nil pointer
var p **int = &i // p is a pointer to a nil pointer || closest thing to pointer to nil lol
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're right. I worded that poorly (wrong). Should have been "pointing to 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 lgtm and i'm assuming it doesn't run afoul of @bill-rich's commentary re: pointers on #1570 (because he's commenting here without objecting) but maybe check with him if you haven't already
yep, chatted out-of-band and we were already making a copy when we dereferenced it to put in the channel. |
This is safer than relying on state to ensure we don't get a nil pointer dereference.