git

package
v0.0.0-...-1f307c6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 14, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package git provides Git repository operations for MonoFS. This file implements a resilient blob cache with LRU eviction and auto-restore.

Package git handles Git repository operations for MonoFS.

Index

Constants

This section is empty.

Variables

View Source
var ErrRepoNotCloned = fmt.Errorf("repository not cloned locally")

OpenOnly opens an existing repository without cloning. Returns nil, ErrRepoNotCloned if the repository is not locally available. This is used for fast-path lookups where we don't want to block on network operations.

Functions

This section is empty.

Types

type BlobCache

type BlobCache struct {
	// contains filtered or unexported fields
}

BlobCache provides resilient blob reading with LRU-based cleanup. It tracks file access times and removes unused blobs to save space. When a cleaned blob is requested, it automatically restores from Git.

func NewBlobCache

func NewBlobCache(repoMgr *RepoManager, cfg BlobCacheConfig) (*BlobCache, error)

NewBlobCache creates a new BlobCache with the given configuration.

func (*BlobCache) CleanupByCount

func (bc *BlobCache) CleanupByCount(count int) int

CleanupByCount removes the oldest N blobs to free space. This is useful when disk space is low and you need to free space immediately.

func (*BlobCache) Close

func (bc *BlobCache) Close() error

Close stops the cleanup goroutine and releases resources.

func (*BlobCache) ForceCleanup

func (bc *BlobCache) ForceCleanup() int

ForceCleanup immediately removes all expired blobs.

func (*BlobCache) GetStats

func (bc *BlobCache) GetStats() CleanupStats

GetStats returns current cache statistics.

func (*BlobCache) ReadBlob

func (bc *BlobCache) ReadBlob(ctx context.Context, repo *git.Repository, blobHash string) ([]byte, error)

ReadBlob reads a blob with automatic retry and restoration. It first tries to read from the cache, then falls back to Git. If the blob was cleaned up, it automatically restores it.

func (*BlobCache) ReadBlobWithRestore

func (bc *BlobCache) ReadBlobWithRestore(ctx context.Context, blobHash, repoURL, displayPath, branch string) ([]byte, error)

ReadBlobWithRestore reads a blob and automatically restores it if needed. This is the primary method for resilient reads that handles missing repos.

func (*BlobCache) RegisterBlob

func (bc *BlobCache) RegisterBlob(blobHash, repoURL, displayPath, branch string)

RegisterBlob registers a blob with metadata for future restoration. This should be called when blob metadata becomes available (e.g., during ingestion).

type BlobCacheConfig

type BlobCacheConfig struct {
	// CacheDir is the directory for cached blobs (default: os.TempDir()/monofs-blobs)
	CacheDir string

	// MaxAge is the maximum age for unused blobs (default: 1 hour)
	MaxAge time.Duration

	// MaxRetries is the number of read/restore attempts (default: 3)
	MaxRetries int

	// RetryDelay is the base delay between retries (default: 100ms)
	RetryDelay time.Duration

	// CleanupInterval is how often cleanup runs (default: 5 minutes)
	CleanupInterval time.Duration
}

BlobCacheConfig holds configuration for BlobCache.

func DefaultBlobCacheConfig

func DefaultBlobCacheConfig() BlobCacheConfig

DefaultBlobCacheConfig returns the default configuration.

type CleanupStats

type CleanupStats struct {
	TotalTracked    int
	CachedOnDisk    int
	ExpiredCount    int
	OldestAccess    time.Time
	NewestAccess    time.Time
	TotalCacheBytes int64
}

CleanupStats returns statistics about the cleanup state.

type FileMetadata

type FileMetadata struct {
	Path     string
	Size     uint64
	Mode     uint32
	BlobHash string
	Mtime    int64
}

FileMetadata represents file metadata from Git.

type RepoManager

type RepoManager struct {
	// contains filtered or unexported fields
}

RepoManager handles Git repository operations.

func NewRepoManager

func NewRepoManager(cacheDir string) (*RepoManager, error)

NewRepoManager creates a new repository manager.

func (*RepoManager) CleanupRepo

func (rm *RepoManager) CleanupRepo(repoID string) error

CleanupRepo removes a cloned repository from cache to free disk space.

func (*RepoManager) CloneOrOpen

func (rm *RepoManager) CloneOrOpen(ctx context.Context, repoURL, repoID, branch string) (*git.Repository, error)

CloneOrOpen clones a repository or opens existing one.

func (*RepoManager) GetDefaultBranch

func (rm *RepoManager) GetDefaultBranch(ctx context.Context, repoURL string) (string, error)

GetDefaultBranch detects the default branch of a remote repository.

func (*RepoManager) GetFileMetadata

func (rm *RepoManager) GetFileMetadata(repo *git.Repository, branch, filePath string) (FileMetadata, error)

GetFileMetadata retrieves metadata for a specific file in the repository.

func (*RepoManager) OpenOnly

func (rm *RepoManager) OpenOnly(repoID string) (*git.Repository, error)

func (*RepoManager) OpenOrClone

func (rm *RepoManager) OpenOrClone(repoURL, branch string) (*git.Repository, error)

OpenOrClone tries to open an existing repo or clones it if not present.

func (*RepoManager) ReadBlob

func (rm *RepoManager) ReadBlob(repo *git.Repository, blobHash string) ([]byte, error)

ReadBlob reads a blob from the repository by hash.

func (*RepoManager) WalkTree

func (rm *RepoManager) WalkTree(repo *git.Repository, branch string, fn func(FileMetadata) error) error

WalkTree walks the Git tree and yields file metadata. Walks git tree objects directly without requiring a working directory.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL