| Index: go/src/infra/libs/git/emptyObject.go
|
| diff --git a/go/src/infra/libs/git/emptyObject.go b/go/src/infra/libs/git/emptyObject.go
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..035b6d3b84e30ff216b0c84f09e4ba4a0c4cb082
|
| --- /dev/null
|
| +++ b/go/src/infra/libs/git/emptyObject.go
|
| @@ -0,0 +1,54 @@
|
| +// Copyright 2014 The Chromium 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 git
|
| +
|
| +import (
|
| + "fmt"
|
| +)
|
| +
|
| +// Types ///////////////////////////////////////////////////////////////////////
|
| +
|
| +// EmptyObject is a placeholder Object which is not Internable, but can be
|
| +// used to create a Complete() Tree. It can be of type "commit" or "blob".
|
| +// It is never Complete().
|
| +//
|
| +// Implements:
|
| +// fmt.Stringer
|
| +// Object
|
| +type EmptyObject struct {
|
| + id *ObjectID
|
| + typ ObjectType
|
| +}
|
| +
|
| +// Constructors ///////////////////////////////////////////////////////////////
|
| +
|
| +// NewEmptyObject returns an Object of type |typ| with no data. For "tree"
|
| +// types, this returns an empty Tree (which is mutable). All other types are an
|
| +// EmptyObject.
|
| +func NewEmptyObjectErr(typ ObjectType, id Identifiable) (Object, error) {
|
| + switch typ {
|
| + case BlobType, CommitType, TreeType:
|
| + return &EmptyObject{id.ID(), typ}, nil
|
| + default:
|
| + return nil, fmt.Errorf("unknown type %s", typ)
|
| + }
|
| +}
|
| +
|
| +func NewEmptyObject(typ ObjectType, id Identifiable) Object {
|
| + r, err := NewEmptyObjectErr(typ, id)
|
| + if err != nil {
|
| + panic(err)
|
| + }
|
| + return r
|
| +}
|
| +
|
| +// Member functions ////////////////////////////////////////////////////////////
|
| +
|
| +func (o *EmptyObject) ID() *ObjectID { return o.id }
|
| +func (o *EmptyObject) Type() ObjectType { return o.typ }
|
| +func (o *EmptyObject) Complete() bool { return false }
|
| +func (o *EmptyObject) String() string {
|
| + return fmt.Sprintf("EmptyObject(%s, %s)", o.ID(), o.Type())
|
| +}
|
|
|