From 85301b69f478c34e3ee7488f5b04ae4ac5b3ba1e Mon Sep 17 00:00:00 2001 From: Bernhard Guillon Date: Tue, 7 Jul 2026 12:32:15 +0200 Subject: Chunk manifest transfer: 1000 files per batch Avoids bufio.Scanner token limit by sending manifest in batches. Each batch is a separate JSON line with up to 1000 files. --- cmd_windows.go | 42 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 8 deletions(-) (limited to 'cmd_windows.go') diff --git a/cmd_windows.go b/cmd_windows.go index 7df0a9b..dfe137a 100644 --- a/cmd_windows.go +++ b/cmd_windows.go @@ -275,16 +275,42 @@ func scanDirectory(root string, stack *GitignoreStack) *Manifest { } func sendManifest(conn net.Conn, manifest *Manifest) { - msg := &ProtocolMessage{ - Type: "manifest", - Files: manifest.ToJSON(), + const batchSize = 1000 + files := make([]FileMetaJSON, 0, batchSize) + paths := make([]string, 0, batchSize) + + for path, meta := range manifest.ToJSON() { + paths = append(paths, path) + files = append(files, meta) + + if len(files) >= batchSize { + msg := &ProtocolMessage{ + Type: "manifest_batch", + Files: make(map[string]FileMetaJSON), + } + for i, p := range paths { + msg.Files[p] = files[i] + } + data, _ := EncodeMessage(msg) + data = append(data, '\n') + conn.Write(data) + files = files[:0] + paths = paths[:0] + } } - data, err := EncodeMessage(msg) - if err != nil { - return + + if len(files) > 0 { + msg := &ProtocolMessage{ + Type: "manifest_batch", + Files: make(map[string]FileMetaJSON), + } + for i, p := range paths { + msg.Files[p] = files[i] + } + data, _ := EncodeMessage(msg) + data = append(data, '\n') + conn.Write(data) } - data = append(data, '\n') - conn.Write(data) done := &ProtocolMessage{Type: "manifest_done"} doneData, _ := EncodeMessage(done) -- cgit v1.2.3