Artifact b306110e69c5d1c83033ee3ab012fd0699e1f06f0c5b7e5d9cf1538d68825523:
- File
repo_ids.go
— part of check-in
[61aa4dd022]
at
2026-05-04 18:59:12
on branch trunk
— feat: add Repo.UUIDFromRID for public rid->uuid lookup (#25)
Consumers (bones, EdgeSync) currently bypass the methods-only Repo API to convert RIDs to UUIDs by reaching into r.DB() and running raw SQL. The lookup is well-defined and recurs throughout the libfossil internals; expose it as a first-class method.
Add Repo.UUIDFromRID(rid int64) (string, error) backed by a small internal helper Repo.UUIDByRID on internal/repo so the SELECT lives in one place. Missing rids surface ErrArtifactNotFound (wraps sql.ErrNoRows behind a typed sentinel) with the rid in the message.
closes #23 (user: [email protected], size: 814) [annotate] [blame] [check-ins using]
package libfossil import ( "database/sql" "errors" "fmt" ) // UUIDFromRID returns the UUID (manifest hash) of the artifact identified by // rid. The UUID is the stable, content-addressed identifier for the artifact; // the rid is a repository-local integer that may differ across clones. // // Returns ErrArtifactNotFound (wrapped) if no artifact with the given rid // exists in the repository. The wrapped error message includes the offending // rid. Other errors surface as-is. func (r *Repo) UUIDFromRID(rid int64) (string, error) { uuid, err := r.inner.UUIDByRID(rid) if err != nil { if errors.Is(err, sql.ErrNoRows) { return "", fmt.Errorf("libfossil: uuid from rid %d: %w", rid, ErrArtifactNotFound) } return "", fmt.Errorf("libfossil: uuid from rid %d: %w", rid, err) } return uuid, nil }