Skip to main content

Store

Struct Store 

Source
pub struct Store<'a> { /* private fields */ }
Expand description

An open store.

Implementations§

Source§

impl Store<'_>

Source

pub fn bare_incoming( &self, path: &Path, head: &str, limit: usize, ) -> Option<usize>

How many commits reachable from head in the bare repository at path are not in HEAD’s history (at most limit); None when the repository or a commit cannot be read (a sync tool may still be copying). Reads the bare repository only.

Source§

impl Store<'_>

Source

pub fn import_history( &self, path: &Path, ids: &[String], tags: &BTreeMap<String, String>, ) -> Result<Vec<String>, CoreError>

The history behind ids and the tags of tags out of the bare repository path (remote_incomplete when an object is missing). Returns the tags created.

Source

pub fn init_from_bare<'a>( env: &Env, fs: &'a dyn Fs, home: &SurjectionHome, client: &str, bare: &Path, head: &str, tags: &BTreeMap<String, String>, ) -> Result<Store<'a>, CoreError>

A new store in home holding the history of head from the bare repository bare (another machine’s store.git). The working tree is checked out; this machine gets its own identity. On failure nothing is left behind, so a retry (after remote_incomplete) starts over.

Source

pub fn init_from_files<'a>( env: &Env, fs: &'a dyn Fs, home: &SurjectionHome, client: &str, files: Files, summary: &str, ) -> Result<Store<'a>, CoreError>

A new store in home whose first commit holds files (an exported tree: a mirror or a zip). The store identity is the one in files. On failure (validation, the leak scan) nothing is left behind.

Source§

impl Store<'_>

Source

pub fn semantic_diff( &self, from: Option<&CommitId>, to: &CommitId, ) -> Result<Vec<EntityChange>, CoreError>

The semantic diff from from (None: the empty store) to to, ordered by file.

Source

pub fn raw_diff( &self, from: Option<&CommitId>, to: &CommitId, ) -> Result<String, CoreError>

The unified git diff from from (None: the empty store) to to.

Source§

impl Store<'_>

Source

pub fn commit_count(&self) -> Result<usize, CoreError>

How many commits HEAD reaches; walks ids only, reads no commit.

Source

pub fn log(&self, filter: &LogFilter) -> Result<Vec<LogEntry>, CoreError>

Commits reachable from HEAD, newest first, matching filter.

Source

pub fn entry(&self, id: &CommitId) -> Result<(LogEntry, String), CoreError>

The commit id as a log entry, with its full message.

Source

pub fn scan_history(&self) -> Result<Vec<HistoryFinding>, CoreError>

The leak scanner over every commit message and every file version reachable from HEAD (SPEC 11.8), for stores imported from elsewhere. Reports only; history is never rewritten. Each file version is scanned once, at the newest commit holding it; the working tree’s allowlist applies.

Source§

impl Store<'_>

Source

pub fn merge_incoming( &self, incoming: &CommitId, label: &str, ) -> Result<MergeOutcome, CoreError>

Merges incoming (whose objects are in the store already) into HEAD; label names it in the merge commit (merge: <label>).

Source§

impl Store<'_>

Source

pub fn resolve(&self, id: &str) -> Result<CommitId, CoreError>

The commit id (full or abbreviated hex) as a full id.

Source

pub fn revision(&self, id: &CommitId) -> Result<Revision<'_>, CoreError>

The store as of commit id.

Source

pub fn first_parent(&self, id: &CommitId) -> Result<Option<CommitId>, CoreError>

The first parent of commit id; None for the initial commit.

Source

pub fn changed_files( &self, from: &CommitId, to: &CommitId, ) -> Result<Vec<String>, CoreError>

Store-relative files whose content differs between from and to (added, removed or changed), sorted.

Source

pub fn create_tag(&self, name: &str, target: &CommitId) -> Result<(), CoreError>

Creates the lightweight tag name on commit target; already_exists when the tag exists.

Source

pub fn tag_exists(&self, name: &str) -> bool

Whether the tag name exists.

Source

pub fn tag_target(&self, name: &str) -> Result<Option<CommitId>, CoreError>

