Artifact f0e17c669a2ddcac225bd104878ada224e7094636b23ad48e88028c014d67277:
- File
hub/commit.go
— part of check-in
[5f025def67]
at
2026-05-04 20:51:09
on branch trunk
— feat(hub): add OpenRepo + *hub.Repo type for server-less operations (#134)
Adds hub.OpenRepo(path) (*Repo, error) — a server-less handle for one-off CLI invocations and short-lived helpers (bones #186 needs this for `bones hub user list`, `bones plan finalize`, and slot-user provisioning, all of which currently drop to direct libfossil.Open because hub.NewHub spins up a redundant NATS server every time).
The new *hub.Repo type holds the libfossil handle and carries every user / commit / read method that *hub.Hub used to define on itself. *hub.Hub now holds a *hub.Repo internally and one-line-delegates each method, so both code paths share method bodies — no duplication.
Adds Hub.Repo() *Repo accessor for sharing the live handle out of a running hub. Documented contract: don't call Close on a *Repo returned by Hub.Repo while the Hub is still serving — Hub.Stop is the right teardown for that case. Repo.Close is idempotent so accidental double- close from teardown ordering is safe.
Tests: - TestOpenRepo_RoundTrip — every *Repo method against a path bootstrapped by NewHub. Same observable state. - TestOpenRepo_RejectsEmptyPath, TestOpenRepo_RejectsMissingPath. - TestRepo_Close_IsIdempotent. - TestHub_Repo_AccessorReturnsLiveHandle — operations on the *Repo accessor are observable via the *Hub.
Closes #131 (user: [email protected], size: 966) [annotate] [blame] [check-ins using]
package hub import "context" // RevID is an opaque commit handle. type RevID string // FileToCommit names a file and its content for inclusion in a commit. type FileToCommit struct { Name string Content []byte } // CommitOpts configures Hub.Commit / Repo.Commit. type CommitOpts struct { Files []FileToCommit Message string Author string // fossil user; required } // Commit commits a set of files to the hub repo. func (h *Hub) Commit(ctx context.Context, opts CommitOpts) (RevID, error) { return h.repo.Commit(ctx, opts) } // Read returns the contents of path at the current trunk tip. func (h *Hub) Read(ctx context.Context, path string) ([]byte, error) { return h.repo.Read(ctx, path) } // ReadAt returns the contents of path at rev. rev may be a branch name // (e.g. "trunk"), a tag, or a RevID returned from Commit. func (h *Hub) ReadAt(ctx context.Context, rev RevID, path string) ([]byte, error) { return h.repo.ReadAt(ctx, rev, path) }