aboutsummaryrefslogtreecommitdiff
path: root/obj_tree.go
diff options
context:
space:
mode:
authorGravatar Runxi Yu2025-11-16 00:00:00 +0000
committerGravatar Runxi Yu2025-11-16 00:00:00 +0000
commitedd37bb4fd3aa08eda39303fd5628a554a8c3aeb (patch)
tree9b438c2e0b64f880cc57c90446fcec8768e7730b /obj_tree.go
parentMove config to its own package (diff)
signature
Separate stored object types from types that the user is expected to construct.
Diffstat (limited to 'obj_tree.go')
-rw-r--r--obj_tree.go22
1 files changed, 17 insertions, 5 deletions
diff --git a/obj_tree.go b/obj_tree.go
index 36c98950..eb926832 100644
--- a/obj_tree.go
+++ b/obj_tree.go
@@ -9,10 +9,20 @@ import (
// Tree represents a Git tree object.
type Tree struct {
- Hash Hash
Entries []TreeEntry
}
+// StoredTree represents a tree stored in the object database.
+type StoredTree struct {
+ Tree
+ hash Hash
+}
+
+// Hash returns the hash of the stored tree.
+func (sTree *StoredTree) Hash() Hash {
+ return sTree.hash
+}
+
// TreeEntry represents a single entry in a Git tree.
type TreeEntry struct {
Mode uint32
@@ -27,7 +37,7 @@ func (tree *Tree) ObjectType() ObjectType {
}
// parseTree decodes a tree body.
-func parseTree(id Hash, body []byte, repo *Repository) (*Tree, error) {
+func parseTree(id Hash, body []byte, repo *Repository) (*StoredTree, error) {
var entries []TreeEntry
i := 0
for i < len(body) {
@@ -66,9 +76,11 @@ func parseTree(id Hash, body []byte, repo *Repository) (*Tree, error) {
entries = append(entries, entry)
}
- return &Tree{
- Hash: id,
- Entries: entries,
+ return &StoredTree{
+ hash: id,
+ Tree: Tree{
+ Entries: entries,
+ },
}, nil
}