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

Unified Diff: go/src/infra/libs/git/types.go

Issue 662113003: Drover's back, baby! (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git/+/master
Patch Set: 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
Index: go/src/infra/libs/git/types.go
diff --git a/go/src/infra/libs/git/types.go b/go/src/infra/libs/git/types.go
new file mode 100644
index 0000000000000000000000000000000000000000..21f116f30e7e6b4aefc8c1aef2c28863f7505fb0
--- /dev/null
+++ b/go/src/infra/libs/git/types.go
@@ -0,0 +1,79 @@
+package git
+
+import "fmt"
+
+// Mode is a typed representation of git's tree mode concept
+type Mode int
+
+// Type returns a Object.Type() compatible string for this mode.
+func (m Mode) Type() string {
+ switch {
+ case m == 0040000:
+ return "tree"
+ case m == 0160000:
+ return "commit"
+ case (m & 0100000) != 0:
+ return "blob"
+ default:
+ panic(fmt.Sprintf("unknown type for mode %d", m))
+ }
+}
+
+func (m Mode) String() string { return fmt.Sprintf("%06o", m) }
+
+// Repo represents a local git repository at the path |Path|.
+type Repo struct {
M-A Ruel 2014/10/18 00:47:06 Please move all the Repo member function into the
iannucci 2014/10/20 21:11:58 Done.
+ // The path on disk to the location of the git repo.
+ Path string
+
+ catFile *chan<- catFileRequest
+ catFileCheck *chan<- catFileRequest
+}
+
+// Object is the barest essence of a git object. It has a Type, and Id, and it
+// can tell you if this instance is 'complete' (does it contain all the data
+// necessary to re-create ID()?).
+//
+// If Complete() is true, you can down-cast this to:
+// *Tree, *Blob, *Commit
+//
+// If Complete() is false, you can down-cast this to:
+// *Tree, EmptyObject
+//
+// Note that Tree's are never EmptyObject's.
+type Object interface {
M-A Ruel 2014/10/18 00:47:06 Could you note in the comment of each struct that
iannucci 2014/10/20 21:11:58 Is that really necessary to note? I thought godoc
M-A Ruel 2014/10/21 00:55:53 It's not necessary but nice to document.
+ ID() ObjectID
+
+ // A git object-type, e.g. "commit", "blob", "tree"
+ Type() string
+
+ // Returns True iff RawString will produce a string which, when hashed,
+ // matches ID()
+ Complete() bool
+}
+
+// InternableObject is an Object which may be interned into a git repo
+// (e.g. hash-object'd). EmptyObjects are NOT InternableObjects.
+type InternableObject interface {
+ Object
+
+ // A hash-object compatible string. May panic if this is an Object which is
+ // !Complete(). Note that for Trees this does NOT imply that all of the
+ // Tree's children are Complete().
+ RawString() string
+}
+
+// Child is an entry in a Tree. It ties a Mode to an Object.
+type Child struct {
+ Object Object
+ Mode Mode
+}
+
+func (c Child) String() string {
+ return fmt.Sprintf("Child(%s, %s)", c.Object, c.Mode)
+}
+
+// ObjectID is a 20-byte git-sha for any Object type.
+type ObjectID struct {
+ raw [20]byte
M-A Ruel 2014/10/18 00:47:06 Ah, that's why you copy around. I think a slice wo
iannucci 2014/10/20 21:11:58 It' has a fixed size... this also means the empty
+}

Powered by Google App Engine
This is Rietveld 408576698