aboutsummaryrefslogtreecommitdiffstats
path: root/formats/packfile/objects.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2015-10-25 02:11:04 +0100
committerMáximo Cuadros <mcuadros@gmail.com>2015-10-25 02:11:04 +0100
commitf5dfba3742d551411ed0d6279c18f867b6496368 (patch)
treea2907d4f5d4814aa3fd8ea21af5bf5e9ead54a00 /formats/packfile/objects.go
parentec6f456c0e8c7058a29611429965aa05c190b54b (diff)
downloadgo-git-f5dfba3742d551411ed0d6279c18f867b6496368.tar.gz
formats/packfile: new reader API (wip)
Diffstat (limited to 'formats/packfile/objects.go')
-rw-r--r--formats/packfile/objects.go32
1 files changed, 27 insertions, 5 deletions
diff --git a/formats/packfile/objects.go b/formats/packfile/objects.go
index e46d8af..bd76896 100644
--- a/formats/packfile/objects.go
+++ b/formats/packfile/objects.go
@@ -9,14 +9,36 @@ import (
"time"
)
-type ObjectType string
+type ObjectType int8
const (
- CommitObject ObjectType = "commit"
- TreeObject ObjectType = "tree"
- BlobObject ObjectType = "blob"
+ CommitObject ObjectType = 1
+ TreeObject ObjectType = 2
+ BlobObject ObjectType = 3
+ TagObject ObjectType = 4
+ OFSDeltaObject ObjectType = 6
+ REFDeltaObject ObjectType = 7
)
+func (t ObjectType) String() string {
+ switch t {
+ case CommitObject:
+ return "commit"
+ case TreeObject:
+ return "tree"
+ case BlobObject:
+ return "blob"
+ default:
+ return "-"
+ }
+}
+
+type RAWObject struct {
+ Hash Hash
+ Type ObjectType
+ Bytes []byte
+}
+
// Object generic object interface
type Object interface {
Type() ObjectType
@@ -28,7 +50,7 @@ type Hash [20]byte
// ComputeHash compute the hash for a given objType and content
func ComputeHash(t ObjectType, content []byte) Hash {
- h := []byte(t)
+ h := []byte(t.String())
h = append(h, ' ')
h = strconv.AppendInt(h, int64(len(content)), 10)
h = append(h, 0)