diff options
| -rw-r--r-- | format/packfile/ingest/api.go | 7 | ||||
| -rw-r--r-- | format/packfile/ingest/idx_write.go | 4 | ||||
| -rw-r--r-- | format/packfile/ingest/progress_write.go | 4 | ||||
| -rw-r--r-- | format/packfile/ingest/resolve_all.go | 1 | ||||
| -rw-r--r-- | format/packfile/ingest/rev_write.go | 1 | ||||
| -rw-r--r-- | format/packfile/ingest/scan.go | 1 | ||||
| -rw-r--r-- | format/packfile/ingest/thin_fix.go | 1 | ||||
| -rw-r--r-- | internal/progress/meter.go | 6 | ||||
| -rw-r--r-- | internal/progress/new.go | 1 | ||||
| -rw-r--r-- | internal/progress/options.go | 6 | ||||
| -rw-r--r-- | internal/progress/render.go | 4 | ||||
| -rw-r--r-- | network/protocol/pktline/encoder.go | 14 | ||||
| -rw-r--r-- | network/protocol/sideband64k/encoder.go | 3 | ||||
| -rw-r--r-- | network/protocol/v0v1/server/receivepack/session.go | 3 | ||||
| -rw-r--r-- | network/protocol/v0v1/server/session.go | 25 | ||||
| -rw-r--r-- | network/receivepack/hook.go | 3 | ||||
| -rw-r--r-- | network/receivepack/receivepack.go | 15 | ||||
| -rw-r--r-- | network/receivepack/service/hook.go | 3 | ||||
| -rw-r--r-- | network/receivepack/service/ingest_quarantine.go | 9 | ||||
| -rw-r--r-- | network/receivepack/service/options.go | 9 |
20 files changed, 59 insertions, 61 deletions
diff --git a/format/packfile/ingest/api.go b/format/packfile/ingest/api.go index 5d999d61..ad04fe14 100644 --- a/format/packfile/ingest/api.go +++ b/format/packfile/ingest/api.go @@ -7,6 +7,7 @@ import ( "io" "os" + "codeberg.org/lindenii/furgit/common/iowrap" objectid "codeberg.org/lindenii/furgit/object/id" objectstore "codeberg.org/lindenii/furgit/object/store" ) @@ -22,11 +23,7 @@ type Options struct { // Progress receives human-readable progress messages. // // When nil, no progress output is emitted. - Progress io.Writer - // ProgressFlush flushes transport output after progress writes. - // - // When nil, no explicit flush is attempted. - ProgressFlush func() error + Progress iowrap.WriteFlusher // RequireTrailingEOF requires the source to hit EOF after the pack trailer. // // This is suitable for exact pack-file readers, but should be disabled for diff --git a/format/packfile/ingest/idx_write.go b/format/packfile/ingest/idx_write.go index 506788b9..fa139264 100644 --- a/format/packfile/ingest/idx_write.go +++ b/format/packfile/ingest/idx_write.go @@ -83,7 +83,6 @@ func writeIdx(state *ingestState) error { oidMeter := progress.New(progress.Options{ Writer: state.opts.Progress, - Flush: state.opts.ProgressFlush, Title: "writing index object ids", Total: uint64(len(order)), }) @@ -108,7 +107,6 @@ func writeIdx(state *ingestState) error { crcMeter := progress.New(progress.Options{ Writer: state.opts.Progress, - Flush: state.opts.ProgressFlush, Title: "writing index crc32", Total: uint64(len(order)), }) @@ -134,7 +132,6 @@ func writeIdx(state *ingestState) error { largeOffsets := make([]uint64, 0) offsetMeter := progress.New(progress.Options{ Writer: state.opts.Progress, - Flush: state.opts.ProgressFlush, Title: "writing index offsets", Total: uint64(len(order)), }) @@ -178,7 +175,6 @@ func writeIdx(state *ingestState) error { largeOffsetMeter := progress.New(progress.Options{ Writer: state.opts.Progress, - Flush: state.opts.ProgressFlush, Title: "writing index large offsets", Total: total, }) diff --git a/format/packfile/ingest/progress_write.go b/format/packfile/ingest/progress_write.go index 5b9f184b..afb39305 100644 --- a/format/packfile/ingest/progress_write.go +++ b/format/packfile/ingest/progress_write.go @@ -5,7 +5,7 @@ import "codeberg.org/lindenii/furgit/internal/utils" func writeProgressf(state *ingestState, format string, args ...any) { utils.BestEffortFprintf(state.opts.Progress, format, args...) - if state.opts.ProgressFlush != nil { - _ = state.opts.ProgressFlush() + if state.opts.Progress != nil { + _ = state.opts.Progress.Flush() } } diff --git a/format/packfile/ingest/resolve_all.go b/format/packfile/ingest/resolve_all.go index e0ad2281..90464015 100644 --- a/format/packfile/ingest/resolve_all.go +++ b/format/packfile/ingest/resolve_all.go @@ -26,7 +26,6 @@ func resolveAll(state *ingestState) error { meter := progress.New(progress.Options{ Writer: state.opts.Progress, - Flush: state.opts.ProgressFlush, Title: "resolving deltas", Total: uint64(pending), }) diff --git a/format/packfile/ingest/rev_write.go b/format/packfile/ingest/rev_write.go index f8c30c1b..16d27085 100644 --- a/format/packfile/ingest/rev_write.go +++ b/format/packfile/ingest/rev_write.go @@ -61,7 +61,6 @@ func writeRev(state *ingestState) error { entriesMeter := progress.New(progress.Options{ Writer: state.opts.Progress, - Flush: state.opts.ProgressFlush, Title: "writing reverse index entries", Total: uint64(len(packOrder)), }) diff --git a/format/packfile/ingest/scan.go b/format/packfile/ingest/scan.go index de4e993c..ddd1eaf3 100644 --- a/format/packfile/ingest/scan.go +++ b/format/packfile/ingest/scan.go @@ -37,7 +37,6 @@ func streamPackAndScan(state *ingestState) error { total := state.objectCountHeader meter := progress.New(progress.Options{ Writer: state.opts.Progress, - Flush: state.opts.ProgressFlush, Title: "receiving objects", Total: uint64(total), Throughput: true, diff --git a/format/packfile/ingest/thin_fix.go b/format/packfile/ingest/thin_fix.go index 3dad1354..f66ed279 100644 --- a/format/packfile/ingest/thin_fix.go +++ b/format/packfile/ingest/thin_fix.go @@ -60,7 +60,6 @@ func maybeFixThin(state *ingestState) error { total := len(baseIDs) meter := progress.New(progress.Options{ Writer: state.opts.Progress, - Flush: state.opts.ProgressFlush, Title: "fixing thin pack", Total: uint64(total), }) diff --git a/internal/progress/meter.go b/internal/progress/meter.go index 3c0079dd..bdf0e613 100644 --- a/internal/progress/meter.go +++ b/internal/progress/meter.go @@ -1,14 +1,14 @@ package progress import ( - "io" "time" + + "codeberg.org/lindenii/furgit/common/iowrap" ) // Meter renders one in-place progress line. type Meter struct { - writer io.Writer - flush func() error + writer iowrap.WriteFlusher title string total uint64 diff --git a/internal/progress/new.go b/internal/progress/new.go index a86a0660..2c304279 100644 --- a/internal/progress/new.go +++ b/internal/progress/new.go @@ -8,7 +8,6 @@ func New(opts Options) *Meter { return &Meter{ writer: opts.Writer, - flush: opts.Flush, title: opts.Title, total: opts.Total, delay: max(opts.Delay, time.Duration(0)), diff --git a/internal/progress/options.go b/internal/progress/options.go index d7c08894..40dd9758 100644 --- a/internal/progress/options.go +++ b/internal/progress/options.go @@ -1,14 +1,14 @@ package progress import ( - "io" "time" + + "codeberg.org/lindenii/furgit/common/iowrap" ) // Options configures one progress meter. type Options struct { - Writer io.Writer - Flush func() error + Writer iowrap.WriteFlusher Title string Total uint64 diff --git a/internal/progress/render.go b/internal/progress/render.go index 6173016a..ae188c0e 100644 --- a/internal/progress/render.go +++ b/internal/progress/render.go @@ -32,7 +32,7 @@ func (meter *Meter) render(now time.Time, eol string) { utils.BestEffortFprintf(meter.writer, "%s", line) - if meter.flush != nil { - _ = meter.flush() + if meter.writer != nil { + _ = meter.writer.Flush() } } diff --git a/network/protocol/pktline/encoder.go b/network/protocol/pktline/encoder.go index b4c6dbf0..3d92ca19 100644 --- a/network/protocol/pktline/encoder.go +++ b/network/protocol/pktline/encoder.go @@ -3,26 +3,20 @@ package pktline import ( "fmt" "io" -) -// WriteFlusher is the output transport contract required by Encoder. -// -// Write emits framed bytes and Flush pushes buffered transport state. -type WriteFlusher interface { - io.Writer - Flush() error -} + "codeberg.org/lindenii/furgit/common/iowrap" +) // Encoder writes pkt-line frames to a flush-capable output transport. // // It writes exactly one frame per method call and does not auto-chunk data. type Encoder struct { - w WriteFlusher + w iowrap.WriteFlusher maxData int } // NewEncoder creates an encoder over w. -func NewEncoder(w WriteFlusher) *Encoder { +func NewEncoder(w iowrap.WriteFlusher) *Encoder { return &Encoder{ w: w, maxData: LargePacketDataMax, diff --git a/network/protocol/sideband64k/encoder.go b/network/protocol/sideband64k/encoder.go index 9f729d15..8b48566d 100644 --- a/network/protocol/sideband64k/encoder.go +++ b/network/protocol/sideband64k/encoder.go @@ -3,6 +3,7 @@ package sideband64k import ( "fmt" + "codeberg.org/lindenii/furgit/common/iowrap" "codeberg.org/lindenii/furgit/network/protocol/pktline" ) @@ -15,7 +16,7 @@ type Encoder struct { } // NewEncoder creates an encoder over w. -func NewEncoder(w pktline.WriteFlusher) *Encoder { +func NewEncoder(w iowrap.WriteFlusher) *Encoder { return &Encoder{ enc: pktline.NewEncoder(w), maxData: DataMax, diff --git a/network/protocol/v0v1/server/receivepack/session.go b/network/protocol/v0v1/server/receivepack/session.go index 55019714..d7b2a7c5 100644 --- a/network/protocol/v0v1/server/receivepack/session.go +++ b/network/protocol/v0v1/server/receivepack/session.go @@ -5,6 +5,7 @@ import ( "io" "strings" + "codeberg.org/lindenii/furgit/common/iowrap" common "codeberg.org/lindenii/furgit/network/protocol/v0v1/server" objectid "codeberg.org/lindenii/furgit/object/id" ) @@ -168,7 +169,7 @@ func (session *Session) WriteProgress(p []byte) error { // ProgressWriter returns one chunking writer for sideband progress output. // // When side-band-64k was not negotiated, writes are discarded. -func (session *Session) ProgressWriter() io.Writer { +func (session *Session) ProgressWriter() iowrap.WriteFlusher { return session.base.ProgressWriter() } diff --git a/network/protocol/v0v1/server/session.go b/network/protocol/v0v1/server/session.go index ab79a7d7..0a4ecb53 100644 --- a/network/protocol/v0v1/server/session.go +++ b/network/protocol/v0v1/server/session.go @@ -3,6 +3,7 @@ package server import ( "io" + "codeberg.org/lindenii/furgit/common/iowrap" "codeberg.org/lindenii/furgit/network/protocol/pktline" "codeberg.org/lindenii/furgit/network/protocol/sideband64k" objectid "codeberg.org/lindenii/furgit/object/id" @@ -26,7 +27,7 @@ type Session struct { } // NewSession creates one v0/v1 server session over r and w. -func NewSession(r io.Reader, w pktline.WriteFlusher, opts Options) *Session { +func NewSession(r io.Reader, w iowrap.WriteFlusher, opts Options) *Session { return &Session{ dec: pktline.NewDecoder(r, pktline.ReadOptions{}), enc: pktline.NewEncoder(w), @@ -96,15 +97,31 @@ func (session *Session) FlushIO() error { return session.enc.FlushIO() } +type flushWriter struct { + writer io.Writer + flush func() error +} + +func (w flushWriter) Write(p []byte) (int, error) { + return w.writer.Write(p) +} + +func (w flushWriter) Flush() error { + return w.flush() +} + // ProgressWriter returns one chunking writer for sideband progress output. // // When side-band-64k was not negotiated, writes are discarded. -func (session *Session) ProgressWriter() io.Writer { +func (session *Session) ProgressWriter() iowrap.WriteFlusher { if !session.useSideBand { - return io.Discard + return iowrap.NopFlush(io.Discard) } - return sideband64k.NewChunkWriter(session.sideband, sideband64k.BandProgress) + return flushWriter{ + writer: sideband64k.NewChunkWriter(session.sideband, sideband64k.BandProgress), + flush: session.sideband.FlushIO, + } } // ErrorWriter returns one chunking writer for sideband error output. diff --git a/network/receivepack/hook.go b/network/receivepack/hook.go index 96027769..22135746 100644 --- a/network/receivepack/hook.go +++ b/network/receivepack/hook.go @@ -4,6 +4,7 @@ import ( "context" "io" + "codeberg.org/lindenii/furgit/common/iowrap" commitgraphread "codeberg.org/lindenii/furgit/format/commitgraph/read" "codeberg.org/lindenii/furgit/network/receivepack/service" objectid "codeberg.org/lindenii/furgit/object/id" @@ -12,7 +13,7 @@ import ( ) type HookIO struct { - Progress io.Writer + Progress iowrap.WriteFlusher Error io.Writer } diff --git a/network/receivepack/receivepack.go b/network/receivepack/receivepack.go index 1052848e..26fce24c 100644 --- a/network/receivepack/receivepack.go +++ b/network/receivepack/receivepack.go @@ -4,7 +4,7 @@ import ( "context" "io" - "codeberg.org/lindenii/furgit/network/protocol/pktline" + "codeberg.org/lindenii/furgit/common/iowrap" common "codeberg.org/lindenii/furgit/network/protocol/v0v1/server" protoreceive "codeberg.org/lindenii/furgit/network/protocol/v0v1/server/receivepack" "codeberg.org/lindenii/furgit/network/receivepack/service" @@ -23,7 +23,7 @@ import ( // Labels: Deps-Borrowed. func ReceivePack( ctx context.Context, - w pktline.WriteFlusher, + w iowrap.WriteFlusher, r io.Reader, opts Options, ) error { @@ -89,12 +89,10 @@ func ReceivePack( return err } - progressWriter := protoSession.ProgressWriter() - progressFlush := base.FlushIO + progress := protoSession.ProgressWriter() if req.Capabilities.Quiet { - progressWriter = io.Discard - progressFlush = nil + progress = iowrap.NopFlush(io.Discard) } serviceReq := &service.Request{ @@ -112,14 +110,13 @@ func ReceivePack( ExistingObjects: opts.ExistingObjects, CommitGraph: opts.CommitGraph, ObjectsRoot: opts.ObjectsRoot, - Progress: progressWriter, - ProgressFlush: progressFlush, + Progress: progress, PromotedObjectPermissions: translatePromotedObjectPermissions( opts.PromotedObjectPermissions, ), Hook: translateHook(opts.Hook), HookIO: service.HookIO{ - Progress: progressWriter, + Progress: progress, Error: protoSession.ErrorWriter(), }, }) diff --git a/network/receivepack/service/hook.go b/network/receivepack/service/hook.go index 66ff0929..7f7b88b5 100644 --- a/network/receivepack/service/hook.go +++ b/network/receivepack/service/hook.go @@ -4,6 +4,7 @@ import ( "context" "io" + "codeberg.org/lindenii/furgit/common/iowrap" commitgraphread "codeberg.org/lindenii/furgit/format/commitgraph/read" objectid "codeberg.org/lindenii/furgit/object/id" objectstore "codeberg.org/lindenii/furgit/object/store" @@ -11,7 +12,7 @@ import ( ) type HookIO struct { - Progress io.Writer + Progress iowrap.WriteFlusher Error io.Writer } diff --git a/network/receivepack/service/ingest_quarantine.go b/network/receivepack/service/ingest_quarantine.go index 1ed62a73..14083fe1 100644 --- a/network/receivepack/service/ingest_quarantine.go +++ b/network/receivepack/service/ingest_quarantine.go @@ -50,11 +50,10 @@ func (service *Service) ingestQuarantine( req.Pack, service.opts.Algorithm, ingest.Options{ - FixThin: true, - WriteRev: true, - Base: service.opts.ExistingObjects, - Progress: service.opts.Progress, - ProgressFlush: service.opts.ProgressFlush, + FixThin: true, + WriteRev: true, + Base: service.opts.ExistingObjects, + Progress: service.opts.Progress, }, ) if err != nil { diff --git a/network/receivepack/service/options.go b/network/receivepack/service/options.go index ab867bce..82c496c3 100644 --- a/network/receivepack/service/options.go +++ b/network/receivepack/service/options.go @@ -1,10 +1,10 @@ package service import ( - "io" "io/fs" "os" + "codeberg.org/lindenii/furgit/common/iowrap" commitgraphread "codeberg.org/lindenii/furgit/format/commitgraph/read" objectid "codeberg.org/lindenii/furgit/object/id" objectstore "codeberg.org/lindenii/furgit/object/store" @@ -22,16 +22,15 @@ type PromotedObjectPermissions struct { // // Refs and ExistingObjects are required and must be non-nil. // ObjectsRoot is required if Execute may need to ingest or promote a pack. -// Progress, ProgressFlush, Hook, and HookIO are optional; when provided they -// are also borrowed for the duration of Execute. +// Progress, Hook, and HookIO are optional; when provided they are also +// borrowed for the duration of Execute. type Options struct { Algorithm objectid.Algorithm Refs refstore.ReadWriteStore ExistingObjects objectstore.ReadingStore CommitGraph *commitgraphread.Reader ObjectsRoot *os.Root - Progress io.Writer - ProgressFlush func() error + Progress iowrap.WriteFlusher PromotedObjectPermissions *PromotedObjectPermissions Hook Hook HookIO HookIO |
