From 7faa841b581dbbacf563a6ca3167efbfd697d37c Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Fri, 12 Jun 2026 18:41:58 +0000 Subject: object/store/packed: Add basic ingestion --- object/store/packed/writer.go | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) (limited to 'object/store/packed/writer.go') diff --git a/object/store/packed/writer.go b/object/store/packed/writer.go index a01bc7dd..59309c24 100644 --- a/object/store/packed/writer.go +++ b/object/store/packed/writer.go @@ -1,10 +1,38 @@ package packed -// import ( -// "io" +import ( + "fmt" + "io" + + "lindenii.org/go/furgit/object/store" + "lindenii.org/go/furgit/object/store/packed/internal/ingest" +) + +var _ store.PackWriter = (*Packed)(nil) + +// WritePack ingests one pack stream into the pack store, +// publishing a pack, index, and reverse index +// under content-addressed names derived from the pack trailer hash. // -// "lindenii.org/go/furgit/object/store" -// ) +// WritePack consumes the pack stream through its trailer and stops there. +// It does not require src to reach EOF afterward, +// so it is safe on a still-open transport connection, +// such as receive-pack, +// whose peer keeps the connection open to read the response. // -// // WritePack ingests one pack stream into the packed store. -// func (packed *Packed) WritePack(src io.Reader, opts store.PackWriteOptions) error +// The pack must be the last thing the peer sends before that response: +// any bytes arriving immediately after the trailer +// are rejected as a malformed pack. +func (packed *Packed) WritePack(src io.Reader, opts store.PackWriteOptions) error { + _, err := ingest.WritePack(packed.root, packed.objectFormat, src, opts) + if err != nil { + return err //nolint:wrapcheck + } + + err = packed.Refresh() + if err != nil { + return fmt.Errorf("object/store/packed: refresh after pack write: %w", err) + } + + return nil +} -- cgit v1.3.1-10-gc9f91