| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package git |
| 6 |
| 7 import ( |
| 8 "fmt" |
| 9 ) |
| 10 |
| 11 // Types /////////////////////////////////////////////////////////////////////// |
| 12 |
| 13 // EmptyObject is a placeholder Object which is not Internable, but can be |
| 14 // used to create a Complete() Tree. It can be of type "commit" or "blob". |
| 15 // It is never Complete(). |
| 16 // |
| 17 // Implements: |
| 18 // fmt.Stringer |
| 19 // Object |
| 20 type EmptyObject struct { |
| 21 id *ObjectID |
| 22 typ ObjectType |
| 23 } |
| 24 |
| 25 // Constructors /////////////////////////////////////////////////////////////// |
| 26 |
| 27 // NewEmptyObject returns an Object of type |typ| with no data. For "tree" |
| 28 // types, this returns an empty Tree (which is mutable). All other types are an |
| 29 // EmptyObject. |
| 30 func NewEmptyObjectErr(typ ObjectType, id Identifiable) (Object, error) { |
| 31 switch typ { |
| 32 case BlobType, CommitType, TreeType: |
| 33 return &EmptyObject{id.ID(), typ}, nil |
| 34 default: |
| 35 return nil, fmt.Errorf("unknown type %s", typ) |
| 36 } |
| 37 } |
| 38 |
| 39 func NewEmptyObject(typ ObjectType, id Identifiable) Object { |
| 40 r, err := NewEmptyObjectErr(typ, id) |
| 41 if err != nil { |
| 42 panic(err) |
| 43 } |
| 44 return r |
| 45 } |
| 46 |
| 47 // Member functions //////////////////////////////////////////////////////////// |
| 48 |
| 49 func (o *EmptyObject) ID() *ObjectID { return o.id } |
| 50 func (o *EmptyObject) Type() ObjectType { return o.typ } |
| 51 func (o *EmptyObject) Complete() bool { return false } |
| 52 func (o *EmptyObject) String() string { |
| 53 return fmt.Sprintf("EmptyObject(%s, %s)", o.ID(), o.Type()) |
| 54 } |
| OLD | NEW |