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

Unified 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, 2 months 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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())
+}
« 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