Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(81)

Side by Side Diff: go/src/infra/libs/git/emptyObject.go

Issue 662113003: Drover's back, baby! (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git/+/master
Patch Set: more tests and refactors Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « go/src/infra/libs/git/commit_test.go ('k') | go/src/infra/libs/git/emptyObject_test.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 }
OLDNEW
« no previous file with comments | « go/src/infra/libs/git/commit_test.go ('k') | go/src/infra/libs/git/emptyObject_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698