Documentation
¶
Index ¶
- Constants
- func SetDefault(db *DB)
- type Blob
- type Commit
- type DB
- func (db *DB) Begin(ctx context.Context) (pgx.Tx, error)
- func (db *DB) BeginTx(ctx context.Context, opts pgx.TxOptions) (pgx.Tx, error)
- func (db *DB) BlobExists(ctx context.Context, path, commitID string) (bool, error)
- func (db *DB) Close()
- func (db *DB) CommitExists(ctx context.Context, id string) (bool, error)
- func (db *DB) CountCommits(ctx context.Context) (int, error)
- func (db *DB) CreateBlob(ctx context.Context, b *Blob) error
- func (db *DB) CreateBlobs(ctx context.Context, blobs []*Blob) error
- func (db *DB) CreateCommit(ctx context.Context, c *Commit) error
- func (db *DB) CreateCommitsBatch(ctx context.Context, commits []*Commit) error
- func (db *DB) DeleteCommitsAfter(ctx context.Context, commitID string) error
- func (db *DB) DeleteMetadata(ctx context.Context, key string) error
- func (db *DB) DeleteRef(ctx context.Context, name string) error
- func (db *DB) DeleteSyncState(ctx context.Context, remoteName string) error
- func (db *DB) DropSchema(ctx context.Context) error
- func (db *DB) EnsureMetadataTable(ctx context.Context) error
- func (db *DB) Exec(ctx context.Context, sql string, args ...any) error
- func (db *DB) FindCommonAncestor(ctx context.Context, commitA, commitB string) (string, error)
- func (db *DB) GetAllCommits(ctx context.Context) ([]*Commit, error)
- func (db *DB) GetAllPaths(ctx context.Context) ([]string, error)
- func (db *DB) GetAllRefs(ctx context.Context) ([]*Ref, error)
- func (db *DB) GetAllSyncStates(ctx context.Context) ([]*SyncState, error)
- func (db *DB) GetBlob(ctx context.Context, path, commitID string) (*Blob, error)
- func (db *DB) GetBlobStats(ctx context.Context) (map[string]interface{}, error)
- func (db *DB) GetBlobsAtCommit(ctx context.Context, commitID string) ([]*Blob, error)
- func (db *DB) GetChangedFiles(ctx context.Context, fromCommit, toCommit string) ([]*Blob, error)
- func (db *DB) GetCommit(ctx context.Context, id string) (*Commit, error)
- func (db *DB) GetCommitLog(ctx context.Context, limit int) ([]*Commit, error)
- func (db *DB) GetCommitLogFrom(ctx context.Context, commitID string, limit int) ([]*Commit, error)
- func (db *DB) GetCommitStats(ctx context.Context) (map[string]interface{}, error)
- func (db *DB) GetCurrentTree(ctx context.Context) ([]*Blob, error)
- func (db *DB) GetFileAtCommit(ctx context.Context, path, commitID string) (*Blob, error)
- func (db *DB) GetFileHistory(ctx context.Context, path string) ([]*Blob, error)
- func (db *DB) GetHead(ctx context.Context) (string, error)
- func (db *DB) GetHeadCommit(ctx context.Context) (*Commit, error)
- func (db *DB) GetLatestCommitID(ctx context.Context) (string, error)
- func (db *DB) GetMetadata(ctx context.Context, key string) (string, error)
- func (db *DB) GetRef(ctx context.Context, name string) (*Ref, error)
- func (db *DB) GetRepoPath(ctx context.Context) string
- func (db *DB) GetRepoStatsFast(ctx context.Context) (*RepoStats, error)
- func (db *DB) GetSyncState(ctx context.Context, remoteName string) (*SyncState, error)
- func (db *DB) GetTreeAtCommit(ctx context.Context, commitID string) ([]*Blob, error)
- func (db *DB) GetXpatchStats(ctx context.Context, tableName string) (*XpatchStats, error)
- func (db *DB) InitSchema(ctx context.Context) error
- func (db *DB) IsConnected() bool
- func (db *DB) Ping(ctx context.Context) error
- func (db *DB) Pool() *pgxpool.Pool
- func (db *DB) Query(ctx context.Context, sql string, args ...any) (pgx.Rows, error)
- func (db *DB) QueryRow(ctx context.Context, sql string, args ...any) pgx.Row
- func (db *DB) RefExists(ctx context.Context, name string) (bool, error)
- func (db *DB) SchemaExists(ctx context.Context) (bool, error)
- func (db *DB) SearchAllBlobs(ctx context.Context, pathPattern string) ([]*Blob, error)
- func (db *DB) SetHead(ctx context.Context, commitID string) error
- func (db *DB) SetMetadata(ctx context.Context, key, value string) error
- func (db *DB) SetRef(ctx context.Context, name, commitID string) error
- func (db *DB) SetRepoPath(ctx context.Context, path string) error
- func (db *DB) SetSyncState(ctx context.Context, remoteName string, lastCommitID *string) error
- func (db *DB) URL() string
- func (db *DB) WithTx(ctx context.Context, fn func(tx pgx.Tx) error) error
- type Ref
- type RepoStats
- type SyncState
- type XpatchStats
Constants ¶
const (
MetaKeyRepoPath = "repo_path"
)
Metadata keys
const SchemaVersion = 1
Schema version for migrations
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Blob ¶
type Blob struct {
Path string
CommitID string
Content []byte // file bytes (empty for empty files)
ContentHash *string // nil = deleted, otherwise hash of content
Mode int
IsSymlink bool
SymlinkTarget *string
}
Blob represents a file at a specific commit
type Commit ¶
type Commit struct {
ID string
ParentID *string
TreeHash string
Message string
AuthorName string
AuthorEmail string
CreatedAt time.Time
}
Commit represents a commit in the database
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB holds the database connection pool
func (*DB) BlobExists ¶
BlobExists checks if a blob exists at a specific commit
func (*DB) CommitExists ¶
CommitExists checks if a commit exists
func (*DB) CountCommits ¶
CountCommits returns the total number of commits
func (*DB) CreateBlob ¶
CreateBlob inserts a new blob into the database
func (*DB) CreateBlobs ¶
CreateBlobs inserts multiple blobs using COPY for speed
func (*DB) CreateCommit ¶
CreateCommit inserts a new commit into the database
func (*DB) CreateCommitsBatch ¶ added in v1.1.0
CreateCommitsBatch inserts multiple commits using pgx.CopyFrom for speed Commits must be in order (parents before children)
func (*DB) DeleteCommitsAfter ¶
DeleteCommitsAfter deletes all commits after (and including) the given commit ID This is used during the "rebuild on divergence" process
func (*DB) DeleteMetadata ¶ added in v1.1.0
DeleteMetadata removes a metadata key
func (*DB) DeleteSyncState ¶
DeleteSyncState deletes the sync state for a remote
func (*DB) DropSchema ¶
DropSchema drops all pgit tables (use with caution!)
func (*DB) EnsureMetadataTable ¶ added in v1.1.0
EnsureMetadataTable creates the metadata table if it doesn't exist
func (*DB) FindCommonAncestor ¶
FindCommonAncestor finds the common ancestor between two commits
func (*DB) GetAllCommits ¶
GetAllCommits retrieves all commits ordered by ID (ULID = time order)
func (*DB) GetAllPaths ¶
GetAllPaths returns all unique file paths in the repository
func (*DB) GetAllRefs ¶
GetAllRefs retrieves all refs
func (*DB) GetAllSyncStates ¶
GetAllSyncStates retrieves all sync states
func (*DB) GetBlobStats ¶
GetBlobStats returns statistics about blobs using xpatch.stats() for O(1) performance
func (*DB) GetBlobsAtCommit ¶
GetBlobsAtCommit retrieves all blobs at a specific commit
func (*DB) GetChangedFiles ¶
GetChangedFiles returns files that changed between two commits
func (*DB) GetCommitLog ¶
GetCommitLog retrieves commits starting from HEAD, walking up the parent chain
func (*DB) GetCommitLogFrom ¶
GetCommitLogFrom retrieves commits starting from a specific commit
func (*DB) GetCommitStats ¶
GetCommitStats returns statistics about commits using xpatch.stats() for O(1) performance
func (*DB) GetCurrentTree ¶
GetCurrentTree retrieves the tree at HEAD
func (*DB) GetFileAtCommit ¶
GetFileAtCommit retrieves a file at a specific commit (or the latest version before it)
func (*DB) GetFileHistory ¶
GetFileHistory retrieves all versions of a file
func (*DB) GetHeadCommit ¶
GetHeadCommit retrieves the commit that HEAD points to
func (*DB) GetLatestCommitID ¶
GetLatestCommitID returns the ID of the latest commit (by ULID order)
func (*DB) GetMetadata ¶ added in v1.1.0
GetMetadata retrieves a metadata value by key
func (*DB) GetRepoPath ¶ added in v1.1.0
GetRepoPath returns the stored repository path, or empty string if not set
func (*DB) GetRepoStatsFast ¶
GetRepoStatsFast returns repository statistics using xpatch.stats() for O(1) performance
func (*DB) GetSyncState ¶
GetSyncState retrieves the sync state for a remote
func (*DB) GetTreeAtCommit ¶
GetTreeAtCommit retrieves the full tree (all files) at a commit This uses the ULID ordering to find the latest version of each file
func (*DB) GetXpatchStats ¶
GetXpatchStats retrieves compression statistics for a table
func (*DB) InitSchema ¶
InitSchema creates the pgit schema in the database
func (*DB) IsConnected ¶
IsConnected returns true if the database is connected
func (*DB) SchemaExists ¶
SchemaExists checks if the pgit schema exists
func (*DB) SearchAllBlobs ¶
SearchAllBlobs retrieves all blobs, optionally filtered by path pattern
func (*DB) SetMetadata ¶ added in v1.1.0
SetMetadata sets a metadata key-value pair (upsert)
func (*DB) SetRepoPath ¶ added in v1.1.0
SetRepoPath stores the repository working directory path
func (*DB) SetSyncState ¶
SetSyncState creates or updates the sync state for a remote
type RepoStats ¶
type RepoStats struct {
// Commit stats
TotalCommits int64
FirstCommitID *string
LastCommitID *string
// Blob stats
TotalBlobs int64
UniqueFiles int64
TotalContentSize int64
DeletedEntries int64
// Size from PostgreSQL (actual disk usage)
CommitsTableSize int64
BlobsTableSize int64
TotalIndexSize int64
}
RepoStats contains all repository statistics
type XpatchStats ¶
type XpatchStats struct {
TotalRows int64
TotalGroups int64
KeyframeCount int64
DeltaCount int64
RawSizeBytes int64
CompressedBytes int64
CompressionRatio float64
CacheHits int64
CacheMisses int64
AvgChainLength float64
}
XpatchStats represents compression statistics from pg-xpatch