From baae1e6560c6e8a1f4a6d00b220f75d37e7d5016 Mon Sep 17 00:00:00 2001 From: Catherine Date: Wed, 3 Dec 2025 01:08:46 +0000 Subject: [PATCH] Simplify. NFCI Co-authored-by: David Leadbeater --- src/fetch.go | 3 ++- src/util.go | 18 ------------------ 2 files changed, 2 insertions(+), 19 deletions(-) diff --git a/src/fetch.go b/src/fetch.go index 4bc71aa..4f987b5 100644 --- a/src/fetch.go +++ b/src/fetch.go @@ -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) } diff --git a/src/util.go b/src/util.go index fea7c59..9079a25 100644 --- a/src/util.go +++ b/src/util.go @@ -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) - } -}