Simplify. NFCI

Co-authored-by: David Leadbeater <dgl@dgl.cx>
This commit is contained in:
Catherine
2025-12-03 01:08:46 +00:00
parent 6faf3b1ee3
commit baae1e6560
2 changed files with 2 additions and 19 deletions

View File

@@ -146,7 +146,8 @@ func FetchRepository(
for _, oldManifestEntry := range oldManifest.GetContents() {
if hash, ok := plumbing.FromHex(oldManifestEntry.GetGitHash()); ok {
if manifestEntry, found := blobsNeeded[hash]; found {
CopyProtoMessage(manifestEntry, oldManifestEntry)
manifestEntry.Reset()
proto.Merge(manifestEntry, oldManifestEntry)
dataBytesFromOldManifest += oldManifestEntry.GetOriginalSize()
delete(blobsNeeded, hash)
}

View File

@@ -4,8 +4,6 @@ import (
"errors"
"io"
"strings"
"google.golang.org/protobuf/proto"
)
type BoundedReader struct {
@@ -87,19 +85,3 @@ func getMediaType(mimeType string) (mediaType string) {
mediaType = strings.TrimSpace(strings.ToLower(mediaType))
return
}
// Copying Protobuf messages like `*dest = *src` causes a lock to be copied, which is unsound.
// Copying Protobuf messages field-wise is fragile: adding a new field to the schema does not
// cause a diagnostic to be emitted pointing to the copy site, making it easy to miss updates.
// Serializing and deserializing is reliable and breaks referential links.
func CopyProtoMessage(dest, src proto.Message) {
data, err := proto.Marshal(src)
if err != nil {
panic(err)
}
err = proto.Unmarshal(data, dest)
if err != nil {
panic(err)
}
}