aboutsummaryrefslogtreecommitdiffstats
path: root/internal
diff options
context:
space:
mode:
Diffstat (limited to 'internal')
-rw-r--r--internal/hash.go5
-rw-r--r--internal/hash_test.go8
-rw-r--r--internal/object.go18
3 files changed, 22 insertions, 9 deletions
diff --git a/internal/hash.go b/internal/hash.go
index db55b24..0540db1 100644
--- a/internal/hash.go
+++ b/internal/hash.go
@@ -30,6 +30,11 @@ func NewHash(s string) Hash {
return h
}
+func (h Hash) IsZero() bool {
+ var empty Hash
+ return h == empty
+}
+
func (h Hash) String() string {
return hex.EncodeToString(h[:])
}
diff --git a/internal/hash_test.go b/internal/hash_test.go
index 222f3b4..063bd23 100644
--- a/internal/hash_test.go
+++ b/internal/hash_test.go
@@ -25,3 +25,11 @@ func (s *HashSuite) TestNewHash(c *C) {
c.Assert(hash, Equals, NewHash(hash.String()))
}
+
+func (s *HashSuite) TestIsZero(c *C) {
+ hash := NewHash("foo")
+ c.Assert(hash.IsZero(), Equals, true)
+
+ hash = NewHash("8ab686eafeb1f44702738c8b0f24f2567c36da6d")
+ c.Assert(hash.IsZero(), Equals, false)
+}
diff --git a/internal/object.go b/internal/object.go
index 0f11140..a30bc9d 100644
--- a/internal/object.go
+++ b/internal/object.go
@@ -71,18 +71,18 @@ func (o *RAWObject) Write(p []byte) (n int, err error) {
}
type RAWObjectStorage struct {
- Objects map[Hash]*RAWObject
- Commits map[Hash]*RAWObject
- Trees map[Hash]*RAWObject
- Blobs map[Hash]*RAWObject
+ Objects map[Hash]Object
+ Commits map[Hash]Object
+ Trees map[Hash]Object
+ Blobs map[Hash]Object
}
func NewRAWObjectStorage() *RAWObjectStorage {
return &RAWObjectStorage{
- Objects: make(map[Hash]*RAWObject, 0),
- Commits: make(map[Hash]*RAWObject, 0),
- Trees: make(map[Hash]*RAWObject, 0),
- Blobs: make(map[Hash]*RAWObject, 0),
+ Objects: make(map[Hash]Object, 0),
+ Commits: make(map[Hash]Object, 0),
+ Trees: make(map[Hash]Object, 0),
+ Blobs: make(map[Hash]Object, 0),
}
}
@@ -92,7 +92,7 @@ func (o *RAWObjectStorage) New() Object {
func (o *RAWObjectStorage) Set(obj Object) Hash {
h := obj.Hash()
- o.Objects[h] = obj.(*RAWObject)
+ o.Objects[h] = obj
switch obj.Type() {
case CommitObject: