Documentation
¶
Overview ¶
Commit a set of changes, reading the file data they need from a local directory.
Import a directory into a repository without attaching it as a workspace.
Merge changes from the repository into the workspace and vice versa.
Index ¶
- Variables
- func AddFileToRepository(ctx context.Context, srcFS lib.FS, path lib.Path, fileInfo fs.FileInfo, ...) (lib.PathMetadata, error)
- func AddSyncTarget(ctx context.Context, w *Workspace, name, uri string, passphrase []byte) error
- func Cat(ctx context.Context, repository *lib.Repository, w io.Writer, opts *CatOptions, ...) error
- func CommitFiles(ctx context.Context, src *CommitFilesSrc, dest *CommitFilesDest, ...) (lib.RevisionId, error)
- func Cp(ctx context.Context, repository *lib.Repository, targetFS lib.FS, ...) error
- func DeleteSyncTarget(ctx context.Context, w *Workspace, name string) error
- func ForceCommit(ctx context.Context, ws *Workspace, repository *lib.Repository, ...) (lib.RevisionId, error)
- func FormatBytes(b int64) string
- func GetSyncTarget(ctx context.Context, w *Workspace, name string) (uri string, found bool, err error)
- func Merge(ctx context.Context, ws *Workspace, repository *lib.Repository, ...) (lib.RevisionId, error)
- func NewStagingCacheWriter(fs lib.FS, maxChunkSize int) *lib.TempWriter[*StagingEntry]
- func OpenStagingCache(fs lib.FS, maxChunksInCache int) (*lib.TempCache[*StagingEntry], error)
- func OpenStorage(uri string, passphrase []byte) (lib.Storage, error)
- func Reset(ctx context.Context, ws *Workspace, repository *lib.Repository, ...) error
- func RunSync(ctx context.Context, w *Workspace, name string, passphrase []byte, ...) error
- func StagingCacheKey(stagingEntry *StagingEntry) string
- func StagingEntryPathCompare(a, b *StagingEntry) int
- func ValidatePathPrefix(pathPrefix string) (lib.Path, error)
- func ValidateSyncTargetName(name string) error
- type CatOptions
- type CommitFilesDest
- type CommitFilesOptions
- type CommitFilesSrc
- type CommitMonitor
- type CpMonitor
- type CpOnError
- type CpOnExists
- type CpOptions
- type DefaultCommitMonitor
- func (m *DefaultCommitMonitor) OnAddBlock(entry *lib.RevisionEntry, blockId lib.BlockId, dataSize int, ...) error
- func (m *DefaultCommitMonitor) OnBeforeCommit() error
- func (m *DefaultCommitMonitor) OnEnd(entry *lib.RevisionEntry) error
- func (m *DefaultCommitMonitor) OnStart(entry *lib.RevisionEntry) error
- func (m *DefaultCommitMonitor) Preparing()
- type DefaultCpMonitor
- func (m *DefaultCpMonitor) OnEnd(entry *lib.RevisionEntry, targetPath string) error
- func (m *DefaultCpMonitor) OnError(entry *lib.RevisionEntry, targetPath string, err error) CpOnError
- func (m *DefaultCpMonitor) OnExists(entry *lib.RevisionEntry, targetPath string) CpOnExists
- func (m *DefaultCpMonitor) OnStart(entry *lib.RevisionEntry, targetPath string) error
- func (m *DefaultCpMonitor) OnWrite(entry *lib.RevisionEntry, targetPath string, blockID lib.BlockId, data []byte) error
- func (m *DefaultCpMonitor) Preparing()
- type DefaultHealthCheckMonitor
- func (m *DefaultHealthCheckMonitor) Duration() time.Duration
- func (m *DefaultHealthCheckMonitor) Finish()
- func (m *DefaultHealthCheckMonitor) OnBlockVerified(blockID lib.BlockId, length int)
- func (m *DefaultHealthCheckMonitor) OnOrphanedBlock(blockID lib.BlockId)
- func (m *DefaultHealthCheckMonitor) OnRevisionEntry(entry *lib.RevisionEntry)
- func (m *DefaultHealthCheckMonitor) OnRevisionStart(revisionID lib.RevisionId)
- func (m *DefaultHealthCheckMonitor) Preparing()
- func (m *DefaultHealthCheckMonitor) Report(checkedBlocks bool, checkedOrphanedBlocks bool, orphanedBlocksFile string) (string, error)
- type DefaultMonitorMode
- type DefaultRevisionSnapshotMonitor
- type DefaultStagingMonitor
- type DefaultSyncRepoMonitor
- func (m *DefaultSyncRepoMonitor) OnBeforeCopy(srcBlocks, dstBlocks int)
- func (m *DefaultSyncRepoMonitor) OnBeforeUpdateDstHead(newHead lib.RevisionId)
- func (m *DefaultSyncRepoMonitor) OnCopyBlock(blockID lib.BlockId, existed bool, length int)
- func (m *DefaultSyncRepoMonitor) OnDstBlockIdsRead(blocksTotal int)
- func (m *DefaultSyncRepoMonitor) OnSrcBlockIdsRead(blocksTotal int)
- func (m *DefaultSyncRepoMonitor) Preparing()
- type ForceCommitOptions
- type Import
- type ImportOptions
- type LogOptions
- type LsFile
- type LsFormat
- type LsOptions
- type MergeConflict
- type MergeConflictsError
- type MergeOptions
- type Merger
- type MonitorEmit
- type RemoteRepository
- type ResetError
- type ResetOptions
- type RevisionLog
- type RunSyncOpts
- type Staging
- type StagingCache
- type StagingEntry
- type StagingEntryChunk
- type StagingEntryMonitor
- type StatusFile
- type StatusFiles
- type StatusOptions
- type SyncTarget
- type TestCommitMonitor
- type TestCpMonitor
- func (m *TestCpMonitor) OnEnd(entry *lib.RevisionEntry, targetPath string) error
- func (m *TestCpMonitor) OnError(entry *lib.RevisionEntry, targetPath string, err error) CpOnError
- func (m *TestCpMonitor) OnExists(entry *lib.RevisionEntry, targetPath string) CpOnExists
- func (m *TestCpMonitor) OnStart(entry *lib.RevisionEntry, targetPath string) error
- func (m *TestCpMonitor) OnWrite(entry *lib.RevisionEntry, targetPath string, blockId lib.BlockId, data []byte) error
- type TestStagingEntryInfo
- type TestStagingMonitor
- type TestWorkspace
- type Workspace
- func (w *Workspace) Close() error
- func (w *Workspace) DeleteSavedPassphrase(ctx context.Context) error
- func (w *Workspace) HasSavedPassphrase(ctx context.Context) bool
- func (w *Workspace) Head(ctx context.Context) (lib.RevisionId, error)
- func (w *Workspace) ReadSavedPassphrase(ctx context.Context, cipher cryptoCipher.AEAD) ([]byte, error)
- func (w *Workspace) WriteSavedPassphrase(ctx context.Context, passphrase []byte, cipher cryptoCipher.AEAD) error
- type WorkspaceTestData
- func (wstd WorkspaceTestData) CommitFilesOptions() *CommitFilesOptions
- func (wstd WorkspaceTestData) CommitMonitor() *TestCommitMonitor
- func (wstd WorkspaceTestData) CpMonitor() *TestCpMonitor
- func (wstd WorkspaceTestData) CpMonitorOverwrite() *TestCpMonitor
- func (wstd WorkspaceTestData) CpOptions(revisionId lib.RevisionId) *CpOptions
- func (wstd WorkspaceTestData) ImportOptions(dest lib.Path) *ImportOptions
- func (wstd WorkspaceTestData) LsOptions(revisionId lib.RevisionId) *LsOptions
- func (wstd WorkspaceTestData) MergeOptions() *MergeOptions
- func (wstd WorkspaceTestData) NewTestWorkspace(tb testing.TB, repository *lib.Repository) *TestWorkspace
- func (wstd WorkspaceTestData) NewTestWorkspaceExtra(tb testing.TB, repository *lib.Repository, pathPrefix string, fs lib.FS) *TestWorkspace
- func (wstd WorkspaceTestData) NewTestWorkspaceWithPathPrefix(tb testing.TB, repository *lib.Repository, pathPrefix string) *TestWorkspace
- func (wstd WorkspaceTestData) ResetOptions(revisionId lib.RevisionId, force bool) *ResetOptions
- func (wstd WorkspaceTestData) SnapshotMonitor() *lib.TestRevisionSnapshotMonitor
- func (wstd WorkspaceTestData) StagingEntryInfos(temp *lib.Temp[*StagingEntry]) []TestStagingEntryInfo
- func (wstd WorkspaceTestData) StagingMonitor() *TestStagingMonitor
- func (wstd WorkspaceTestData) StatusOptions() *StatusOptions
Constants ¶
This section is empty.
Variables ¶
var ( ErrSourceVanished = lib.Errorf("file vanished while committing") ErrSourceModified = lib.Errorf("file was modified while committing") )
var ( ErrUpToDate = lib.Errorf("workspace is up to date") ErrRemoteChanged = lib.Errorf("remote repository has changed during merge") )
var ErrSavedPassphraseNotFound = lib.Errorf("saved passphrase not found")
var ErrSymLinkTargetEscapes = lib.Errorf("symlink target escapes path root")
Functions ¶
func AddFileToRepository ¶
func AddFileToRepository( ctx context.Context, srcFS lib.FS, path lib.Path, fileInfo fs.FileInfo, repository *lib.Repository, entry *lib.RevisionEntry, mon CommitMonitor, ) (lib.PathMetadata, error)
Add the file contents to the repository and return the file metadata.
func AddSyncTarget ¶
AddSyncTarget registers a new target. Returns an error if `name` is invalid, already present, or if the target's repository config does not match the workspace's source repository (the sync precondition). `passphrase` is forwarded to `OpenStorage` so it can decrypt S3 URIs (both `w`'s source URI and the target `uri`). Non-S3 URIs ignore it.
func Cat ¶
func Cat(ctx context.Context, repository *lib.Repository, w io.Writer, opts *CatOptions, tmpFS lib.FS) error
Cat writes the contents of a single regular file from the repository to w.
func CommitFiles ¶
func CommitFiles( ctx context.Context, src *CommitFilesSrc, dest *CommitFilesDest, opts *CommitFilesOptions, tmpFS lib.FS, ) (lib.RevisionId, error)
Commit `src.Files` as a new revision, uploading the file data they need. Return `lib.ErrEmptyCommit` if nothing was left to commit, `lib.ErrHeadChanged` if the repository moved on, and `ErrSourceVanished` or `ErrSourceModified` if the source changed underneath.
func DeleteSyncTarget ¶
DeleteSyncTarget removes the named target. Returns an error if it isn't registered.
func ForceCommit ¶
func ForceCommit( ctx context.Context, ws *Workspace, repository *lib.Repository, opts *ForceCommitOptions, ) (lib.RevisionId, error)
Commit all local changes ignoring possible conflicts. Afterwards, merge the repository into the workspace. Return a `lib.EmptyCommit` error if there are no local changes.
func FormatBytes ¶
func GetSyncTarget ¶
func GetSyncTarget(ctx context.Context, w *Workspace, name string) (uri string, found bool, err error)
GetSyncTarget looks up a registered target by name. `found` is false if no target with that name is registered.
func Merge ¶
func Merge(ctx context.Context, ws *Workspace, repository *lib.Repository, opts *MergeOptions) (lib.RevisionId, error)
Merge the changes from the repository into the workspace and vice versa. Return a `MergeConflictsError` error if there are conflicts. todo: return new revision id and the local changes.
func NewStagingCacheWriter ¶
func NewStagingCacheWriter(fs lib.FS, maxChunkSize int) *lib.TempWriter[*StagingEntry]
func OpenStagingCache ¶
func OpenStorage ¶
OpenStorage opens a repository storage by URI. `s3+<http-url>` URIs need the repository passphrase to decrypt the embedded credentials. Local paths ignore the passphrase.
func Reset ¶
func Reset(ctx context.Context, ws *Workspace, repository *lib.Repository, opts *ResetOptions) error
Reset the workspace to a specific revision. Return `ResetError` if there are local changes and `opts.Force` is not set.
func RunSync ¶
func RunSync( ctx context.Context, w *Workspace, name string, passphrase []byte, srcRevisionChain lib.RevisionChain, opts RunSyncOpts, ) error
RunSync syncs the workspace's repository to the registered target named `name`. The caller drives multi-target iteration and aggregation.
func StagingCacheKey ¶
func StagingCacheKey(stagingEntry *StagingEntry) string
func StagingEntryPathCompare ¶
func StagingEntryPathCompare(a, b *StagingEntry) int
func ValidateSyncTargetName ¶
ValidateSyncTargetName rejects names that aren't ASCII alphanumeric or '-'.
Types ¶
type CatOptions ¶
type CatOptions struct {
RevisionId lib.RevisionId
SnapshotMonitor lib.RevisionSnapshotMonitor
// Path is relative to PathPrefix.
Path lib.Path
PathPrefix lib.Path
}
type CommitFilesDest ¶
type CommitFilesDest struct {
Repository *lib.Repository
// The revision `Files` were computed against, and the parent of the new one.
// Blocks `Snapshot` already holds are reused instead of read and uploaded again.
RevisionId lib.RevisionId
Snapshot *lib.TempCache[*lib.RevisionEntry]
}
The repository the files are committed to, and the revision they are committed onto.
type CommitFilesOptions ¶
type CommitFilesOptions struct {
Author string
Message string
Monitor CommitMonitor
// Which metadata differences count as a change. An entry that differs in no
// other way is left out of the revision.
RestorableMetadataFlag lib.RestorableMetadataFlag
}
type CommitFilesSrc ¶
type CommitFilesSrc struct {
// `Files` are read from `Src`. `SrcPrefix` is the repository path the root of
// `Src` maps to, so `<SrcPrefix>/a/b.txt` is read from `a/b.txt`.
Src lib.FS
SrcPrefix lib.Path
Files *lib.Temp[*lib.RevisionEntry]
}
The files to commit and where their data is read from.
type CommitMonitor ¶
type CommitMonitor interface {
OnStart(entry *lib.RevisionEntry) error
// bytesWritten: if nil, the block already existed; otherwise, the total block size (including
// header) written.
OnAddBlock(entry *lib.RevisionEntry, blockId lib.BlockId, dataSize int, bytesWritten *int) error
OnEnd(entry *lib.RevisionEntry) error
OnBeforeCommit() error
}
type CpMonitor ¶
type CpMonitor interface {
OnStart(entry *lib.RevisionEntry, targetPath string) error
OnExists(entry *lib.RevisionEntry, targetPath string) CpOnExists
OnWrite(entry *lib.RevisionEntry, targetPath string, blockId lib.BlockId, data []byte) error
OnEnd(entry *lib.RevisionEntry, targetPath string) error
OnError(entry *lib.RevisionEntry, targetPath string, err error) CpOnError
}
type CpOnExists ¶
type CpOnExists int
const ( CpOnExistsAbort CpOnExists = 1 CpOnExistsIgnore CpOnExists = 2 CpOnExistsOverwrite CpOnExists = 3 )
type CpOptions ¶
type CpOptions struct {
RevisionId lib.RevisionId
Monitor CpMonitor
SnapshotMonitor lib.RevisionSnapshotMonitor
Include *lib.PathInclusionFilter
Exclude *lib.PathExclusionFilter
PathPrefix lib.Path
RestorableMetadataFlag lib.RestorableMetadataFlag
}
type DefaultCommitMonitor ¶
type DefaultCommitMonitor struct {
StartTime time.Time
Paths int
RawBytesAdded int64
CompressedBytesAdded int64
RawBytesReused int64
// contains filtered or unexported fields
}
func NewDefaultCommitMonitor ¶
func NewDefaultCommitMonitor( mode DefaultMonitorMode, cancel func() error, emit MonitorEmit, ) *DefaultCommitMonitor
func (*DefaultCommitMonitor) OnAddBlock ¶
func (m *DefaultCommitMonitor) OnAddBlock( entry *lib.RevisionEntry, blockId lib.BlockId, dataSize int, dataBytesWritten *int, ) error
func (*DefaultCommitMonitor) OnBeforeCommit ¶
func (m *DefaultCommitMonitor) OnBeforeCommit() error
func (*DefaultCommitMonitor) OnEnd ¶
func (m *DefaultCommitMonitor) OnEnd(entry *lib.RevisionEntry) error
func (*DefaultCommitMonitor) OnStart ¶
func (m *DefaultCommitMonitor) OnStart(entry *lib.RevisionEntry) error
type DefaultCpMonitor ¶
type DefaultCpMonitor struct {
StartTime time.Time
Paths int
Excluded int
BytesWritten int64
Errors int
// contains filtered or unexported fields
}
func NewDefaultCpMonitor ¶
func NewDefaultCpMonitor( mode DefaultMonitorMode, cancel func() error, emit MonitorEmit, cpOnExists CpOnExists, ignoreErrors bool, ) *DefaultCpMonitor
func (*DefaultCpMonitor) OnEnd ¶
func (m *DefaultCpMonitor) OnEnd(entry *lib.RevisionEntry, targetPath string) error
func (*DefaultCpMonitor) OnError ¶
func (m *DefaultCpMonitor) OnError(entry *lib.RevisionEntry, targetPath string, err error) CpOnError
func (*DefaultCpMonitor) OnExists ¶
func (m *DefaultCpMonitor) OnExists(entry *lib.RevisionEntry, targetPath string) CpOnExists
func (*DefaultCpMonitor) OnStart ¶
func (m *DefaultCpMonitor) OnStart(entry *lib.RevisionEntry, targetPath string) error
func (*DefaultCpMonitor) OnWrite ¶
func (m *DefaultCpMonitor) OnWrite( entry *lib.RevisionEntry, targetPath string, blockID lib.BlockId, data []byte, ) error
type DefaultHealthCheckMonitor ¶
type DefaultHealthCheckMonitor struct {
StartTime time.Time
EndTime time.Time
Revisions int
Paths int
Blocks int
BlockBytes int64
OrphanedBlocks []lib.BlockId
// contains filtered or unexported fields
}
func NewDefaultHealthCheckMonitor ¶
func NewDefaultHealthCheckMonitor(mode DefaultMonitorMode, emit MonitorEmit) *DefaultHealthCheckMonitor
func (*DefaultHealthCheckMonitor) Duration ¶
func (m *DefaultHealthCheckMonitor) Duration() time.Duration
func (*DefaultHealthCheckMonitor) Finish ¶
func (m *DefaultHealthCheckMonitor) Finish()
func (*DefaultHealthCheckMonitor) OnBlockVerified ¶
func (m *DefaultHealthCheckMonitor) OnBlockVerified(blockID lib.BlockId, length int)
func (*DefaultHealthCheckMonitor) OnOrphanedBlock ¶
func (m *DefaultHealthCheckMonitor) OnOrphanedBlock(blockID lib.BlockId)
func (*DefaultHealthCheckMonitor) OnRevisionEntry ¶
func (m *DefaultHealthCheckMonitor) OnRevisionEntry(entry *lib.RevisionEntry)
func (*DefaultHealthCheckMonitor) OnRevisionStart ¶
func (m *DefaultHealthCheckMonitor) OnRevisionStart(revisionID lib.RevisionId)
type DefaultMonitorMode ¶
type DefaultMonitorMode int
const ( DefaultMonitorModeSilent DefaultMonitorMode = iota DefaultMonitorModeProgress DefaultMonitorModeVerbose )
type DefaultRevisionSnapshotMonitor ¶
type DefaultRevisionSnapshotMonitor struct {
Revisions int
Entries int
// contains filtered or unexported fields
}
func NewDefaultRevisionSnapshotMonitor ¶
func NewDefaultRevisionSnapshotMonitor(mode DefaultMonitorMode, emit MonitorEmit) *DefaultRevisionSnapshotMonitor
func (*DefaultRevisionSnapshotMonitor) OnRevisionEntry ¶
func (m *DefaultRevisionSnapshotMonitor) OnRevisionEntry(entry *lib.RevisionEntry)
func (*DefaultRevisionSnapshotMonitor) OnRevisionStart ¶
func (m *DefaultRevisionSnapshotMonitor) OnRevisionStart(revisionId lib.RevisionId)
type DefaultStagingMonitor ¶
type DefaultStagingMonitor struct {
StartTime time.Time
Paths int
Excluded int
TotalFileSizes int64
// contains filtered or unexported fields
}
func NewDefaultStagingMonitor ¶
func NewDefaultStagingMonitor( mode DefaultMonitorMode, cancel func() error, emit MonitorEmit, ) *DefaultStagingMonitor
func (*DefaultStagingMonitor) OnEnd ¶
func (m *DefaultStagingMonitor) OnEnd(path lib.Path, excluded bool, metadata *lib.PathMetadata) error
type DefaultSyncRepoMonitor ¶
type DefaultSyncRepoMonitor struct {
TargetName string
StartTime time.Time
SrcBlocks int
DstBlocks int
Blocks int
Bytes int64
// contains filtered or unexported fields
}
func NewDefaultSyncRepoMonitor ¶
func NewDefaultSyncRepoMonitor(mode DefaultMonitorMode, emit MonitorEmit, targetName string) *DefaultSyncRepoMonitor
func (*DefaultSyncRepoMonitor) OnBeforeCopy ¶
func (m *DefaultSyncRepoMonitor) OnBeforeCopy(srcBlocks, dstBlocks int)
func (*DefaultSyncRepoMonitor) OnBeforeUpdateDstHead ¶
func (m *DefaultSyncRepoMonitor) OnBeforeUpdateDstHead(newHead lib.RevisionId)
func (*DefaultSyncRepoMonitor) OnCopyBlock ¶
func (m *DefaultSyncRepoMonitor) OnCopyBlock(blockID lib.BlockId, existed bool, length int)
func (*DefaultSyncRepoMonitor) OnDstBlockIdsRead ¶
func (m *DefaultSyncRepoMonitor) OnDstBlockIdsRead(blocksTotal int)
func (*DefaultSyncRepoMonitor) OnSrcBlockIdsRead ¶
func (m *DefaultSyncRepoMonitor) OnSrcBlockIdsRead(blocksTotal int)
func (*DefaultSyncRepoMonitor) Preparing ¶
func (m *DefaultSyncRepoMonitor) Preparing()
type ForceCommitOptions ¶
type ForceCommitOptions struct {
MergeOptions
}
type Import ¶
type Import struct {
Changes StatusFiles
// contains filtered or unexported fields
}
func NewImport ¶
func NewImport( ctx context.Context, repository *lib.Repository, src lib.FS, opts *ImportOptions, tmpFS lib.FS, ) (*Import, error)
Scan `src` and compute the changes `Commit` would write to the repository. Nothing is written until `Commit` is called.
func (*Import) Commit ¶
func (i *Import) Commit(ctx context.Context, info *lib.CommitInfo) (lib.RevisionId, error)
Commit the changes as a new revision. Return `lib.ErrEmptyCommit` if there is nothing to commit and `lib.ErrHeadChanged` if the repository moved on since the scan.
type ImportOptions ¶
type ImportOptions struct {
// The subtree `Dest` is relative to, and the space `Changes` is reported in.
PathPrefix lib.Path
// The directory below `PathPrefix` that receives the contents of the source.
Dest lib.Path
Include *lib.PathInclusionFilter
Exclude *lib.PathExclusionFilter
StagingMonitor StagingEntryMonitor
CommitMonitor CommitMonitor
SnapshotMonitor lib.RevisionSnapshotMonitor
RestorableMetadataFlag lib.RestorableMetadataFlag
}
type LogOptions ¶
type LogOptions struct {
// Include and Exclude match paths relative to PathPrefix. Either one drops
// a revision that has no path left after filtering.
Include *lib.PathInclusionFilter
Exclude *lib.PathExclusionFilter
Status bool
// Range is not validated against the repository:
// a Range.Until not in the repository fails when its revision is read,
// and a Range.Since not in the repository is never reached, so the log
// runs to the root.
Range lib.RevisionRange
// PathPrefix scopes the reported paths to a subtree. It deliberately does
// not hide revisions that touched nothing inside it, because history is
// global: revision ids, `~<n>`, and ranges all address the whole chain.
PathPrefix lib.Path
}
type LsOptions ¶
type LsOptions struct {
RevisionId lib.RevisionId
SnapshotMonitor lib.RevisionSnapshotMonitor
Include *lib.PathInclusionFilter
Exclude *lib.PathExclusionFilter
PathPrefix lib.Path
// Maximum number of path segments to list, counted from `PathPrefix`.
// 0 means unlimited.
Depth int
}
type MergeConflict ¶
type MergeConflict struct {
WorkspaceEntry *lib.RevisionEntry
RepositoryEntry *lib.RevisionEntry
}
type MergeConflictsError ¶
type MergeConflictsError []MergeConflict
func (MergeConflictsError) Error ¶
func (mc MergeConflictsError) Error() string
type MergeOptions ¶
type MergeOptions struct {
StagingMonitor StagingEntryMonitor
CpMonitor CpMonitor
CommitMonitor CommitMonitor
SnapshotMonitor lib.RevisionSnapshotMonitor
Author string
Message string
RestorableMetadataFlag lib.RestorableMetadataFlag
UseStagingCache bool
}
type MonitorEmit ¶
type MonitorEmit func(text string)
type RemoteRepository ¶
type RemoteRepository string
type ResetError ¶
type ResetError struct {
LocalChanges *lib.TempCache[*lib.RevisionEntry]
}
func (ResetError) Error ¶
func (e ResetError) Error() string
type ResetOptions ¶
type ResetOptions struct {
RevisionId lib.RevisionId
Force bool
StagingMonitor StagingEntryMonitor
CpMonitor CpMonitor
SnapshotMonitor lib.RevisionSnapshotMonitor
RestorableMetadataFlag lib.RestorableMetadataFlag
UseStagingCache bool
}
type RevisionLog ¶
type RevisionLog struct {
RevisionId lib.RevisionId
Revision lib.Revision
Files []StatusFile
// TotalFiles is how many paths the revision holds, including the ones
// skipped by PathPrefix, Include, and Exclude.
TotalFiles int
}
func Log ¶
func Log(ctx context.Context, repository *lib.Repository, opts *LogOptions) ([]RevisionLog, error)
func (*RevisionLog) Long ¶
func (l *RevisionLog) Long() string
Return the log in long format (a bit like `git log`).
Revision: 54601297f7a5003df8a4be36f4298c03dd2f90d1 Author: pero Date: Tue, 13 May 2025 12:16:16 CEST
Commit message
func (*RevisionLog) Short ¶
func (l *RevisionLog) Short() string
Return the log in short format.
<RevisionId> <Date> <Message>
type RunSyncOpts ¶
type RunSyncOpts struct {
Monitor lib.RepositorySyncMonitor
Workers int
SkipHeadCheck bool
}
RunSyncOpts holds the tunable options for `RunSync`.
type Staging ¶
type Staging struct {
Include *lib.PathInclusionFilter
Exclude *lib.PathExclusionFilter
// contains filtered or unexported fields
}
func NewStaging ¶
func NewStaging( src lib.FS, pathPrefix lib.Path, include *lib.PathInclusionFilter, exclude *lib.PathExclusionFilter, cache *StagingCache, tmp lib.FS, mon StagingEntryMonitor, ) (*Staging, error)
Build a `Staging` from the `src` directory. `.cling` is always ignored, and stale `.cling_sync_tmp_*` files left by an interrupted restore are deleted. A nil `cache` scans without reading or writing a staging cache, so nothing else in `src` is written. If `pathPrefix` is not empty, it will be prepended to all paths *after* the filters are applied.
func (*Staging) MergeWithSnapshot ¶
func (s *Staging) MergeWithSnapshot( snapshot *lib.Temp[*lib.RevisionEntry], restorableMetadataFlag lib.RestorableMetadataFlag, suppressDeletes bool, ) (*lib.Temp[*lib.RevisionEntry], error)
Merge the staging snapshot with the revision snapshot. The resulting `RevisionTemp` will contain all entries that transition from the revision snapshot to the staging snapshot. If `suppressDeletes` is `true`, paths that are in the revision snapshot but not in staging do not produce `Delete` entries. Used when the diff baseline is the repository head rather than the workspace head (attach-non-empty).
type StagingCache ¶
type StagingCache struct {
// contains filtered or unexported fields
}
func NewStagingCache ¶
func NewStagingCache(src lib.FS, useCache bool) (*StagingCache, error)
func (*StagingCache) Cleanup ¶
func (c *StagingCache) Cleanup() error
Remove the current and all temp cache directories if they are alder than one day.
func (*StagingCache) Finalize ¶
func (c *StagingCache) Finalize() error
type StagingEntry ¶
type StagingEntry struct {
RepoPath lib.Path
Metadata lib.PathMetadata
Ctime lib.Timestamp
Size int64
Inode uint64
}
func NewStagingEntry ¶
func UnmarshallStagingEntry ¶
func UnmarshallStagingEntry(r *lib.ProtobufReader) (*StagingEntry, error)
func (*StagingEntry) HasChanged ¶
func (e *StagingEntry) HasChanged(other *StagingEntry) bool
func (*StagingEntry) Marshall ¶
func (o *StagingEntry) Marshall(w lib.ProtobufWriter) error
func (*StagingEntry) MarshallSize ¶
func (o *StagingEntry) MarshallSize() int
func (*StagingEntry) Validate ¶
func (o *StagingEntry) Validate() error
type StagingEntryChunk ¶
type StagingEntryChunk struct {
Entries []*StagingEntry
}
func UnmarshallStagingEntryChunk ¶
func UnmarshallStagingEntryChunk(r *lib.ProtobufReader) (*StagingEntryChunk, error)
func (*StagingEntryChunk) Marshall ¶
func (o *StagingEntryChunk) Marshall(w lib.ProtobufWriter) error
func (*StagingEntryChunk) MarshallSize ¶
func (o *StagingEntryChunk) MarshallSize() int
func (*StagingEntryChunk) Validate ¶
func (o *StagingEntryChunk) Validate() error
type StagingEntryMonitor ¶
type StatusFile ¶
type StatusFile struct {
Path lib.Path
Kind lib.RevisionEntryKind
Metadata lib.PathMetadata
}
func (StatusFile) Format ¶
func (f StatusFile) Format() string
type StatusFiles ¶
type StatusFiles []StatusFile
func Status ¶
func Status( ctx context.Context, ws *Workspace, repository *lib.Repository, opts *StatusOptions, tmpFS lib.FS, ) (StatusFiles, error)
func (StatusFiles) Summary ¶
func (s StatusFiles) Summary() string
type StatusOptions ¶
type StatusOptions struct {
Include *lib.PathInclusionFilter
Exclude *lib.PathExclusionFilter
Monitor StagingEntryMonitor
SnapshotMonitor lib.RevisionSnapshotMonitor
RestorableMetadataFlag lib.RestorableMetadataFlag
UseStagingCache bool
}
type SyncTarget ¶
SyncTarget is one registered sync destination.
func LoadSyncTargets ¶
func LoadSyncTargets(ctx context.Context, w *Workspace) ([]SyncTarget, error)
LoadSyncTargets returns the workspace's registered sync targets sorted by name.
type TestCommitMonitor ¶
type TestCommitMonitor struct {
OnStartCalls []*lib.RevisionEntry
OnAddBlockCalls []*lib.RevisionEntry
OnEndCalls []*lib.RevisionEntry
}
func (*TestCommitMonitor) OnAddBlock ¶
func (m *TestCommitMonitor) OnAddBlock( entry *lib.RevisionEntry, blockId lib.BlockId, dataSize int, dataBytesWritten *int, ) error
func (*TestCommitMonitor) OnBeforeCommit ¶
func (m *TestCommitMonitor) OnBeforeCommit() error
func (*TestCommitMonitor) OnEnd ¶
func (m *TestCommitMonitor) OnEnd(entry *lib.RevisionEntry) error
func (*TestCommitMonitor) OnStart ¶
func (m *TestCommitMonitor) OnStart(entry *lib.RevisionEntry) error
type TestCpMonitor ¶
type TestCpMonitor struct {
Exists CpOnExists
OnStartCalls []*lib.RevisionEntry
OnWriteCalls []*lib.RevisionEntry
OnExistsCalls []*lib.RevisionEntry
OnEndCalls []*lib.RevisionEntry
OnErrorCalls []*lib.RevisionEntry
}
func NewTestCpMonitor ¶
func NewTestCpMonitor(exists CpOnExists) *TestCpMonitor
func (*TestCpMonitor) OnEnd ¶
func (m *TestCpMonitor) OnEnd(entry *lib.RevisionEntry, targetPath string) error
func (*TestCpMonitor) OnError ¶
func (m *TestCpMonitor) OnError(entry *lib.RevisionEntry, targetPath string, err error) CpOnError
func (*TestCpMonitor) OnExists ¶
func (m *TestCpMonitor) OnExists(entry *lib.RevisionEntry, targetPath string) CpOnExists
func (*TestCpMonitor) OnStart ¶
func (m *TestCpMonitor) OnStart(entry *lib.RevisionEntry, targetPath string) error
func (*TestCpMonitor) OnWrite ¶
func (m *TestCpMonitor) OnWrite(entry *lib.RevisionEntry, targetPath string, blockId lib.BlockId, data []byte) error
type TestStagingEntryInfo ¶
type TestStagingMonitor ¶
type TestStagingMonitor struct{}
func (*TestStagingMonitor) Close ¶
func (m *TestStagingMonitor) Close()
func (*TestStagingMonitor) OnEnd ¶
func (m *TestStagingMonitor) OnEnd(path lib.Path, excluded bool, metadata *lib.PathMetadata) error
type TestWorkspace ¶
func (*TestWorkspace) Head ¶
func (w *TestWorkspace) Head() lib.RevisionId
type Workspace ¶
type Workspace struct {
RemoteRepository RemoteRepository
PathPrefix lib.Path
Storage lib.Storage
FS lib.FS
TempFS lib.FS
}
func NewWorkspace ¶
func NewWorkspace( ctx context.Context, fs lib.FS, tempFS lib.FS, remoteRepository RemoteRepository, pathPrefix lib.Path, ) (*Workspace, error)
Create a new workspace. Workspaces can be nested, i.e. a workspace can be inside another workspace.
func OpenWorkspace ¶
Load the configuration from `<fs>/.cling/workspace.txt`.
func (*Workspace) DeleteSavedPassphrase ¶
func (*Workspace) HasSavedPassphrase ¶
func (*Workspace) ReadSavedPassphrase ¶
func (*Workspace) WriteSavedPassphrase ¶
func (w *Workspace) WriteSavedPassphrase(ctx context.Context, passphrase []byte, cipher cryptoCipher.AEAD) error
WriteSavedPassphrase AEAD-encrypts `passphrase` with `cipher` and stores the ciphertext as a workspace control file. The encryption key (which `cipher` was built from) is meant to live in the system keychain; the two-layer scheme means neither alone unlocks the repository.
type WorkspaceTestData ¶
type WorkspaceTestData struct{}
func (WorkspaceTestData) CommitFilesOptions ¶
func (wstd WorkspaceTestData) CommitFilesOptions() *CommitFilesOptions
func (WorkspaceTestData) CommitMonitor ¶
func (wstd WorkspaceTestData) CommitMonitor() *TestCommitMonitor
func (WorkspaceTestData) CpMonitor ¶
func (wstd WorkspaceTestData) CpMonitor() *TestCpMonitor
func (WorkspaceTestData) CpMonitorOverwrite ¶
func (wstd WorkspaceTestData) CpMonitorOverwrite() *TestCpMonitor
func (WorkspaceTestData) CpOptions ¶
func (wstd WorkspaceTestData) CpOptions(revisionId lib.RevisionId) *CpOptions
func (WorkspaceTestData) ImportOptions ¶
func (wstd WorkspaceTestData) ImportOptions(dest lib.Path) *ImportOptions
func (WorkspaceTestData) LsOptions ¶
func (wstd WorkspaceTestData) LsOptions(revisionId lib.RevisionId) *LsOptions
func (WorkspaceTestData) MergeOptions ¶
func (wstd WorkspaceTestData) MergeOptions() *MergeOptions
func (WorkspaceTestData) NewTestWorkspace ¶
func (wstd WorkspaceTestData) NewTestWorkspace(tb testing.TB, repository *lib.Repository) *TestWorkspace
func (WorkspaceTestData) NewTestWorkspaceExtra ¶
func (wstd WorkspaceTestData) NewTestWorkspaceExtra( tb testing.TB, repository *lib.Repository, pathPrefix string, fs lib.FS, ) *TestWorkspace
func (WorkspaceTestData) NewTestWorkspaceWithPathPrefix ¶
func (wstd WorkspaceTestData) NewTestWorkspaceWithPathPrefix( tb testing.TB, repository *lib.Repository, pathPrefix string, ) *TestWorkspace
func (WorkspaceTestData) ResetOptions ¶
func (wstd WorkspaceTestData) ResetOptions(revisionId lib.RevisionId, force bool) *ResetOptions
func (WorkspaceTestData) SnapshotMonitor ¶
func (wstd WorkspaceTestData) SnapshotMonitor() *lib.TestRevisionSnapshotMonitor
func (WorkspaceTestData) StagingEntryInfos ¶
func (wstd WorkspaceTestData) StagingEntryInfos(temp *lib.Temp[*StagingEntry]) []TestStagingEntryInfo
func (WorkspaceTestData) StagingMonitor ¶
func (wstd WorkspaceTestData) StagingMonitor() *TestStagingMonitor
func (WorkspaceTestData) StatusOptions ¶
func (wstd WorkspaceTestData) StatusOptions() *StatusOptions