From 8b839334f225a55995d049f03940da417012fb42 Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Sun, 24 May 2026 07:32:34 +0000 Subject: object/blob: Fix naming --- object/blob/append.go | 18 ++++++++++++++++++ object/blob/append_test.go | 30 ++++++++++++++++++++++++++++++ object/blob/serialize.go | 18 ------------------ object/blob/serialize_test.go | 30 ------------------------------ 4 files changed, 48 insertions(+), 48 deletions(-) create mode 100644 object/blob/append.go create mode 100644 object/blob/append_test.go delete mode 100644 object/blob/serialize.go delete mode 100644 object/blob/serialize_test.go diff --git a/object/blob/append.go b/object/blob/append.go new file mode 100644 index 00000000..9d912223 --- /dev/null +++ b/object/blob/append.go @@ -0,0 +1,18 @@ +package blob + +import ( + "codeberg.org/lindenii/furgit/object/header" + "codeberg.org/lindenii/furgit/object/typ" +) + +// AppendWithoutHeader renders the raw blob body bytes. +func (blob *Blob) AppendWithoutHeader(dst []byte) ([]byte, error) { + return append(dst, blob.Data...), nil +} + +// AppendWithHeader renders the raw object (header + body). +func (blob *Blob) AppendWithHeader(dst []byte) ([]byte, error) { + dst = header.Append(dst, typ.TypeBlob, uint64(len(blob.Data))) + + return blob.AppendWithoutHeader(dst) +} diff --git a/object/blob/append_test.go b/object/blob/append_test.go new file mode 100644 index 00000000..51f92c48 --- /dev/null +++ b/object/blob/append_test.go @@ -0,0 +1,30 @@ +package blob_test + +import ( + "testing" + + "codeberg.org/lindenii/furgit/internal/testgit" + "codeberg.org/lindenii/furgit/object/blob" + objectid "codeberg.org/lindenii/furgit/object/id" +) + +func TestBlobAppend(t *testing.T) { + t.Parallel() + testgit.ForEachAlgorithm(t, func(t *testing.T, algo objectid.Algorithm) { //nolint:thelper + testRepo := testgit.NewRepo(t, testgit.RepoOptions{ObjectFormat: algo, Bare: true}) + body := []byte("hello\nblob\n") + wantID := testRepo.HashObject(t, "blob", body) + + obj := &blob.Blob{Data: body} + + rawObj, err := obj.AppendWithHeader([]byte(nil)) + if err != nil { + t.Fatalf("BytesWithHeader: %v", err) + } + + gotID := algo.Sum(rawObj) + if gotID != wantID { + t.Fatalf("object id mismatch: got %s want %s", gotID, wantID) + } + }) +} diff --git a/object/blob/serialize.go b/object/blob/serialize.go deleted file mode 100644 index 2dcc147f..00000000 --- a/object/blob/serialize.go +++ /dev/null @@ -1,18 +0,0 @@ -package blob - -import ( - "codeberg.org/lindenii/furgit/object/header" - "codeberg.org/lindenii/furgit/object/typ" -) - -// BytesWithoutHeader renders the raw blob body bytes. -func (blob *Blob) AppendWithoutHeader(dst []byte) ([]byte, error) { - return append(dst, blob.Data...), nil -} - -// BytesWithHeader renders the raw object (header + body). -func (blob *Blob) AppendWithHeader(dst []byte) ([]byte, error) { - dst = header.Append(dst, typ.TypeBlob, uint64(len(blob.Data))) - - return blob.AppendWithoutHeader(dst) -} diff --git a/object/blob/serialize_test.go b/object/blob/serialize_test.go deleted file mode 100644 index 62a0b9a9..00000000 --- a/object/blob/serialize_test.go +++ /dev/null @@ -1,30 +0,0 @@ -package blob_test - -import ( - "testing" - - "codeberg.org/lindenii/furgit/internal/testgit" - "codeberg.org/lindenii/furgit/object/blob" - objectid "codeberg.org/lindenii/furgit/object/id" -) - -func TestBlobSerialize(t *testing.T) { - t.Parallel() - testgit.ForEachAlgorithm(t, func(t *testing.T, algo objectid.Algorithm) { //nolint:thelper - testRepo := testgit.NewRepo(t, testgit.RepoOptions{ObjectFormat: algo, Bare: true}) - body := []byte("hello\nblob\n") - wantID := testRepo.HashObject(t, "blob", body) - - obj := &blob.Blob{Data: body} - - rawObj, err := obj.AppendWithHeader([]byte(nil)) - if err != nil { - t.Fatalf("BytesWithHeader: %v", err) - } - - gotID := algo.Sum(rawObj) - if gotID != wantID { - t.Fatalf("object id mismatch: got %s want %s", gotID, wantID) - } - }) -} -- cgit v1.3.1-10-gc9f91