pub struct Store<'a> { /* private fields */ }Expand description
An open store.
Implementations§
Source§impl Store<'_>
impl Store<'_>
Sourcepub fn bare_incoming(
&self,
path: &Path,
head: &str,
limit: usize,
) -> Option<usize>
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<'_>
impl Store<'_>
Sourcepub fn import_history(
&self,
path: &Path,
ids: &[String],
tags: &BTreeMap<String, String>,
) -> Result<Vec<String>, CoreError>
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.
Sourcepub 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>
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.
Sourcepub fn init_from_files<'a>(
env: &Env,
fs: &'a dyn Fs,
home: &SurjectionHome,
client: &str,
files: Files,
summary: &str,
) -> Result<Store<'a>, CoreError>
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<'_>
impl Store<'_>
Sourcepub fn semantic_diff(
&self,
from: Option<&CommitId>,
to: &CommitId,
) -> Result<Vec<EntityChange>, CoreError>
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§impl Store<'_>
impl Store<'_>
Sourcepub fn commit_count(&self) -> Result<usize, CoreError>
pub fn commit_count(&self) -> Result<usize, CoreError>
How many commits HEAD reaches; walks ids only, reads no commit.
Sourcepub fn log(&self, filter: &LogFilter) -> Result<Vec<LogEntry>, CoreError>
pub fn log(&self, filter: &LogFilter) -> Result<Vec<LogEntry>, CoreError>
Commits reachable from HEAD, newest first, matching filter.
Sourcepub fn entry(&self, id: &CommitId) -> Result<(LogEntry, String), CoreError>
pub fn entry(&self, id: &CommitId) -> Result<(LogEntry, String), CoreError>
The commit id as a log entry, with its full message.
Sourcepub fn scan_history(&self) -> Result<Vec<HistoryFinding>, CoreError>
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<'_>
impl Store<'_>
Sourcepub fn merge_incoming(
&self,
incoming: &CommitId,
label: &str,
) -> Result<MergeOutcome, CoreError>
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<'_>
impl Store<'_>
Sourcepub fn resolve(&self, id: &str) -> Result<CommitId, CoreError>
pub fn resolve(&self, id: &str) -> Result<CommitId, CoreError>
The commit id (full or abbreviated hex) as a full id.
Sourcepub fn revision(&self, id: &CommitId) -> Result<Revision<'_>, CoreError>
pub fn revision(&self, id: &CommitId) -> Result<Revision<'_>, CoreError>
The store as of commit id.
Sourcepub fn first_parent(&self, id: &CommitId) -> Result<Option<CommitId>, CoreError>
pub fn first_parent(&self, id: &CommitId) -> Result<Option<CommitId>, CoreError>
The first parent of commit id; None for the initial commit.
Sourcepub fn changed_files(
&self,
from: &CommitId,
to: &CommitId,
) -> Result<Vec<String>, CoreError>
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.
Sourcepub fn create_tag(&self, name: &str, target: &CommitId) -> Result<(), CoreError>
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.
Sourcepub fn tag_exists(&self, name: &str) -> bool
pub fn tag_exists(&self, name: &str) -> bool
Whether the tag name exists.
Sourcepub fn tag_target(&self, name: &str) -> Result<Option<CommitId>, CoreError>
pub fn tag_target(&self, name: &str) -> Result<Option<CommitId>, CoreError>
The commit a tag points at.
Source§impl Store<'_>
impl Store<'_>
Sourcepub fn create_user_tag(
&self,
name: &str,
target: &CommitId,
message: Option<&str>,
) -> Result<TagInfo, CoreError>
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>.
Sourcepub fn create_auto_tag(&self, kind: &str) -> Result<String, CoreError>
pub fn create_auto_tag(&self, kind: &str) -> Result<String, CoreError>
Creates auto/<kind>/<timestamp> on HEAD; see
Store::create_auto_tag_at.
Sourcepub fn create_auto_tag_at(
&self,
kind: &str,
target: &CommitId,
) -> Result<String, CoreError>
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.
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.
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§impl Store<'_>
impl Store<'_>
Sourcepub fn transaction<'s, T>(
&'s self,
operation: Operation,
f: impl FnOnce(&mut Transaction<'s>) -> Result<T, CoreError>,
) -> Result<Committed<T>, CoreError>
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.
Sourcepub fn worktree_changes(&self) -> Result<Vec<String>, CoreError>
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.
Sourcepub fn commit_worktree(
&self,
operation: Operation,
) -> Result<(Option<CommitId>, Vec<String>), CoreError>
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>
impl<'a> Store<'a>
Sourcepub fn open(
env: &Env,
fs: &'a dyn Fs,
home: &SurjectionHome,
client: &str,
) -> Result<Option<Self>, CoreError>
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).
Sourcepub fn open_or_init(
env: &Env,
fs: &'a dyn Fs,
home: &SurjectionHome,
client: &str,
) -> Result<Self, CoreError>
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.
Sourcepub fn reference_target(
&self,
name: &str,
) -> Result<Option<CommitId>, CoreError>
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.
Sourcepub fn secret_memory(&self) -> &Arc<SecretMemory> ⓘ
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).
pub fn identity(&self) -> &StoreIdentity
pub fn store_id(&self) -> &str
Sourcepub fn path(&self, relative: &str) -> Result<PathBuf, CoreError>
pub fn path(&self, relative: &str) -> Result<PathBuf, CoreError>
Absolute path of a store-relative path (servers/github.toml).
Sourcepub fn read_to_string(
&self,
relative: &str,
) -> Result<Option<String>, CoreError>
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§impl Store<'_>
impl Store<'_>
Sourcepub fn check_incoming_with(
&self,
id: &CommitId,
origin: &str,
registry: &Registry,
) -> Result<(), CoreError>
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.