Skip to content

Commit

Permalink
gitserver: protobuf: relax ArchiveRequest path fields to be bytes i…
Browse files Browse the repository at this point in the history
…nstead of `string` (#61970)

commit-id:582a4b96
(cherry picked from commit 6a0c465)
  • Loading branch information
ggilmore committed Apr 17, 2024
1 parent 1dbec80 commit 3d7b26f
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 11 deletions.
4 changes: 2 additions & 2 deletions cmd/gitserver/internal/server_grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ func (gs *grpcServer) Archive(req *proto.ArchiveRequest, ss proto.GitserverServi
accesslog.Record(ctx, req.GetRepo(),
log.String("treeish", req.GetTreeish()),
log.String("format", string(format)),
log.Strings("path", req.GetPaths()),
log.Strings("path", byteSlicesToStrings(req.GetPaths())),
)

repoName := api.RepoName(req.GetRepo())
Expand Down Expand Up @@ -289,7 +289,7 @@ func (gs *grpcServer) Archive(req *proto.ArchiveRequest, ss proto.GitserverServi

backend := gs.getBackendFunc(repoDir, repoName)

r, err := backend.ArchiveReader(ctx, format, req.GetTreeish(), req.GetPaths())
r, err := backend.ArchiveReader(ctx, format, req.GetTreeish(), byteSlicesToStrings(req.GetPaths()))
if err != nil {
if os.IsNotExist(err) {
var path string
Expand Down
30 changes: 25 additions & 5 deletions internal/gitserver/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,17 @@ type CommitLog struct {

// ArchiveOptions contains options for the Archive func.
type ArchiveOptions struct {
Treeish string // the tree or commit to produce an archive for
Format ArchiveFormat // format of the resulting archive (usually "tar" or "zip")
Paths []string // if nonempty, only include these paths.
// Treeish is the tree or commit to produce an archive for
Treeish string
// Format is the format of the resulting archive (usually "tar" or "zip")
Format ArchiveFormat
// Paths is a list of paths to include in the archive. If empty, the entire
// repository is included.
//
// Note: The Path strings are not guaranteed to be UTF-8 encoded, as file paths
// on Linux can be arbitrary byte sequences. Users should take care to validate / sanitize
// paths if necessary.
Paths []string
}

func (a *ArchiveOptions) Attrs() []attribute.KeyValue {
Expand All @@ -275,19 +283,31 @@ func (a *ArchiveOptions) Attrs() []attribute.KeyValue {
}

func (o *ArchiveOptions) FromProto(x *proto.ArchiveRequest) {
protoPaths := x.GetPaths()

paths := make([]string, len(protoPaths))
for i, p := range protoPaths {
paths[i] = string(p)
}

*o = ArchiveOptions{
Treeish: x.GetTreeish(),
Format: ArchiveFormatFromProto(x.GetFormat()),
Paths: x.GetPaths(),
Paths: paths,
}
}

func (o *ArchiveOptions) ToProto(repo string) *proto.ArchiveRequest {
paths := make([][]byte, len(o.Paths))
for i, p := range o.Paths {
paths[i] = []byte(p)
}

return &proto.ArchiveRequest{
Repo: repo,
Treeish: o.Treeish,
Format: o.Format.ToProto(),
Paths: o.Paths,
Paths: paths,
}
}

Expand Down
6 changes: 3 additions & 3 deletions internal/gitserver/v1/gitserver.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/gitserver/v1/gitserver.proto
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ message ArchiveRequest {
ArchiveFormat format = 3;
// paths is the list of paths to include in the archive. If empty, all
// paths are included.
repeated string paths = 4;
repeated bytes paths = 4;
}

// ArchiveResponse is the response from the Archive RPC that returns a chunk of
Expand Down

0 comments on commit 3d7b26f

Please sign in to comment.