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_commit.go | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'obj_commit.go') diff --git a/obj_commit.go b/obj_commit.go index f1616fba..c3a4e5db 100644 --- a/obj_commit.go +++ b/obj_commit.go @@ -6,9 +6,8 @@ import ( "fmt" ) -// Commit mirrors the structure of a Git commit object. +// Commit represents a Git commit object. type Commit struct { - Hash Hash Tree Hash Parents []Hash Author Ident @@ -17,15 +16,26 @@ type Commit struct { ExtraHeaders []ExtraHeader } +// StoredCommit represents a commit stored in the object database. +type StoredCommit struct { + Commit + hash Hash +} + +// Hash returns the hash of the stored commit. +func (sCommit *StoredCommit) Hash() Hash { + return sCommit.hash +} + // ObjectType allows Commit to satisfy the Object interface. func (commit *Commit) ObjectType() ObjectType { _ = commit return ObjectTypeCommit } -func parseCommit(id Hash, body []byte, repo *Repository) (*Commit, error) { - c := new(Commit) - c.Hash = id +func parseCommit(id Hash, body []byte, repo *Repository) (*StoredCommit, error) { + c := new(StoredCommit) + c.hash = id i := 0 for i < len(body) { rel := bytes.IndexByte(body[i:], '\n') -- cgit v1.3.1-10-gc9f91