Skip to content
Permalink
Branch: master
Commits on Jan 12, 2020
  1. all: minor tweaks

    dsnet committed Jan 12, 2020
    Fix a typo in legacy_enum.go.
    Rename package in ancient legacy proto so that it doesn't confuse
    tooling that assume that the package and directory names match.
    
    Change-Id: I0b896045e74b0a7f998d3e5693b853eb3aa3839c
    Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/214182
    Reviewed-by: Joe Tsai <joetsai@google.com>
  2. internal/testprotos: hide all public testprotos

    dsnet committed Jan 11, 2020
    The encoding/testprotos and reflect/protoregistry/testprotos are
    accessible by other modules. Move them under internal/testprotos
    to dissuade programmers who are too lazy to use their own test protos
    when they need one.
    
    Change-Id: I3dbfbce74e68ef033ec252bed076861cb47dd21e
    Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/214341
    Reviewed-by: Damien Neil <dneil@google.com>
  3. internal/testprotos/legacy: rename and regenerate

    dsnet committed Jan 11, 2020
    Avoid dots and dashes in the directory to avoid issues on
    build systems that cannot support them well.
    
    Change-Id: I7ea5e6ce0b16c7158c7e53bcf5c3c1a334fe4718
    Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/214342
    Reviewed-by: Damien Neil <dneil@google.com>
Commits on Jan 11, 2020
  1. cmd/protoc-gen-go: refactor package

    dsnet committed Jan 10, 2020
    Refactor the internal logic of protoc-gen-go to better plumb local
    settings and parameters down the call tree.
    
    Change-Id: I09fec188d7359f2b66be584aa8f10e682a7b6796
    Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/214357
    Reviewed-by: Patrik Nyblom <pnyb@google.com>
    Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
Commits on Jan 6, 2020
  1. proto: add Clone function and MergeOptions.Clone method

    dsnet committed Jan 4, 2020
    We resisted adding Clone for a while since:
    * It is a function that is perfectly suited for generics.
    However, generics probably still won't be available in Go for some time
    and it is impractical to block addition of this function when it is very
    widely used and will be necessary for the v1 to v2 migration.
    * In the past, there was no protoreflect.Message.IsValid, so there was
    no proper API to detect invalid top-level messages and return them as such.
    
    Since Clone relies on certain properties about proper round-tripping
    of ProtoMessage.ProtoReflect <-> Message.Interface, we add a test
    in testing/prototest to check for this.
    
    Change-Id: Ic492b68f27b8b88322a6a3fa3a5e492228db79d9
    Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/213297
    Reviewed-by: Damien Neil <dneil@google.com>
  2. proto: add MergeOptions.Shallow option

    dsnet committed Jan 2, 2020
    A shallow copy of a message is a common operation with over 10k
    usages inside Google. However, the semantics of a shallow copy
    on the struct is ill-defined and not officially supported by
    the generated protobuf API.
    
    To reduce improper usages, add an official implementation of
    shallow merging that does something similar where messages, lists,
    and maps are shallow copied into the destination if it does not
    already have one populated.
    
    In the common case where the destination is empty, this equivalent to:
    	src.Range(func(fd protoreflect.FieldDescriptor, v protoreflect.Value) bool {
    		dst.Set(fd, v)
    	})
    	if len(src.GetUnknown()) > 0 {
    		dst.SetUnknown(src.GetUnknown())
    	}
    which is as simple of a shallow copy definition as you can get.
    
    A future CL will add a fast-path implementation of both
    deep and shallow merges.
    
    Change-Id: Ic4a5503dd1b11b505738f5e503f97d55997e9418
    Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/213131
    Reviewed-by: Damien Neil <dneil@google.com>
  3. proto: distinguish between invalid and empty messages in Equal

    dsnet committed Jan 4, 2020
    The v1 proto.Equal function treats (*Message)(nil) and new(Message)
    as being different, while v2 proto.Equal treated them as equal since
    a typed nil pointer is functionally an empty message since the
    protobuf data model has no concept of presence as a first-class
    property of messages.
    
    Unfortunately, a significant amount of code depends on this distinction
    that it would be difficult to migrate users from v1 to v2 unless we
    preserved similar semantics in the v2 proto.Equal.
    
    Also, double down on these semantics for protocmp.Transform.
    
    Fixes #965
    
    Change-Id: I21e78ba6251401a0ac0ccf495188093973cd7f3f
    Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/213238
    Reviewed-by: Damien Neil <dneil@google.com>
  4. internal/impl: return nil for nil enum or message

    dsnet committed Jan 4, 2020
    Ensure that EnumOf, EnumDescriptorOf, EnumTypeOf, ProtoMessageV1Of,
    ProtoMessageV2Of, MessageOf, MessageDescriptorOf, and MessageTypeOf
    all return nil if passed a nil interface.
    
    This parallels the behavior of reflect.TypeOf or reflect.ValueOf,
    which return nil or an invalid value rather than panicking.
    
    Change-Id: I461f15542f16cb0922d627bca6fcad5fc27d87e2
    Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/213239
    Reviewed-by: Damien Neil <dneil@google.com>
  5. internal/filedesc: use jsonName.Init method over JSONName constructor

    dsnet committed Jan 3, 2020
    The JSONName constructor returns a struct value which shallow copies
    a sync.Once within it; this is a dubious pattern.
    Instead, add a jsonName.Init method to initialize the value.
    
    Change-Id: I190a7239b1b62a8041ee7e4e09c0fe37b64ff623
    Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/213237
    Reviewed-by: Damien Neil <dneil@google.com>
You can’t perform that action at this time.