diff options
| author | 2026-06-12 18:41:58 +0000 | |
|---|---|---|
| committer | 2026-06-12 18:41:58 +0000 | |
| commit | 7faa841b581dbbacf563a6ca3167efbfd697d37c (patch) | |
| tree | ab54845bcf708b1099f88a339d18bdf1cdb6f23f /object/store/packed/writer.go | |
| parent | object/store/packed: Add missing t.Helper (diff) | |
object/store/packed: Add basic ingestion
Diffstat (limited to 'object/store/packed/writer.go')
| -rw-r--r-- | object/store/packed/writer.go | 40 |
1 files changed, 34 insertions, 6 deletions
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 +} |
