-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
gitserver: port FirstEverCommit functionality from client to git cli backend #62165
gitserver: port FirstEverCommit functionality from client to git cli backend #62165
Conversation
0b26aab
to
2443801
Compare
01ed324
to
9147a1a
Compare
9147a1a
to
732f339
Compare
2443801
to
5d7fa42
Compare
732f339
to
bf4e953
Compare
5d7fa42
to
772f91b
Compare
bf4e953
to
cf13ed9
Compare
cf13ed9
to
26d91b0
Compare
var cmdFailedErr *CommandFailedError | ||
if errors.As(err, &cmdFailedErr) { | ||
if cmdFailedErr.ExitStatus == 129 && bytes.Contains(cmdFailedErr.Stderr, []byte(revListUsageString)) { | ||
// If the error is due to an empty repository, return a sentinel 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.
This exit condition comes from https://sourcegraph.com/github.com/git/git@bf995e7a4f94a9388aa8042dc9e338f3fcb75496/-/blob/builtin/rev-list.c?L701-706 in the source I believe.
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.
strange that it'd print the usage 😬 but thanks for the link, very helpful!
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 quite brittle, as any unrelated formatting change with our errors could change the semantics here. I decided to create a new sentinel error for this condition, gitdomain.RepoEmptyErr, to 1) better state our intent and 2) make this check more robust against minor formatting changes in our error libraries. When we generate the gRPC bindings, we'll need to create a new protobuf message for this error and write ToProto/FromProto functions, etc.
Strongly agree that no caller should depend on any git error message. We want to fully own the process of potentially switching to go-git, libgit2, or any self-made implementations that will yield different error strings.
One question - in alignment with gRPC saying "there should not be too many different error codes, because callers will most likely not add more than a few checks", should we try to keep the error types in check as well, and repurpose the RevisionNotFoundError
here?
I think it's technically a correct error, since FirstEverCommit would try to look at HEAD, HEAD resolves to no branch yet, so HEAD is not found?
if strings.Contains(err.Error(), emptyRepoErrMessage) { | ||
return true |
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.
Should we remove this, after the gRPC API PR is merged? Once the client makes use of the gRPC API there's no way this could still be returned.
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.
Ping :)
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.
var cmdFailedErr *CommandFailedError | ||
if errors.As(err, &cmdFailedErr) { | ||
if cmdFailedErr.ExitStatus == 129 && bytes.Contains(cmdFailedErr.Stderr, []byte(revListUsageString)) { | ||
// If the error is due to an empty repository, return a sentinel 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.
strange that it'd print the usage 😬 but thanks for the link, very helpful!
78388ea
to
1bbfc10
Compare
1bbfc10
to
521a52c
Compare
521a52c
to
05a1f32
Compare
05a1f32
to
0dbd2b6
Compare
if strings.Contains(err.Error(), emptyRepoErrMessage) { | ||
return true |
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.
Ping :)
0dbd2b6
to
dd47983
Compare
0a3ffb5
to
a8d5080
Compare
a8d5080
to
df87c59
Compare
Part of #61689
Overview
This PR adapts the existing FirstEverCommit logic from the gitserver client to our new git cli backend. This is the first step as part of a set of stacked PRs to port the functionality to gRPC.
Existing
func (c *clientImplementor) FirstEverCommit()
implementation for reference:sourcegraph/internal/gitserver/commands.go
Lines 1734 to 1757 in 412654f
Note
One of the existing tests that I ported called out that code insights depended on the formatting of a specific error string in order to detect if the repository was empty.
(Test in question):
sourcegraph/internal/gitserver/commands_test.go
Lines 721 to 729 in 948848b
(String checking logic in code insights):
https://github.com/sourcegraph/sourcegraph/blob/2443801b4ea4a4d48a8badf3c34ed2761af65db4/internal/insights/gitserver/first_commit.go#L18-L38
This is quite brittle, as any unrelated formatting change with our errors could change the semantics here. I decided to create a new sentinel error for this condition,
gitdomain.RepoEmptyErr
, to 1) better state our intent and 2) make this check more robust against minor formatting changes in our error libraries. When we generate the gRPC bindings, we'll need to create a new protobuf message for this error and writeToProto/FromProto
functions, etc.Test plan
Adapted existing unit tests