Documentation
¶
Index ¶
- Constants
- func SetDefault(db *DB)
- type AmbiguousCommitError
- type Blob
- type Commit
- type Content
- type ContentKey
- type ContentVersionPair
- 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) ContentExists(ctx context.Context, groupID, versionID int32) (bool, error)
- func (db *DB) CountBlobs(ctx context.Context) (int64, error)
- func (db *DB) CountCommits(ctx context.Context) (int, error)
- func (db *DB) CountContents(ctx context.Context) (int64, error)
- func (db *DB) CountFileRefs(ctx context.Context) (int64, error)
- func (db *DB) CountPaths(ctx context.Context) (int64, error)
- func (db *DB) CreateBlob(ctx context.Context, b *Blob) error
- func (db *DB) CreateBlobs(ctx context.Context, blobs []*Blob) error
- func (db *DB) CreateBlobsForGroup(ctx context.Context, blobs []*Blob, groupID int32, versionCounter *int32, ...) error
- func (db *DB) CreateBlobsTx(ctx context.Context, tx pgx.Tx, 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) CreateCommitsBatchTx(ctx context.Context, tx pgx.Tx, commits []*Commit) error
- func (db *DB) CreateContent(ctx context.Context, c *Content) error
- func (db *DB) CreateContentBatch(ctx context.Context, contents []*Content) error
- func (db *DB) CreateContentTx(ctx context.Context, tx pgx.Tx, c *Content) error
- func (db *DB) CreateFileRef(ctx context.Context, ref *FileRef) error
- func (db *DB) CreateFileRefTx(ctx context.Context, tx pgx.Tx, ref *FileRef) error
- func (db *DB) CreateFileRefsBatch(ctx context.Context, refs []*FileRef) error
- func (db *DB) CreateFileRefsIndexes(ctx context.Context) error
- func (db *DB) DeleteBlobsForCommits(ctx context.Context, commitIDs []string) error
- func (db *DB) DeleteCommits(ctx context.Context, commitIDs []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) DropFileRefsIndexes(ctx context.Context) 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) FileExistsInTree(ctx context.Context, path, commitID string) (bool, error)
- func (db *DB) FileRefExists(ctx context.Context, groupID int32, commitID string) (bool, error)
- func (db *DB) FindCommitByPartialID(ctx context.Context, partialID string) (*Commit, error)
- func (db *DB) FindCommonAncestor(ctx context.Context, commitA, commitB string) (string, error)
- func (db *DB) GetAllCommitIDsOrdered(ctx context.Context) ([]string, error)
- func (db *DB) GetAllCommits(ctx context.Context) ([]*Commit, error)
- func (db *DB) GetAllContentForGroup(ctx context.Context, groupID int32, isBinary bool) ([]ContentVersionPair, error)
- func (db *DB) GetAllPaths(ctx context.Context) ([]string, error)
- func (db *DB) GetAllPathsV2(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) GetBlobsAtCommitMetadata(ctx context.Context, commitID string) ([]*Blob, error)
- func (db *DB) GetChangedFileRefs(ctx context.Context, fromCommit, toCommit string) ([]*FileRef, error)
- func (db *DB) GetChangedFileRefsWithPaths(ctx context.Context, fromCommit, toCommit string) ([]*FileRefWithPath, error)
- func (db *DB) GetChangedFiles(ctx context.Context, fromCommit, toCommit string) ([]*Blob, error)
- func (db *DB) GetChangedFilesMetadata(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) GetCommitsAfter(ctx context.Context, afterID string) ([]*Commit, error)
- func (db *DB) GetCommitsBatch(ctx context.Context, ids []string) (map[string]*Commit, error)
- func (db *DB) GetCommitsBatchByRange(ctx context.Context, ids []string) (map[string]*Commit, error)
- func (db *DB) GetContent(ctx context.Context, groupID, versionID int32, isBinary bool) ([]byte, error)
- func (db *DB) GetContentForFileRef(ctx context.Context, ref *FileRef) ([]byte, error)
- func (db *DB) GetContentsBatch(ctx context.Context, keys []ContentKey, isBinaryMap map[ContentKey]bool) (map[ContentKey][]byte, error)
- func (db *DB) GetContentsByGroupID(ctx context.Context, groupID int32) ([]*Content, error)
- func (db *DB) GetContentsForFileRefs(ctx context.Context, refs []*FileRef) (map[ContentKey][]byte, error)
- func (db *DB) GetCurrentTree(ctx context.Context) ([]*Blob, error)
- func (db *DB) GetCurrentTreeMetadata(ctx context.Context) ([]*Blob, error)
- func (db *DB) GetDetailedTableSizes(ctx context.Context) (*DetailedTableSizes, 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) GetFileRef(ctx context.Context, groupID int32, commitID string) (*FileRef, error)
- func (db *DB) GetFileRefAtCommit(ctx context.Context, groupID int32, commitID string) (*FileRef, error)
- func (db *DB) GetFileRefHistory(ctx context.Context, groupID int32) ([]*FileRef, error)
- func (db *DB) GetFileRefsAtCommit(ctx context.Context, commitID string) ([]*FileRef, error)
- func (db *DB) GetFileRefsAtCommitWithPaths(ctx context.Context, commitID string) ([]*FileRefWithPath, error)
- func (db *DB) GetGroupIDByPath(ctx context.Context, path string) (int32, error)
- func (db *DB) GetHead(ctx context.Context) (string, error)
- func (db *DB) GetHeadCommit(ctx context.Context) (*Commit, error)
- func (db *DB) GetImportedPaths(ctx context.Context) (map[string]bool, error)
- func (db *DB) GetLatestCommitID(ctx context.Context) (string, error)
- func (db *DB) GetMetadata(ctx context.Context, key string) (string, error)
- func (db *DB) GetNextVersionID(ctx context.Context, groupID int32) (int32, error)
- func (db *DB) GetNextVersionIDTx(ctx context.Context, tx pgx.Tx, groupID int32) (int32, error)
- func (db *DB) GetOrCreatePath(ctx context.Context, path string) (int32, error)
- func (db *DB) GetOrCreatePathTx(ctx context.Context, tx pgx.Tx, path string) (int32, error)
- func (db *DB) GetOrCreatePathsBatch(ctx context.Context, paths []string) (map[string]int32, error)
- func (db *DB) GetPath(ctx context.Context, groupID int32) (string, error)
- func (db *DB) GetPathsByGroupIDs(ctx context.Context, groupIDs []int32) (map[int32]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) GetSchemaVersion(ctx context.Context) (int, 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) GetTreeMetadataAtCommit(ctx context.Context, commitID string) ([]*Blob, error)
- func (db *DB) GetTreeRefsAtCommit(ctx context.Context, commitID string) ([]*FileRef, error)
- func (db *DB) GetTreeRefsAtCommitWithPaths(ctx context.Context, commitID string) ([]*FileRefWithPath, 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) IsSchemaAtLeast(ctx context.Context, minVersion int) (bool, error)
- func (db *DB) Ping(ctx context.Context) error
- func (db *DB) Pool() *pgxpool.Pool
- func (db *DB) PreRegisterPaths(ctx context.Context, paths []string) (map[string]int32, error)
- 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) ResetImportGUCs(ctx context.Context) error
- func (db *DB) SchemaExists(ctx context.Context) (bool, error)
- func (db *DB) SearchContent(ctx context.Context, opts SearchContentOptions) ([]*SearchContentResult, error)
- func (db *DB) SearchContentAtCommit(ctx context.Context, commitID string, opts SearchContentOptions) ([]*SearchContentResult, error)
- func (db *DB) SetHead(ctx context.Context, commitID string) error
- func (db *DB) SetImportGUCs(ctx context.Context) 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) SetSchemaVersion(ctx context.Context, version int) 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 DetailedTableSizes
- type FileRef
- type FileRefWithPath
- type Path
- type Ref
- type RepoStats
- type SearchContentOptions
- type SearchContentResult
- type SyncState
- type XpatchStats
Constants ¶
const (
MetaKeyRepoPath = "repo_path"
)
Metadata keys
const SchemaVersion = 3
SchemaVersion is the current schema version. Version 3 introduces: - Committer fields (committer_name, committer_email, committed_at) - Renamed created_at -> authored_at - Split content into pgit_text_content (TEXT) + pgit_binary_content (BYTEA) - Added is_binary flag to pgit_file_refs
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AmbiguousCommitError ¶ added in v3.2.0
AmbiguousCommitError is returned when a partial commit ID matches multiple commits.
func (*AmbiguousCommitError) Error ¶ added in v3.2.0
func (e *AmbiguousCommitError) Error() string
type Blob ¶
type Blob struct {
Path string
CommitID string
Content []byte // file bytes (empty for empty files)
ContentHash []byte // 16 bytes BLAKE3, nil = deleted
Mode int
IsSymlink bool
SymlinkTarget *string
IsBinary bool
}
Blob represents a file at a specific commit. This is the compatibility layer that combines data from pgit_paths, pgit_file_refs, and pgit_text_content/pgit_binary_content tables in schema v3.
type Commit ¶
type Commit struct {
ID string
ParentID *string
TreeHash string
Message string
AuthorName string
AuthorEmail string
AuthoredAt time.Time
CommitterName string
CommitterEmail string
CommittedAt time.Time
}
Commit represents a commit in the database
type Content ¶
type Content struct {
GroupID int32
VersionID int32
Content []byte
IsBinary bool // Determines which table to use
}
Content represents file content stored in text or binary content tables. Content is delta-compressed by xpatch, grouped by group_id.
type ContentKey ¶
ContentKey is used for batch lookups.
type ContentVersionPair ¶
ContentVersionPair holds a version_id and its content.
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB holds the database connection pool
func ConnectLite ¶
ConnectLite establishes a lightweight connection (single connection, no pool) Use this for quick operations like metadata lookups
func (*DB) BlobExists ¶
BlobExists checks if a blob exists at a specific commit.
func (*DB) CommitExists ¶
CommitExists checks if a commit exists
func (*DB) ContentExists ¶
ContentExists checks if content exists in either table.
func (*DB) CountBlobs ¶
CountBlobs returns the total number of blob versions (file refs).
func (*DB) CountCommits ¶
CountCommits returns the total number of commits
func (*DB) CountContents ¶
CountContents returns the total number of content entries across both tables.
func (*DB) CountFileRefs ¶
CountFileRefs returns the total number of file refs.
func (*DB) CountPaths ¶
CountPaths returns the number of unique paths in the repository.
func (*DB) CreateBlob ¶
CreateBlob inserts a new blob into the database. This writes to pgit_paths, pgit_file_refs, and pgit_text_content or pgit_binary_content.
func (*DB) CreateBlobs ¶
CreateBlobs inserts multiple blobs efficiently. Blobs should be pre-sorted by path for optimal delta compression.
func (*DB) CreateBlobsForGroup ¶ added in v3.3.0
func (db *DB) CreateBlobsForGroup(ctx context.Context, blobs []*Blob, groupID int32, versionCounter *int32, onProgress func(int)) error
CreateBlobsForGroup inserts all blobs for a single group (path) in one transaction. Large groups are split into chunks of copyChunkSize, each chunk getting its own COPY calls — but all within the same transaction to keep xpatch's delta chain on one connection.
groupID is the pre-registered group_id for this path. versionCounter points to the caller-managed next version_id for this group. onProgress is called after each chunk with the number of blobs in that chunk (may be nil).
func (*DB) CreateBlobsTx ¶ added in v3.2.0
CreateBlobsTx inserts multiple blobs within an existing transaction. Same logic as CreateBlobs but uses the provided tx instead of creating its own.
func (*DB) CreateCommit ¶
CreateCommit inserts a new commit into the database
func (*DB) CreateCommitsBatch ¶
CreateCommitsBatch inserts multiple commits using pgx.CopyFrom for speed Commits must be in order (parents before children)
func (*DB) CreateCommitsBatchTx ¶ added in v3.2.0
CreateCommitsBatchTx inserts multiple commits within an existing transaction.
func (*DB) CreateContent ¶
CreateContent inserts content into the appropriate content table.
func (*DB) CreateContentBatch ¶
CreateContentBatch inserts multiple content entries using COPY for speed. Splits into text and binary batches and writes to respective tables.
func (*DB) CreateContentTx ¶
CreateContentTx inserts content within a transaction.
func (*DB) CreateFileRef ¶
CreateFileRef inserts a new file reference.
func (*DB) CreateFileRefTx ¶
CreateFileRefTx inserts a new file reference within a transaction.
func (*DB) CreateFileRefsBatch ¶
CreateFileRefsBatch inserts multiple file references using COPY for speed.
func (*DB) CreateFileRefsIndexes ¶ added in v3.3.1
CreateFileRefsIndexes creates the secondary indexes on pgit_file_refs. This is much faster than maintaining indexes during bulk insert because PostgreSQL can sort and bulk-load the B-tree in a single pass.
func (*DB) DeleteBlobsForCommits ¶ added in v3.2.0
DeleteBlobsForCommits removes all file_refs and content data for the given commit IDs. For xpatch content tables, it truncates each affected file's chain at the lowest version_id being removed (xpatch cascade-deletes the rest). This must be called BEFORE DeleteCommits since we need the commit data to identify which content versions to clean up.
func (*DB) DeleteCommits ¶ added in v3.2.0
DeleteCommits deletes the given commits from the xpatch chain by PK. In xpatch, deleting a row cascade-deletes all rows with higher _xp_seq in the same group. So deleting the earliest commit in the list effectively truncates the chain from that point forward.
The caller should pass ALL commit IDs that need to be removed (local-only commits, plus any previously-pulled remote commits that are interleaved). Subsequent deletes after the first cascade are harmless no-ops.
After deletion, refreshes xpatch stats for the commits table.
func (*DB) DeleteMetadata ¶
DeleteMetadata removes a metadata key
func (*DB) DeleteSyncState ¶
DeleteSyncState deletes the sync state for a remote
func (*DB) DropFileRefsIndexes ¶ added in v3.3.1
DropFileRefsIndexes drops the secondary indexes on pgit_file_refs. The primary key (group_id, commit_id) is kept for COPY conflict detection. Call this before bulk import to avoid random B-tree insertions, then call CreateFileRefsIndexes after import to rebuild them efficiently.
func (*DB) DropSchema ¶
DropSchema drops all pgit tables (use with caution!)
func (*DB) EnsureMetadataTable ¶
EnsureMetadataTable creates the metadata table if it doesn't exist
func (*DB) FileExistsInTree ¶
FileExistsInTree checks if a file exists (is not deleted) in the tree at a commit. This finds the latest version of the file at or before commitID and checks if it's not deleted.
func (*DB) FileRefExists ¶
FileRefExists checks if a file ref exists at a specific commit.
func (*DB) FindCommitByPartialID ¶
FindCommitByPartialID finds a commit by partial ID match. Uses prefix range scan first (fast, uses xpatch PK index), then falls back to suffix match on pgit_file_refs (normal table) if no prefix match found.
func (*DB) FindCommonAncestor ¶
FindCommonAncestor finds the common ancestor between two commits
func (*DB) GetAllCommitIDsOrdered ¶ added in v3.2.0
GetAllCommitIDsOrdered returns all commit IDs in ascending ULID order. Used for rebuilding markToULID mapping during import resume.
func (*DB) GetAllCommits ¶
GetAllCommits retrieves all commits ordered by ID (ULID = time order)
func (*DB) GetAllContentForGroup ¶
func (db *DB) GetAllContentForGroup(ctx context.Context, groupID int32, isBinary bool) ([]ContentVersionPair, error)
GetAllContentForGroup retrieves all content versions for a single group, ordered by version_id ASC (front-to-back). This is the fastest access pattern for xpatch: a single Index Scan through the delta chain, decompressing sequentially. The caller can reverse the slice in Go for newest-first iteration.
func (*DB) GetAllPaths ¶
GetAllPaths returns all unique file paths in the repository. This is very fast as it queries the small pgit_paths table.
func (*DB) GetAllPathsV2 ¶
GetAllPathsV2 retrieves all unique file paths in the repository. This is very fast as it queries the small pgit_paths table. Note: This replaces the old GetAllPaths from blobs.go in schema v2.
func (*DB) GetAllRefs ¶
GetAllRefs retrieves all refs
func (*DB) GetAllSyncStates ¶
GetAllSyncStates retrieves all sync states
func (*DB) GetBlobStats ¶
GetBlobStats returns statistics about blobs using the v3 schema. Sums stats from both pgit_text_content and pgit_binary_content.
func (*DB) GetBlobsAtCommit ¶
GetBlobsAtCommit retrieves all blobs at a specific commit. This returns only files that were changed in that specific commit. Uses a two-step approach: get refs, then batch-fetch content from both tables.
func (*DB) GetBlobsAtCommitMetadata ¶
GetBlobsAtCommitMetadata retrieves all blobs at a specific commit WITHOUT content. This returns only files that were changed in that specific commit (not the full tree).
func (*DB) GetChangedFileRefs ¶
func (db *DB) GetChangedFileRefs(ctx context.Context, fromCommit, toCommit string) ([]*FileRef, error)
GetChangedFileRefs returns file refs that changed between two commits.
func (*DB) GetChangedFileRefsWithPaths ¶
func (db *DB) GetChangedFileRefsWithPaths(ctx context.Context, fromCommit, toCommit string) ([]*FileRefWithPath, error)
GetChangedFileRefsWithPaths returns file refs with paths that changed between two commits.
func (*DB) GetChangedFiles ¶
GetChangedFiles returns files that changed between two commits.
func (*DB) GetChangedFilesMetadata ¶
func (db *DB) GetChangedFilesMetadata(ctx context.Context, fromCommit, toCommit string) ([]*Blob, error)
GetChangedFilesMetadata returns files that changed between two commits WITHOUT content. Use this for operations that only need paths and hashes (e.g., diff --name-only).
func (*DB) GetCommitLog ¶
GetCommitLog retrieves commits starting from HEAD in reverse chronological order. Uses a range query on ULID-ordered IDs instead of a recursive CTE, which is much faster on xpatch tables (sequential scan vs random PK lookups).
func (*DB) GetCommitLogFrom ¶
GetCommitLogFrom retrieves commits in reverse chronological order starting from a commit. Since commit IDs are ULIDs (lexicographically = chronologically ordered), we use a simple range query instead of walking parent_id chains.
func (*DB) GetCommitStats ¶
GetCommitStats returns statistics about commits using xpatch.stats() for O(1) performance
func (*DB) GetCommitsAfter ¶ added in v3.2.0
GetCommitsAfter returns all commits with ID > afterID, in chronological order (oldest first). If afterID is empty, returns all commits (same as GetAllCommits). Uses a forward scan on the xpatch delta chain — optimal access pattern.
func (*DB) GetCommitsBatch ¶
GetCommitsBatch retrieves multiple commits by their IDs in a single query.
func (*DB) GetCommitsBatchByRange ¶
GetCommitsBatchByRange retrieves multiple commits using a range scan instead of ANY(). This is much faster on xpatch tables because it scans a contiguous range of the delta chain instead of doing random-access per ID. The ids slice is used to filter results in Go after the range scan.
func (*DB) GetContent ¶
func (db *DB) GetContent(ctx context.Context, groupID, versionID int32, isBinary bool) ([]byte, error)
GetContent retrieves content by (group_id, version_id). isBinary determines which table to query.
func (*DB) GetContentForFileRef ¶
GetContentForFileRef retrieves content for a file ref. Returns nil for deleted refs (ContentHash == nil) since they have no content row.
func (*DB) GetContentsBatch ¶
func (db *DB) GetContentsBatch(ctx context.Context, keys []ContentKey, isBinaryMap map[ContentKey]bool) (map[ContentKey][]byte, error)
GetContentsBatch retrieves multiple contents by their keys. isBinaryMap indicates which keys are binary. Keys not in the map default to text.
func (*DB) GetContentsByGroupID ¶
GetContentsByGroupID retrieves all content versions for a group. Queries both tables and merges results.
func (*DB) GetContentsForFileRefs ¶
func (db *DB) GetContentsForFileRefs(ctx context.Context, refs []*FileRef) (map[ContentKey][]byte, error)
GetContentsForFileRefs retrieves content for multiple file refs. Skips deleted refs (ContentHash == nil) since they have no content row.
func (*DB) GetCurrentTree ¶
GetCurrentTree retrieves the tree at HEAD.
func (*DB) GetCurrentTreeMetadata ¶
GetCurrentTreeMetadata retrieves the tree metadata at HEAD without content. Use this for operations that only need paths and hashes.
func (*DB) GetDetailedTableSizes ¶
func (db *DB) GetDetailedTableSizes(ctx context.Context) (*DetailedTableSizes, error)
GetDetailedTableSizes returns sizes for all pgit tables.
func (*DB) GetFileAtCommit ¶
GetFileAtCommit retrieves a file at a specific commit (or the latest version before it). Uses file ref lookup + content fetch from the correct table.
func (*DB) GetFileHistory ¶
GetFileHistory retrieves all versions of a file. Uses a two-step approach: get refs, then batch-fetch content from both tables.
func (*DB) GetFileRef ¶
GetFileRef retrieves a specific file reference.
func (*DB) GetFileRefAtCommit ¶
func (db *DB) GetFileRefAtCommit(ctx context.Context, groupID int32, commitID string) (*FileRef, error)
GetFileRefAtCommit retrieves a file ref at or before a specific commit.
func (*DB) GetFileRefHistory ¶
GetFileRefHistory retrieves all versions of a file by group_id.
func (*DB) GetFileRefsAtCommit ¶
GetFileRefsAtCommit retrieves all file refs at a specific commit. This returns only files that were changed in that specific commit.
func (*DB) GetFileRefsAtCommitWithPaths ¶
func (db *DB) GetFileRefsAtCommitWithPaths(ctx context.Context, commitID string) ([]*FileRefWithPath, error)
GetFileRefsAtCommitWithPaths retrieves file refs with resolved paths.
func (*DB) GetGroupIDByPath ¶
GetGroupIDByPath retrieves the group_id for a specific path. Returns 0 and nil error if the path doesn't exist.
func (*DB) GetHeadCommit ¶
GetHeadCommit retrieves the commit that HEAD points to
func (*DB) GetImportedPaths ¶ added in v3.2.0
GetImportedPaths returns the set of paths that have at least one file ref. Used during import resume to skip paths whose blobs are already imported.
func (*DB) GetLatestCommitID ¶
GetLatestCommitID returns the ID of the latest commit (by ULID order)
func (*DB) GetMetadata ¶
GetMetadata retrieves a metadata value by key
func (*DB) GetNextVersionID ¶
GetNextVersionID returns the next version_id for a group. This is used when creating new file refs.
func (*DB) GetNextVersionIDTx ¶
GetNextVersionIDTx returns the next version_id within a transaction.
func (*DB) GetOrCreatePath ¶
GetOrCreatePath returns the group_id for a path, creating it if needed. This is the primary method for getting a group_id during blob creation.
func (*DB) GetOrCreatePathTx ¶
GetOrCreatePathTx returns the group_id for a path within a transaction.
func (*DB) GetOrCreatePathsBatch ¶
GetOrCreatePathsBatch handles multiple paths efficiently. Returns a map of path -> group_id.
func (*DB) GetPathsByGroupIDs ¶
GetPathsByGroupIDs retrieves multiple paths by group_ids. Returns a map of group_id -> path.
func (*DB) GetRepoPath ¶
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. This version supports the v3 schema with split text/binary content tables.
func (*DB) GetSchemaVersion ¶
GetSchemaVersion returns the current schema version from the database. Returns 1 for legacy schemas that don't have a version set.
func (*DB) GetSyncState ¶
GetSyncState retrieves the sync state for a remote
func (*DB) GetTreeAtCommit ¶
GetTreeAtCommit retrieves the full tree (all files) at a commit. Uses a two-step approach: get refs with DISTINCT ON, then batch-fetch content.
func (*DB) GetTreeMetadataAtCommit ¶
GetTreeMetadataAtCommit retrieves the full tree metadata (all files) at a commit WITHOUT loading content. This is much faster than GetTreeAtCommit when you only need paths and hashes (e.g., for status, ls-tree). The returned Blobs have Content set to nil.
func (*DB) GetTreeRefsAtCommit ¶
GetTreeRefsAtCommit retrieves the full tree (latest version per path <= commitID). This is the core query for getting the state of the repository at a commit.
func (*DB) GetTreeRefsAtCommitWithPaths ¶
func (db *DB) GetTreeRefsAtCommitWithPaths(ctx context.Context, commitID string) ([]*FileRefWithPath, error)
GetTreeRefsAtCommitWithPaths retrieves the full tree with resolved paths. This is a metadata-only query - no content is fetched.
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) IsSchemaAtLeast ¶
IsSchemaAtLeast checks if the database schema is at least the given version.
func (*DB) PreRegisterPaths ¶ added in v3.3.0
PreRegisterPaths inserts all paths into pgit_paths in a single transaction and returns the complete path -> group_id mapping. This eliminates per-worker path lookup queries during import. Paths that already exist are returned as-is.
func (*DB) ResetImportGUCs ¶ added in v3.3.0
ResetImportGUCs restores default PostgreSQL session settings after import.
func (*DB) SchemaExists ¶
SchemaExists checks if the pgit schema exists
func (*DB) SearchContent ¶
func (db *DB) SearchContent(ctx context.Context, opts SearchContentOptions) ([]*SearchContentResult, error)
SearchContent searches text file contents using parallel-by-group fetching. Binary files are excluded from search results. Strategy:
- Load all matching file refs into memory
- Group by group_id, build version→ref lookup
- Worker goroutines process groups in parallel, each issuing a single server-side regex query per group for optimal xpatch delta-chain access
func (*DB) SearchContentAtCommit ¶
func (db *DB) SearchContentAtCommit(ctx context.Context, commitID string, opts SearchContentOptions) ([]*SearchContentResult, error)
SearchContentAtCommit searches text file contents at a specific commit. This searches the tree state at that commit (latest version of each file <= commitID). Binary files are excluded from search results.
func (*DB) SetImportGUCs ¶ added in v3.3.0
SetImportGUCs configures session-level PostgreSQL settings optimized for bulk import on ALL connections in the pool. These settings trade crash safety for speed — safe because import can resume from the temp file if PostgreSQL crashes.
func (*DB) SetMetadata ¶
SetMetadata sets a metadata key-value pair (upsert)
func (*DB) SetRepoPath ¶
SetRepoPath stores the repository working directory path
func (*DB) SetSchemaVersion ¶
SetSchemaVersion sets the schema version in the database.
func (*DB) SetSyncState ¶
SetSyncState creates or updates the sync state for a remote
type DetailedTableSizes ¶
type DetailedTableSizes struct {
Commits int64
Paths int64
FileRefs int64
TextContent int64
BinaryContent int64
Refs int64
SyncState int64
Metadata int64
Indexes int64
}
GetDetailedTableSizes returns detailed size information for each table.
type FileRef ¶
type FileRef struct {
GroupID int32
CommitID string
VersionID int32
ContentHash []byte // 16 bytes BLAKE3, nil = deleted
Mode int
IsSymlink bool
SymlinkTarget *string
IsBinary bool
}
FileRef represents a file reference at a specific commit. This is the metadata-only representation without actual content.
type FileRefWithPath ¶
type FileRefWithPath struct {
Path string
GroupID int32
CommitID string
VersionID int32
ContentHash []byte
Mode int
IsSymlink bool
SymlinkTarget *string
IsBinary bool
}
FileRefWithPath combines FileRef with resolved path. Used when returning results that need the actual file path.
type Path ¶
Path represents a file path in the path registry. Each unique path gets a unique group_id for efficient storage.
type RepoStats ¶
type RepoStats struct {
// Commit stats
TotalCommits int64
FirstCommitID *string
LastCommitID *string
// File stats
TotalBlobs int64 // Total file refs (from pgit_file_refs)
UniqueFiles int64 // Unique paths (from pgit_paths)
TotalContentSize int64 // Raw content size (sum from both content tables via xpatch.stats)
DeletedEntries int64
// Table sizes from PostgreSQL (pg_table_size = heap + TOAST + FSM)
CommitsTableSize int64
PathsTableSize int64
FileRefsTableSize int64
TextContentTableSize int64
BinaryContentTableSize int64
RefsTableSize int64
MetadataTableSize int64
SyncStateTableSize int64
TotalIndexSize int64
// xpatch compressed bytes (compressed_size_bytes from xpatch.stats)
// This is the actual data after delta compression, excluding PG overhead.
XpatchCompressedCommits int64
XpatchCompressedText int64
XpatchCompressedBinary int64
// Normal table raw data bytes (computed from column widths, no PG overhead)
NormalRawFileRefs int64
NormalRawPaths int64
NormalRawRefs int64
NormalRawMetadata int64
// Legacy field for compatibility (sum of paths + file_refs + both content tables)
BlobsTableSize int64
}
RepoStats contains all repository statistics for schema v3.
type SearchContentOptions ¶
type SearchContentOptions struct {
// Pattern is the regex pattern to search for (PostgreSQL regex syntax).
Pattern string
// IgnoreCase enables case-insensitive matching.
IgnoreCase bool
// PathPattern is an optional glob pattern to filter files by path.
PathPattern string
// CommitID limits search to files at or before this commit.
// Empty string means search all versions.
CommitID string
// Limit is the maximum number of matching files to return.
// 0 means no limit.
Limit int
}
SearchContentOptions configures content search behavior.
type SearchContentResult ¶
type SearchContentResult struct {
Path string
GroupID int32
CommitID string
VersionID int32
Content []byte
}
SearchContentResult represents a file that matched the search.
type XpatchStats ¶
type XpatchStats struct {
TotalRows int64
TotalGroups int64
KeyframeCount int64
DeltaCount int64
RawSizeBytes int64
CompressedBytes int64
CompressionRatio float64
CacheHits int64
CacheMisses int64
AvgDepth float64 // avg_compression_depth: average delta distance (versions back) per reconstruction
}
XpatchStats represents compression statistics from pg-xpatch