gitserver: Allow non-utf-8 refnames in ListRefs API (#61988)

We recently saw an alert for this on dotcom, refnames can be non utf-8 as well so we have to switch to bytes for this field.

Test plan:

Round trip test still passes.
This commit is contained in:
Erik Seliger 2024-04-18 16:46:08 +02:00 committed by GitHub
parent 5bbff91e1a
commit 948848bca6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 20 additions and 20 deletions

View File

@ -907,7 +907,7 @@ func TestGRPCServer_ListRefs(t *testing.T) {
}
if diff := cmp.Diff([]*v1.GitRef{
{
RefName: "refs/heads/master",
RefName: []byte("refs/heads/master"),
CreatedAt: timestamppb.New(time.Time{}),
},
}, refs, cmpopts.IgnoreUnexported(v1.GitRef{}, timestamppb.Timestamp{})); diff != "" {

View File

@ -2067,7 +2067,7 @@ func TestClient_ListRefs(t *testing.T) {
ss.RecvFunc.SetDefaultReturn(nil, io.EOF)
ss.RecvFunc.PushReturn(&proto.ListRefsResponse{Refs: []*proto.GitRef{
{
RefName: "refs/heads/master",
RefName: []byte("refs/heads/master"),
TargetCommit: "deadbeef",
CreatedAt: timestamppb.New(now),
},

View File

@ -417,8 +417,8 @@ type Ref struct {
func RefFromProto(r *proto.GitRef) Ref {
return Ref{
Name: r.GetRefName(),
ShortName: r.GetShortRefName(),
Name: string(r.GetRefName()),
ShortName: string(r.GetShortRefName()),
Type: RefTypeFromProto(r.GetRefType()),
CommitID: api.CommitID(r.GetTargetCommit()),
RefOID: api.CommitID(r.GetRefOid()),
@ -429,8 +429,8 @@ func RefFromProto(r *proto.GitRef) Ref {
func (r *Ref) ToProto() *proto.GitRef {
return &proto.GitRef{
RefName: r.Name,
ShortRefName: r.ShortName,
RefName: []byte(r.Name),
ShortRefName: []byte(r.ShortName),
TargetCommit: string(r.CommitID),
RefOid: string(r.RefOID),
CreatedAt: timestamppb.New(r.CreatedDate),

View File

@ -796,10 +796,10 @@ type GitRef struct {
unknownFields protoimpl.UnknownFields
// ref_name is the unabbreviated name of the reference, i.e., refs/heads/main, or refs/tags/1.0.
RefName string `protobuf:"bytes,1,opt,name=ref_name,json=refName,proto3" json:"ref_name,omitempty"`
RefName []byte `protobuf:"bytes,1,opt,name=ref_name,json=refName,proto3" json:"ref_name,omitempty"`
// short_ref_name is the abbreviated name of the reference, if unambiguous.
// I.e., main, or 1.0.
ShortRefName string `protobuf:"bytes,2,opt,name=short_ref_name,json=shortRefName,proto3" json:"short_ref_name,omitempty"`
ShortRefName []byte `protobuf:"bytes,2,opt,name=short_ref_name,json=shortRefName,proto3" json:"short_ref_name,omitempty"`
// target_commit is the hash of the commit the reference is currently pointing at.
// For a head reference, this is the commit the head is currently pointing at.
// For a tag, this is the commit that the tag is attached to.
@ -849,18 +849,18 @@ func (*GitRef) Descriptor() ([]byte, []int) {
return file_gitserver_proto_rawDescGZIP(), []int{7}
}
func (x *GitRef) GetRefName() string {
func (x *GitRef) GetRefName() []byte {
if x != nil {
return x.RefName
}
return ""
return nil
}
func (x *GitRef) GetShortRefName() string {
func (x *GitRef) GetShortRefName() []byte {
if x != nil {
return x.ShortRefName
}
return ""
return nil
}
func (x *GitRef) GetTargetCommit() string {
@ -6533,9 +6533,9 @@ var file_gitserver_proto_rawDesc = []byte{
0x14, 0x2e, 0x67, 0x69, 0x74, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2e, 0x76, 0x31, 0x2e, 0x47,
0x69, 0x74, 0x52, 0x65, 0x66, 0x52, 0x04, 0x72, 0x65, 0x66, 0x73, 0x22, 0xe0, 0x02, 0x0a, 0x06,
0x47, 0x69, 0x74, 0x52, 0x65, 0x66, 0x12, 0x19, 0x0a, 0x08, 0x72, 0x65, 0x66, 0x5f, 0x6e, 0x61,
0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x72, 0x65, 0x66, 0x4e, 0x61, 0x6d,
0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x72, 0x65, 0x66, 0x4e, 0x61, 0x6d,
0x65, 0x12, 0x24, 0x0a, 0x0e, 0x73, 0x68, 0x6f, 0x72, 0x74, 0x5f, 0x72, 0x65, 0x66, 0x5f, 0x6e,
0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x73, 0x68, 0x6f, 0x72, 0x74,
0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0c, 0x73, 0x68, 0x6f, 0x72, 0x74,
0x52, 0x65, 0x66, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x23, 0x0a, 0x0d, 0x74, 0x61, 0x72, 0x67, 0x65,
0x74, 0x5f, 0x63, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c,
0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x12, 0x17, 0x0a, 0x07,

View File

@ -278,10 +278,10 @@ message ListRefsResponse {
message GitRef {
// ref_name is the unabbreviated name of the reference, i.e., refs/heads/main, or refs/tags/1.0.
string ref_name = 1;
bytes ref_name = 1;
// short_ref_name is the abbreviated name of the reference, if unambiguous.
// I.e., main, or 1.0.
string short_ref_name = 2;
bytes short_ref_name = 2;
// target_commit is the hash of the commit the reference is currently pointing at.
// For a head reference, this is the commit the head is currently pointing at.
// For a tag, this is the commit that the tag is attached to.

View File

@ -69,8 +69,8 @@ type GitserverServiceClient interface {
// currently not filter parts of the archive, so this would be considered
// leaking information.
//
// If the given treeish does not exist, an error with a
// RevisionNotFoundPayload is returned.
// If the given treeish does not exist, an error with a RevisionNotFoundPayload
// is returned.
//
// If the given repo is not cloned, it will be enqueued for cloning and a
// NotFound error will be returned, with a RepoNotFoundPayload in the details.
@ -668,8 +668,8 @@ type GitserverServiceServer interface {
// currently not filter parts of the archive, so this would be considered
// leaking information.
//
// If the given treeish does not exist, an error with a
// RevisionNotFoundPayload is returned.
// If the given treeish does not exist, an error with a RevisionNotFoundPayload
// is returned.
//
// If the given repo is not cloned, it will be enqueued for cloning and a
// NotFound error will be returned, with a RepoNotFoundPayload in the details.