Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Commit 948848b

Browse files
authored
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.
1 parent 5bbff91 commit 948848b

File tree

6 files changed

+20
-20
lines changed

6 files changed

+20
-20
lines changed

cmd/gitserver/internal/server_grpc_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,7 @@ func TestGRPCServer_ListRefs(t *testing.T) {
907907
}
908908
if diff := cmp.Diff([]*v1.GitRef{
909909
{
910-
RefName: "refs/heads/master",
910+
RefName: []byte("refs/heads/master"),
911911
CreatedAt: timestamppb.New(time.Time{}),
912912
},
913913
}, refs, cmpopts.IgnoreUnexported(v1.GitRef{}, timestamppb.Timestamp{})); diff != "" {

internal/gitserver/commands_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2067,7 +2067,7 @@ func TestClient_ListRefs(t *testing.T) {
20672067
ss.RecvFunc.SetDefaultReturn(nil, io.EOF)
20682068
ss.RecvFunc.PushReturn(&proto.ListRefsResponse{Refs: []*proto.GitRef{
20692069
{
2070-
RefName: "refs/heads/master",
2070+
RefName: []byte("refs/heads/master"),
20712071
TargetCommit: "deadbeef",
20722072
CreatedAt: timestamppb.New(now),
20732073
},

internal/gitserver/gitdomain/common.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -417,8 +417,8 @@ type Ref struct {
417417

418418
func RefFromProto(r *proto.GitRef) Ref {
419419
return Ref{
420-
Name: r.GetRefName(),
421-
ShortName: r.GetShortRefName(),
420+
Name: string(r.GetRefName()),
421+
ShortName: string(r.GetShortRefName()),
422422
Type: RefTypeFromProto(r.GetRefType()),
423423
CommitID: api.CommitID(r.GetTargetCommit()),
424424
RefOID: api.CommitID(r.GetRefOid()),
@@ -429,8 +429,8 @@ func RefFromProto(r *proto.GitRef) Ref {
429429

430430
func (r *Ref) ToProto() *proto.GitRef {
431431
return &proto.GitRef{
432-
RefName: r.Name,
433-
ShortRefName: r.ShortName,
432+
RefName: []byte(r.Name),
433+
ShortRefName: []byte(r.ShortName),
434434
TargetCommit: string(r.CommitID),
435435
RefOid: string(r.RefOID),
436436
CreatedAt: timestamppb.New(r.CreatedDate),

internal/gitserver/v1/gitserver.pb.go

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/gitserver/v1/gitserver.proto

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,10 +278,10 @@ message ListRefsResponse {
278278

279279
message GitRef {
280280
// ref_name is the unabbreviated name of the reference, i.e., refs/heads/main, or refs/tags/1.0.
281-
string ref_name = 1;
281+
bytes ref_name = 1;
282282
// short_ref_name is the abbreviated name of the reference, if unambiguous.
283283
// I.e., main, or 1.0.
284-
string short_ref_name = 2;
284+
bytes short_ref_name = 2;
285285
// target_commit is the hash of the commit the reference is currently pointing at.
286286
// For a head reference, this is the commit the head is currently pointing at.
287287
// For a tag, this is the commit that the tag is attached to.

internal/gitserver/v1/gitserver_grpc.pb.go

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)