1
0
mirror of https://github.com/go-gitea/gitea.git synced 2024-12-04 14:46:57 -05:00
gitea/vendor/google.golang.org/protobuf/internal/impl/merge.go
6543 792b4dba2c
[Vendor] Update directly used dependencys (#15593)
* update github.com/blevesearch/bleve v2.0.2 -> v2.0.3

* github.com/denisenkom/go-mssqldb v0.9.0 -> v0.10.0

* github.com/editorconfig/editorconfig-core-go v2.4.1 -> v2.4.2

* github.com/go-chi/cors v1.1.1 -> v1.2.0

* github.com/go-git/go-billy v5.0.0 -> v5.1.0

* github.com/go-git/go-git v5.2.0 -> v5.3.0

* github.com/go-ldap/ldap v3.2.4 -> v3.3.0

* github.com/go-redis/redis v8.6.0 -> v8.8.2

* github.com/go-sql-driver/mysql v1.5.0 -> v1.6.0

* github.com/go-swagger/go-swagger v0.26.1 -> v0.27.0

* github.com/lib/pq v1.9.0 -> v1.10.1

* github.com/mattn/go-sqlite3 v1.14.6 -> v1.14.7

* github.com/go-testfixtures/testfixtures v3.5.0 -> v3.6.0

* github.com/issue9/identicon v1.0.1 -> v1.2.0

* github.com/klauspost/compress v1.11.8 -> v1.12.1

* github.com/mgechev/revive v1.0.3 -> v1.0.6

* github.com/microcosm-cc/bluemonday v1.0.7 -> v1.0.8

* github.com/niklasfasching/go-org v1.4.0 -> v1.5.0

* github.com/olivere/elastic v7.0.22 -> v7.0.24

* github.com/pelletier/go-toml v1.8.1 -> v1.9.0

* github.com/prometheus/client_golang v1.9.0 -> v1.10.0

* github.com/xanzy/go-gitlab v0.44.0 -> v0.48.0

* github.com/yuin/goldmark v1.3.3 -> v1.3.5

* github.com/6543/go-version v1.2.4 -> v1.3.1

* do github.com/lib/pq v1.10.0 -> v1.10.1 again ...
2021-04-22 20:08:53 -04:00

177 lines
4.4 KiB
Go
Vendored

// Copyright 2020 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package impl
import (
"fmt"
"reflect"
"google.golang.org/protobuf/proto"
pref "google.golang.org/protobuf/reflect/protoreflect"
piface "google.golang.org/protobuf/runtime/protoiface"
)
type mergeOptions struct{}
func (o mergeOptions) Merge(dst, src proto.Message) {
proto.Merge(dst, src)
}
// merge is protoreflect.Methods.Merge.
func (mi *MessageInfo) merge(in piface.MergeInput) piface.MergeOutput {
dp, ok := mi.getPointer(in.Destination)
if !ok {
return piface.MergeOutput{}
}
sp, ok := mi.getPointer(in.Source)
if !ok {
return piface.MergeOutput{}
}
mi.mergePointer(dp, sp, mergeOptions{})
return piface.MergeOutput{Flags: piface.MergeComplete}
}
func (mi *MessageInfo) mergePointer(dst, src pointer, opts mergeOptions) {
mi.init()
if dst.IsNil() {
panic(fmt.Sprintf("invalid value: merging into nil message"))
}
if src.IsNil() {
return
}
for _, f := range mi.orderedCoderFields {
if f.funcs.merge == nil {
continue
}
sfptr := src.Apply(f.offset)
if f.isPointer && sfptr.Elem().IsNil() {
continue
}
f.funcs.merge(dst.Apply(f.offset), sfptr, f, opts)
}
if mi.extensionOffset.IsValid() {
sext := src.Apply(mi.extensionOffset).Extensions()
dext := dst.Apply(mi.extensionOffset).Extensions()
if *dext == nil {
*dext = make(map[int32]ExtensionField)
}
for num, sx := range *sext {
xt := sx.Type()
xi := getExtensionFieldInfo(xt)
if xi.funcs.merge == nil {
continue
}
dx := (*dext)[num]
var dv pref.Value
if dx.Type() == sx.Type() {
dv = dx.Value()
}
if !dv.IsValid() && xi.unmarshalNeedsValue {
dv = xt.New()
}
dv = xi.funcs.merge(dv, sx.Value(), opts)
dx.Set(sx.Type(), dv)
(*dext)[num] = dx
}
}
if mi.unknownOffset.IsValid() {
su := mi.getUnknownBytes(src)
if su != nil && len(*su) > 0 {
du := mi.mutableUnknownBytes(dst)
*du = append(*du, *su...)
}
}
}
func mergeScalarValue(dst, src pref.Value, opts mergeOptions) pref.Value {
return src
}
func mergeBytesValue(dst, src pref.Value, opts mergeOptions) pref.Value {
return pref.ValueOfBytes(append(emptyBuf[:], src.Bytes()...))
}
func mergeListValue(dst, src pref.Value, opts mergeOptions) pref.Value {
dstl := dst.List()
srcl := src.List()
for i, llen := 0, srcl.Len(); i < llen; i++ {
dstl.Append(srcl.Get(i))
}
return dst
}
func mergeBytesListValue(dst, src pref.Value, opts mergeOptions) pref.Value {
dstl := dst.List()
srcl := src.List()
for i, llen := 0, srcl.Len(); i < llen; i++ {
sb := srcl.Get(i).Bytes()
db := append(emptyBuf[:], sb...)
dstl.Append(pref.ValueOfBytes(db))
}
return dst
}
func mergeMessageListValue(dst, src pref.Value, opts mergeOptions) pref.Value {
dstl := dst.List()
srcl := src.List()
for i, llen := 0, srcl.Len(); i < llen; i++ {
sm := srcl.Get(i).Message()
dm := proto.Clone(sm.Interface()).ProtoReflect()
dstl.Append(pref.ValueOfMessage(dm))
}
return dst
}
func mergeMessageValue(dst, src pref.Value, opts mergeOptions) pref.Value {
opts.Merge(dst.Message().Interface(), src.Message().Interface())
return dst
}
func mergeMessage(dst, src pointer, f *coderFieldInfo, opts mergeOptions) {
if f.mi != nil {
if dst.Elem().IsNil() {
dst.SetPointer(pointerOfValue(reflect.New(f.mi.GoReflectType.Elem())))
}
f.mi.mergePointer(dst.Elem(), src.Elem(), opts)
} else {
dm := dst.AsValueOf(f.ft).Elem()
sm := src.AsValueOf(f.ft).Elem()
if dm.IsNil() {
dm.Set(reflect.New(f.ft.Elem()))
}
opts.Merge(asMessage(dm), asMessage(sm))
}
}
func mergeMessageSlice(dst, src pointer, f *coderFieldInfo, opts mergeOptions) {
for _, sp := range src.PointerSlice() {
dm := reflect.New(f.ft.Elem().Elem())
if f.mi != nil {
f.mi.mergePointer(pointerOfValue(dm), sp, opts)
} else {
opts.Merge(asMessage(dm), asMessage(sp.AsValueOf(f.ft.Elem().Elem())))
}
dst.AppendPointerSlice(pointerOfValue(dm))
}
}
func mergeBytes(dst, src pointer, _ *coderFieldInfo, _ mergeOptions) {
*dst.Bytes() = append(emptyBuf[:], *src.Bytes()...)
}
func mergeBytesNoZero(dst, src pointer, _ *coderFieldInfo, _ mergeOptions) {
v := *src.Bytes()
if len(v) > 0 {
*dst.Bytes() = append(emptyBuf[:], v...)
}
}
func mergeBytesSlice(dst, src pointer, _ *coderFieldInfo, _ mergeOptions) {
ds := dst.BytesSlice()
for _, v := range *src.BytesSlice() {
*ds = append(*ds, append(emptyBuf[:], v...))
}
}