The commit a tag points at.

Source

pub fn ahead_behind( &self, local: &CommitId, upstream: &CommitId, ) -> Result<(usize, usize), CoreError>

Commits reachable from local but not upstream, and from upstream but not local (ahead, behind). Both must be in the store.

Source

pub fn count_not_in( &self, head: &CommitId, hide: &[CommitId], ) -> Result<Option<usize>, CoreError>

Commits reachable from head and from none of hide; ids this store does not have are ignored. None when every id is unknown.

Source§

impl Store<'_>

Source

pub fn create_user_tag( &self, name: &str, target: &CommitId, message: Option<&str>, ) -> Result<TagInfo, CoreError>

Creates the annotated user tag name on target, tagged by this machine. message defaults to tag <name>.

Source

pub fn create_auto_tag(&self, kind: &str) -> Result<String, CoreError>

Creates auto/<kind>/<timestamp> on HEAD; see Store::create_auto_tag_at.

Source

pub fn create_auto_tag_at( &self, kind: &str, target: &CommitId, ) -> Result<String, CoreError>

Creates auto/<kind>/<timestamp> (with a -N suffix when taken) on target and prunes automatic tags older than AUTO_TAG_RETENTION (best effort). Returns the new tag’s name.

Source

pub fn prune_auto_tags( &self, now: SystemTime, retention: Duration, ) -> Result<Vec<String>, CoreError>

Deletes automatic tags made more than retention before now. User tags and automatic tags whose time cannot be read are kept. Returns the deleted names.

Source

pub fn tags(&self) -> Result<Vec<TagInfo>, CoreError>

Every tag that points at a commit, user tags first, then automatic ones, each sorted by name. Tags that do not resolve to a commit are left out.

Source

pub fn tag(&self, name: &str) -> Result<Option<TagInfo>, CoreError>

The tag name, if it exists.

Source

pub fn delete_tag(&self, name: &str) -> Result<(), CoreError>

Deletes the tag name; not_found when there is none.

Source§

impl Store<'_>

Source

pub fn transaction<'s, T>( &'s self, operation: Operation, f: impl FnOnce(&mut Transaction<'s>) -> Result<T, CoreError>, ) -> Result<Committed<T>, CoreError>

Runs one mutation: takes the cross-process lock (waiting up to LOCK_TIMEOUT), lets f stage changes, validates every staged store file, runs the leak scanner (SPEC 11.8) over the staged files and the commit message, writes them to the working tree and creates exactly one commit with the Operation’s trailers. When f, validation or the scanner fails nothing is written and nothing is committed.

Source

pub fn worktree_changes(&self) -> Result<Vec<String>, CoreError>

Store files edited, added or removed in the working tree since HEAD (hand edits), store-relative and sorted. A nested repository (shown by git as a directory) is not a store file and is left out.

Source

pub fn commit_worktree( &self, operation: Operation, ) -> Result<(Option<CommitId>, Vec<String>), CoreError>

Commits the working tree’s hand edits (Store::worktree_changes, read under the lock) as one commit with their entities as trailers, after the same validation and leak scan as every transaction. Returns the commit (None when the working tree is clean) and the files it holds.

Source§

impl<'a> Store<'a>

Source

pub fn open( env: &Env, fs: &'a dyn Fs, home: &SurjectionHome, client: &str, ) -> Result<Option<Self>, CoreError>

Opens the store in home, or None when it has not been created yet. Creates nothing. client names the calling program and version for the Surjection-Client trailer (surject-cli/0.1.0).

Source

pub fn open_or_init( env: &Env, fs: &'a dyn Fs, home: &SurjectionHome, client: &str, ) -> Result<Self, CoreError>

Opens the store in home, creating it first if needed: a git repository on main whose initial commit init: store <store_id> holds loadout.toml.

Source

pub fn root(&self) -> &Path

The store working tree.

Source

pub fn fs(&self) -> &'a dyn Fs

The file system the store was opened with.

Source

pub fn state_dir(&self) -> &Path

<SURJECTION_HOME>/state.

Source

pub fn contains(&self, id: &CommitId) -> bool

Whether commit id is HEAD or in HEAD’s history.

Source

pub fn reference_target( &self, name: &str, ) -> Result<Option<CommitId>, CoreError>

The commit reference name (refs/remotes/<name>/main) points at; None when there is no such reference.

Source

pub fn env(&self) -> &Env

The environment the store was opened with.

Source

pub fn secret_memory(&self) -> &Arc<SecretMemory> ⓘ

Hashes of the secret values this process resolved. Share it with every crate::secrets::providers::Resolver of the process, so commits holding a resolved value are refused (SPEC 11.8).

Source

pub fn identity(&self) -> &StoreIdentity

Source

pub fn store_id(&self) -> &str

Source

pub fn head(&self) -> Result<CommitId, CoreError>

The commit main points at.

Source

pub fn path(&self, relative: &str) -> Result<PathBuf, CoreError>

Absolute path of a store-relative path (servers/github.toml).

Source

pub fn read_to_string( &self, relative: &str, ) -> Result<Option<String>, CoreError>

Reads a store file from the working tree; None if it does not exist.

Source

pub fn server( &self, id: &str, ) -> Result<Option<TomlDocument<Server>>, CoreError>

The server id, parsed but not validated; None if it does not exist.

Source

pub fn servers(&self) -> Result<Vec<ServerEntry>, CoreError>

Every servers/*.toml, sorted by id, parsed and validated.

Source§

impl Store<'_>

Source

pub fn check_incoming( &self, id: &CommitId, origin: &str, ) -> Result<(), CoreError>

Source

pub fn check_incoming_with( &self, id: &CommitId, origin: &str, registry: &Registry, ) -> Result<(), CoreError>

check_store_files_with over commit id’s tree (its objects are in the store already): run before a pull or restore tags or merges it, so a refused source leaves HEAD, the working tree and the tags as they were.

Trait Implementations§

Source§

impl Debug for Store<'_>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl StoreRead for Store<'_>

Source§

fn read_file(&self, relative: &str) -> Result<Option<String>, CoreError>

A store file as text; None if it does not exist.
Source§

fn list_files(&self, dir: &str) -> Result<Vec<String>, CoreError>

Names of the files (not directories) directly in the store-relative directory dir, sorted; empty if it does not exist.

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for Store<'a>

§

impl<'a> !Sync for Store<'a>

§

impl<'a> !UnwindSafe for Store<'a>

§

impl<'a> Forget for Store<'a>

§

impl<'a> Freeze for Store<'a>
where *const u8 is !null: Freeze, PhantomData<u8>: Freeze, *const LeafNode<String, OsString> is !null: Freeze, PhantomData<(Owned, LeafOrInternal)>: Freeze, PhantomData<Box<(String, OsString)>>: Freeze, *const ArcInner<dyn Clock> is !null: Freeze, PhantomData<ArcInner<dyn Clock>>: Freeze, &'a dyn Fs: Freeze, *mut git_repository: Freeze, *const LeafNode<String, Value> is !null: Freeze, PhantomData<Box<(String, Value)>>: Freeze, *const ArcInner<SecretMemory> is !null: Freeze, PhantomData<ArcInner<SecretMemory>>: Freeze,

§

impl<'a> Move for Store<'a>

§

impl<'a> Send for Store<'a>
where RawVecInner: Send, NodeRef<Owned, String, OsString, LeafOrInternal>: Send, BoxRaw<(String, OsString)>: Send, Arc<dyn Clock>: Send, &'a dyn Fs: Send, Repository: Send, NodeRef<Owned, String, Value, LeafOrInternal>: Send, BoxRaw<(String, Value)>: Send, Arc<SecretMemory>: Send,

§

impl<'a> Unpin for Store<'a>
where *const u8 is !null: Unpin, *const LeafNode<String, OsString> is !null: Unpin, Box<(String, OsString)>: Unpin, Arc<dyn Clock>: Unpin, &'a dyn Fs: Unpin, *mut git_repository: Unpin, *const LeafNode<String, Value> is !null: Unpin, Box<(String, Value)>: Unpin, Arc<SecretMemory>: Unpin,

§

impl<'a> UnsafeUnpin for Store<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more