aboutsummaryrefslogtreecommitdiff
path: root/repository/write_loose.go
diff options
context:
space:
mode:
authorGravatar Runxi Yu2026-02-21 15:39:10 +0800
committerGravatar Runxi Yu2026-02-21 15:39:10 +0800
commitc9eefd50557a5436da84e0a38ee96c812d453336 (patch)
treea64a5d67a727e6e2ec54b426179e473f4b6806fc /repository/write_loose.go
parentrepository, {ref,object}store: Make stores own their roots (diff)
signatureNo signature
repository: Add loose object writing v0.1.20
Diffstat (limited to 'repository/write_loose.go')
-rw-r--r--repository/write_loose.go50
1 files changed, 50 insertions, 0 deletions
diff --git a/repository/write_loose.go b/repository/write_loose.go
new file mode 100644
index 00000000..c9f42fea
--- /dev/null
+++ b/repository/write_loose.go
@@ -0,0 +1,50 @@
+package repository
+
+import (
+ "fmt"
+ "io"
+
+ "codeberg.org/lindenii/furgit/objectid"
+ "codeberg.org/lindenii/furgit/objecttype"
+)
+
+// WriteLooseBytesFull writes one loose object from raw "type size\0content".
+func (repo *Repository) WriteLooseBytesFull(raw []byte) (objectid.ObjectID, error) {
+ id, err := repo.objectsLooseForWritingOnly.WriteBytesFull(raw)
+ if err != nil {
+ return objectid.ObjectID{}, fmt.Errorf("repository: write loose full bytes: %w", err)
+ }
+ return id, nil
+}
+
+// WriteLooseBytesContent writes one loose object from typed content bytes.
+func (repo *Repository) WriteLooseBytesContent(ty objecttype.Type, content []byte) (objectid.ObjectID, error) {
+ id, err := repo.objectsLooseForWritingOnly.WriteBytesContent(ty, content)
+ if err != nil {
+ return objectid.ObjectID{}, fmt.Errorf("repository: write loose content bytes: %w", err)
+ }
+ return id, nil
+}
+
+// WriteLooseWriterFull returns a writer for one full serialized object stream.
+//
+// The caller must close the writer, then call finalize to publish the object.
+func (repo *Repository) WriteLooseWriterFull() (io.WriteCloser, func() (objectid.ObjectID, error), error) {
+ writer, finalize, err := repo.objectsLooseForWritingOnly.WriteWriterFull()
+ if err != nil {
+ return nil, nil, fmt.Errorf("repository: create loose full writer: %w", err)
+ }
+ return writer, finalize, nil
+}
+
+// WriteLooseWriterContent returns a writer for one typed object content stream.
+//
+// The caller must write exactly size bytes, close the writer, then call
+// finalize to publish the object.
+func (repo *Repository) WriteLooseWriterContent(ty objecttype.Type, size int64) (io.WriteCloser, func() (objectid.ObjectID, error), error) {
+ writer, finalize, err := repo.objectsLooseForWritingOnly.WriteWriterContent(ty, size)
+ if err != nil {
+ return nil, nil, fmt.Errorf("repository: create loose content writer: %w", err)
+ }
+ return writer, finalize, nil
+}