From edd37bb4fd3aa08eda39303fd5628a554a8c3aeb Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Sun, 16 Nov 2025 00:00:00 +0000 Subject: Separate stored object types from types that the user is expected to construct. --- obj_tree.go | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'obj_tree.go') 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 } -- cgit v1.3.1-10-gc9f91