From 5cfbd8863dfb7c6af92497d9a5eb6eb63a6bd589 Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Sun, 16 Nov 2025 00:00:00 +0000 Subject: Revert "hash: Generic hash-algorithm API" This reverts commit 94bfb1fa147f80e6ec39009d41fc2f853925e0a5. Generics actually kinda suck for these purposes... once you look at it from the user's perspective. --- obj_commit.go | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'obj_commit.go') diff --git a/obj_commit.go b/obj_commit.go index f733a56f..84de2c41 100644 --- a/obj_commit.go +++ b/obj_commit.go @@ -7,10 +7,10 @@ import ( ) // Commit mirrors the structure of a Git commit object. -type Commit[T HashType] struct { - Hash Hash[T] - Tree Hash[T] - Parents []Hash[T] +type Commit struct { + Hash Hash + Tree Hash + Parents []Hash Author Ident Committer Ident Message []byte @@ -18,12 +18,12 @@ type Commit[T HashType] struct { } // ObjType allows Commit to satisfy the Object interface. -func (*Commit[T]) ObjType() ObjType { +func (*Commit) ObjType() ObjType { return ObjCommit } -func parseCommit[T HashType](id Hash[T], body []byte) (*Commit[T], error) { - c := new(Commit[T]) +func parseCommit(id Hash, body []byte, hashSize int) (*Commit, error) { + c := new(Commit) c.Hash = id i := 0 for i < len(body) { @@ -39,13 +39,13 @@ func parseCommit[T HashType](id Hash[T], body []byte) (*Commit[T], error) { switch { case bytes.HasPrefix(line, []byte("tree ")): - treeID, err := ParseHash[T](string(line[5:])) + treeID, err := ParseHashWithSize(string(line[5:]), hashSize) if err != nil { return nil, fmt.Errorf("furgit: commit: tree: %w", err) } c.Tree = treeID case bytes.HasPrefix(line, []byte("parent ")): - parent, err := ParseHash[T](string(line[7:])) + parent, err := ParseHashWithSize(string(line[7:]), hashSize) if err != nil { return nil, fmt.Errorf("furgit: commit: parent: %w", err) } @@ -91,11 +91,11 @@ func parseCommit[T HashType](id Hash[T], body []byte) (*Commit[T], error) { return c, nil } -func commitBody[T HashType](c *Commit[T]) []byte { +func commitBody(c *Commit, hashSize int) []byte { var buf bytes.Buffer - fmt.Fprintf(&buf, "tree %s\n", c.Tree.String()) + fmt.Fprintf(&buf, "tree %s\n", c.Tree.StringWithSize(hashSize)) for _, p := range c.Parents { - fmt.Fprintf(&buf, "parent %s\n", p.String()) + fmt.Fprintf(&buf, "parent %s\n", p.StringWithSize(hashSize)) } buf.WriteString("author ") buf.Write(c.Author.Serialize()) @@ -110,8 +110,8 @@ func commitBody[T HashType](c *Commit[T]) []byte { } // Serialize renders a Commit into canonical Git format. -func (c *Commit[T]) Serialize() ([]byte, error) { - body := commitBody(c) +func (c *Commit) Serialize(hashSize int) ([]byte, error) { + body := commitBody(c, hashSize) header, err := headerForType(ObjCommit, body) if err != nil { return nil, err -- cgit v1.3.1-10-gc9f91