Artifact 941ea40ee75f765d46e1e0043257aa773f5abfd801c26f02f6b65fce087579d0:
- File
repo_pull.go
— part of check-in
[9594cf3bae]
at
2026-10-29 03:06:23
on branch main
— perf(wasm): add a libfossil_nohttp build tag that leaves out net/http
Under TinyGo, importing net/http at all links its TLS and X.509 code (crypto/x509, encoding/asn1, math/big's integers, AES-GCM, SHA-3, netip) whether or not a request is ever made: a five-line program that calls only http.StatusText grows by about 430 KB raw. The library imports it for its HTTP client transport and its HTTP server, which a program that serves sync through HandleSyncWithOpts and supplies its own transport never calls.
Built with -tags libfossil_nohttp, the library leaves out NewHTTPTransport, WithHTTPClient, Repo.Pull, Repo.XferHandler and Repo.ServeHTTP, and the internal/sync client, server, redirect handling and peer-address trace they use. HandleSync, HandleSyncWithOpts, Sync over a host Transport and everything else are unchanged. Without the tag nothing changes. The retry classifier keeps the two statuses it read from net/http as constants, and DNS fault classification moves to its own file so it stays in the tagged build.
For the html-artifact-publisher engine (TinyGo 0.43.0, Go 1.26.0) the tag takes the gzipped binary from 1,100,251 to 1,003,279 bytes. A test builds the library, db and simio with the tag for the host and js/wasm and checks none links net/http, net/http/httptrace or crypto/tls, and that the untagged library still does. (user: [email protected], size: 1749) [annotate] [blame] [check-ins using] [more...]
//go:build !libfossil_nohttp package libfossil // Pull dials its peer through NewHTTPTransport, so a build with the // libfossil_nohttp tag, which leaves out net/http, leaves it out too. import ( "context" "fmt" ) // PullOpts configures a pull-only sync. Fields are a subset of SyncOpts; // Pull is hard-coded true and Push is hard-coded false to keep the API // surface honest about what Pull does. type PullOpts struct { // ProjectCode optionally pins the expected server project code. Empty // accepts whatever the peer advertises (matches existing Sync semantics). ProjectCode string // MaxSend caps the bytes the client will send per round (mostly clones // of clients with UV files). Zero leaves the existing default in place. MaxSend int // Observer receives sync-progress events. nil disables observation. Observer SyncObserver } // Pull fetches commits and ancillary objects from a Fossil HTTP peer and // applies them to this repo. It is a strict pull — nothing is sent. // // Tiger Style: hostile inputs panic via assert at the boundary; transport // failures return wrapped errors. Idempotent on a repo already at peer's // tip (returns a SyncResult with Rounds=0–1 and FilesRecvd=0). func (r *Repo) Pull(ctx context.Context, url string, opts PullOpts) (*SyncResult, error) { if ctx == nil { panic("libfossil: Pull: ctx is nil") } if url == "" { panic("libfossil: Pull: url is empty") } transport := NewHTTPTransport(url) res, err := r.Sync(ctx, transport, SyncOpts{ Pull: true, Push: false, ProjectCode: opts.ProjectCode, MaxSend: opts.MaxSend, Observer: opts.Observer, }) if err != nil { return res, fmt.Errorf("libfossil: pull %s: %w", url, err) } return res, nil }