Artifact e13e6ac8f14c30fb10e7d636ca4d79efcb8571eb0c334767b7e4ba273c936580:
- File
cli/repo_serve.go
— part of check-in
[7572f7d420]
at
2026-07-19 18:31:37
on branch trunk
— cli: add repo serve command wiring the xfer HTTP server (#72)
* cli: add repo serve command wiring the xfer HTTP server
Repo.ServeHTTP has always been public, but nothing in the CLI called it, so a repo created or cloned with this tool could only ever be a clone leaf. Add `libfossil repo serve` as a thin adapter: open the repo, build the bind address, translate process interrupt into the context cancellation ServeHTTP already honors, and call it. No new server or shutdown logic.
Binds to 127.0.0.1:8080 by default; --addr overrides host and/or port. Verified against a stock fossil client (canonical binary, not just this library's own transport) cloning over an actual TCP round trip.
* cli: address review nits on serve interop test
Document why TestRepoServeCmdRun and TestRepoServeCmdCanonicalFossilClone are allowed to send a real SIGINT to the test process (no t.Parallel(), no competing signal handlers in package cli_test), so a future test in this package doesn't silently break that assumption.
Also log the canonical fossil binary path and version the interop test actually exercised. A skip and a pass read identically in a non-verbose CI log; if the apt install step that puts fossil on PATH is ever removed or reordered, this line is what would tell us the test stopped proving anything instead of just staying green. (user: [email protected], size: 1008) [annotate] [blame] [check-ins using]
package cli import ( "context" "fmt" "os" "os/signal" "syscall" ) // RepoServeCmd starts an HTTP xfer server for the repository so a remote // fossil client -- the canonical binary or another instance of this tool -- // can clone or sync against it. This is a thin wrapper: all serving logic // lives in Repo.ServeHTTP; the command's job is to open the repo, resolve // the bind address, and translate process interrupt into the context // cancellation that ServeHTTP already honors. type RepoServeCmd struct { Addr string `short:"P" default:"127.0.0.1:8080" help:"Bind address as host:port"` } func (c *RepoServeCmd) Run(g *Globals) error { r, err := g.OpenRepo() if err != nil { return err } defer r.Close() ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM) defer stop() fmt.Printf("serving %s on http://%s (Ctrl-C to stop)\n", g.Repo, c.Addr) if err := r.ServeHTTP(ctx, c.Addr); err != nil { return fmt.Errorf("serve: %w", err) } return nil }