aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Runxi Yu2025-11-15 00:00:00 +0000
committerGravatar Runxi Yu2025-11-15 00:00:00 +0000
commitbd398609ce7f516bf6fae617656fff0509c5fc1c (patch)
treee40c636584d2193f7d0716564b5357c30577660c
parentREADME: Add example (diff)
signature
Include hashes in object structs
-rw-r--r--obj.go4
-rw-r--r--obj_blob.go6
-rw-r--r--obj_commit.go4
-rw-r--r--obj_tag.go4
-rw-r--r--obj_tree.go6
5 files changed, 10 insertions, 14 deletions
diff --git a/obj.go b/obj.go
index d3d69c25..38f18b55 100644
--- a/obj.go
+++ b/obj.go
@@ -33,10 +33,6 @@ type Object interface {
ObjType() ObjType
}
-type objectBase struct {
- Hash Hash
-}
-
func computeRawHash(data []byte) Hash {
var id Hash
sum := newHash(data)
diff --git a/obj_blob.go b/obj_blob.go
index eda0ca5f..5ae0c40e 100644
--- a/obj_blob.go
+++ b/obj_blob.go
@@ -2,7 +2,7 @@ package furgit
// Blob represents the contents of a Git blob.
type Blob struct {
- objectBase
+ Hash Hash
Data []byte
}
@@ -15,8 +15,8 @@ func (*Blob) ObjType() ObjType {
func parseBlob(id Hash, body []byte) (*Blob, error) {
data := append([]byte(nil), body...)
return &Blob{
- objectBase: objectBase{Hash: id},
- Data: data,
+ Hash: id,
+ Data: data,
}, nil
}
diff --git a/obj_commit.go b/obj_commit.go
index 100c6b35..38f24ffc 100644
--- a/obj_commit.go
+++ b/obj_commit.go
@@ -8,7 +8,7 @@ import (
// Commit mirrors the structure of a Git commit object.
type Commit struct {
- objectBase
+ Hash Hash
Tree Hash
Parents []Hash
@@ -25,7 +25,7 @@ func (*Commit) ObjType() ObjType {
func parseCommit(id Hash, body []byte) (*Commit, error) {
c := new(Commit)
- c.objectBase = objectBase{Hash: id}
+ c.Hash = id
i := 0
for i < len(body) {
rel := bytes.IndexByte(body[i:], '\n')
diff --git a/obj_tag.go b/obj_tag.go
index 348afd48..f3d96bd1 100644
--- a/obj_tag.go
+++ b/obj_tag.go
@@ -8,7 +8,7 @@ import (
// Tag models an annotated Git tag object.
type Tag struct {
- objectBase
+ Hash Hash
Target Hash
TargetType ObjType
@@ -25,7 +25,7 @@ func (*Tag) ObjType() ObjType {
// parseTag parses a tag object body.
func parseTag(id Hash, body []byte) (*Tag, error) {
t := new(Tag)
- t.objectBase = objectBase{Hash: id}
+ t.Hash = id
i := 0
var haveTarget, haveType bool
diff --git a/obj_tree.go b/obj_tree.go
index 48121b0a..5336cbf2 100644
--- a/obj_tree.go
+++ b/obj_tree.go
@@ -9,7 +9,7 @@ import (
// Tree represents a Git tree object.
type Tree struct {
- objectBase
+ Hash Hash
Entries []TreeEntry
}
@@ -66,8 +66,8 @@ func parseTree(id Hash, body []byte) (*Tree, error) {
}
return &Tree{
- objectBase: objectBase{Hash: id},
- Entries: entries,
+ Hash: id,
+ Entries: entries,
}, nil
}