mirror of
https://codeberg.org/git-pages/git-pages.git
synced 2026-08-17 09:26:04 +00:00
Use int64, not uint32, for sizes in the manifest.
This change eliminates a number of rather sketchy casts. This conversion is a no-op for the wire format, explicitly per Protobuf documentation.
This commit is contained in:
+3
-3
@@ -58,12 +58,12 @@ func ExtractTar(reader io.Reader) (*Manifest, error) {
|
||||
}
|
||||
|
||||
manifestEntry.Type = Type_InlineFile.Enum()
|
||||
manifestEntry.Size = proto.Uint32(uint32(header.Size))
|
||||
manifestEntry.Size = proto.Int64(header.Size)
|
||||
manifestEntry.Data = fileData
|
||||
|
||||
case tar.TypeSymlink:
|
||||
manifestEntry.Type = Type_Symlink.Enum()
|
||||
manifestEntry.Size = proto.Uint32(uint32(header.Size))
|
||||
manifestEntry.Size = proto.Int64(header.Size)
|
||||
manifestEntry.Data = []byte(header.Linkname)
|
||||
|
||||
case tar.TypeDir:
|
||||
@@ -145,7 +145,7 @@ func ExtractZip(reader io.Reader) (*Manifest, error) {
|
||||
}
|
||||
|
||||
manifestEntry.Type = Type_InlineFile.Enum()
|
||||
manifestEntry.Size = proto.Uint32(uint32(file.UncompressedSize64))
|
||||
manifestEntry.Size = proto.Int64(int64(file.UncompressedSize64))
|
||||
manifestEntry.Data = fileData
|
||||
} else {
|
||||
manifestEntry.Type = Type_Directory.Enum()
|
||||
|
||||
+1
-1
@@ -101,7 +101,7 @@ func FetchRepository(ctx context.Context, repoURL string, branch string) (*Manif
|
||||
} else {
|
||||
manifestEntry.Type = Type_InlineFile.Enum()
|
||||
}
|
||||
manifestEntry.Size = proto.Uint32(uint32(blob.Size))
|
||||
manifestEntry.Size = proto.Int64(blob.Size)
|
||||
manifestEntry.Data = data
|
||||
} else if entry.Mode == filemode.Dir {
|
||||
manifestEntry.Type = Type_Directory.Enum()
|
||||
|
||||
+4
-4
@@ -131,14 +131,14 @@ func CompressFiles(ctx context.Context, manifest *Manifest) {
|
||||
span, _ := ObserveFunction(ctx, "CompressFiles")
|
||||
defer span.Finish()
|
||||
|
||||
var originalSize, transformedSize uint32
|
||||
var originalSize, transformedSize int64
|
||||
for _, entry := range manifest.Contents {
|
||||
if entry.GetType() == Type_InlineFile && entry.GetXfrm() == Transform_None {
|
||||
originalSize += entry.GetSize()
|
||||
compressedData := zstdEncoder.EncodeAll(entry.GetData(), make([]byte, 0, entry.GetSize()))
|
||||
if len(compressedData) < int(*entry.Size) {
|
||||
entry.Data = compressedData
|
||||
entry.Size = proto.Uint32(uint32(len(entry.Data)))
|
||||
entry.Size = proto.Int64(int64(len(entry.Data)))
|
||||
entry.Xfrm = Transform_Zstandard.Enum()
|
||||
}
|
||||
transformedSize += entry.GetSize()
|
||||
@@ -186,11 +186,11 @@ func StoreManifest(ctx context.Context, name string, manifest *Manifest) (*Manif
|
||||
Contents: make(map[string]*Entry),
|
||||
Redirects: manifest.Redirects,
|
||||
Problems: manifest.Problems,
|
||||
TotalSize: proto.Uint32(0),
|
||||
TotalSize: proto.Int64(0),
|
||||
}
|
||||
for name, entry := range manifest.Contents {
|
||||
cannotBeInlined := entry.GetType() == Type_InlineFile &&
|
||||
entry.GetSize() > uint32(config.Limits.MaxInlineFileSize.Bytes())
|
||||
entry.GetSize() > int64(config.Limits.MaxInlineFileSize.Bytes())
|
||||
if cannotBeInlined {
|
||||
extManifest.Contents[name] = &Entry{
|
||||
Type: Type_ExternalFile.Enum(),
|
||||
|
||||
+6
-6
@@ -134,7 +134,7 @@ type Entry struct {
|
||||
Type *Type `protobuf:"varint,1,opt,name=type,enum=Type" json:"type,omitempty"`
|
||||
// Only present for `type == InlineFile` and `type == ExternalFile`.
|
||||
// For transformed entries, refers to the post-transformation (compressed) size.
|
||||
Size *uint32 `protobuf:"varint,2,opt,name=size" json:"size,omitempty"`
|
||||
Size *int64 `protobuf:"varint,2,opt,name=size" json:"size,omitempty"`
|
||||
// Meaning depends on `type`:
|
||||
// - If `type == InlineFile`, contains file data.
|
||||
// - If `type == ExternalFile`, contains blob name (an otherwise unspecified
|
||||
@@ -186,7 +186,7 @@ func (x *Entry) GetType() Type {
|
||||
return Type_Invalid
|
||||
}
|
||||
|
||||
func (x *Entry) GetSize() uint32 {
|
||||
func (x *Entry) GetSize() int64 {
|
||||
if x != nil && x.Size != nil {
|
||||
return *x.Size
|
||||
}
|
||||
@@ -337,7 +337,7 @@ type Manifest struct {
|
||||
Commit *string `protobuf:"bytes,3,opt,name=commit" json:"commit,omitempty"`
|
||||
// Contents
|
||||
Contents map[string]*Entry `protobuf:"bytes,4,rep,name=contents" json:"contents,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"`
|
||||
TotalSize *uint32 `protobuf:"varint,5,opt,name=total_size,json=totalSize" json:"total_size,omitempty"`
|
||||
TotalSize *int64 `protobuf:"varint,5,opt,name=total_size,json=totalSize" json:"total_size,omitempty"`
|
||||
// Netlify-style `_redirects`
|
||||
Redirects []*Redirect `protobuf:"bytes,6,rep,name=redirects" json:"redirects,omitempty"`
|
||||
// Diagnostics for non-fatal errors
|
||||
@@ -404,7 +404,7 @@ func (x *Manifest) GetContents() map[string]*Entry {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *Manifest) GetTotalSize() uint32 {
|
||||
func (x *Manifest) GetTotalSize() int64 {
|
||||
if x != nil && x.TotalSize != nil {
|
||||
return *x.TotalSize
|
||||
}
|
||||
@@ -432,7 +432,7 @@ const file_schema_proto_rawDesc = "" +
|
||||
"\fschema.proto\"j\n" +
|
||||
"\x05Entry\x12\x19\n" +
|
||||
"\x04type\x18\x01 \x01(\x0e2\x05.TypeR\x04type\x12\x12\n" +
|
||||
"\x04size\x18\x02 \x01(\rR\x04size\x12\x12\n" +
|
||||
"\x04size\x18\x02 \x01(\x03R\x04size\x12\x12\n" +
|
||||
"\x04data\x18\x03 \x01(\fR\x04data\x12\x1e\n" +
|
||||
"\x04xfrm\x18\x04 \x01(\x0e2\n" +
|
||||
".TransformR\x04xfrm\"\\\n" +
|
||||
@@ -450,7 +450,7 @@ const file_schema_proto_rawDesc = "" +
|
||||
"\x06commit\x18\x03 \x01(\tR\x06commit\x123\n" +
|
||||
"\bcontents\x18\x04 \x03(\v2\x17.Manifest.ContentsEntryR\bcontents\x12\x1d\n" +
|
||||
"\n" +
|
||||
"total_size\x18\x05 \x01(\rR\ttotalSize\x12'\n" +
|
||||
"total_size\x18\x05 \x01(\x03R\ttotalSize\x12'\n" +
|
||||
"\tredirects\x18\x06 \x03(\v2\t.RedirectR\tredirects\x12$\n" +
|
||||
"\bproblems\x18\a \x03(\v2\b.ProblemR\bproblems\x1aC\n" +
|
||||
"\rContentsEntry\x12\x10\n" +
|
||||
|
||||
+2
-2
@@ -26,7 +26,7 @@ message Entry {
|
||||
Type type = 1;
|
||||
// Only present for `type == InlineFile` and `type == ExternalFile`.
|
||||
// For transformed entries, refers to the post-transformation (compressed) size.
|
||||
uint32 size = 2;
|
||||
int64 size = 2;
|
||||
// Meaning depends on `type`:
|
||||
// * If `type == InlineFile`, contains file data.
|
||||
// * If `type == ExternalFile`, contains blob name (an otherwise unspecified
|
||||
@@ -61,7 +61,7 @@ message Manifest {
|
||||
|
||||
// Contents
|
||||
map<string, Entry> contents = 4;
|
||||
uint32 total_size = 5;
|
||||
int64 total_size = 5;
|
||||
|
||||
// Netlify-style `_redirects`
|
||||
repeated Redirect redirects = 6;
|
||||
|
||||
Reference in New Issue
Block a user