pub struct RepositoryId(/* private fields */);Expand description
A git repository, named without naming a disk.
The value is crate::repository::git_identity’s digest of the git directory every
work tree shares: one value for the primary checkout and every linked worktree of it,
a different value for a different repository, and never a path — a shared record that
carried the path would disclose where somebody keeps their work, which is of no use to
a reader and of some use to somebody else (ADR 0014).
use majordomus_cli::session::RepositoryId;
use std::process::Command;
let dir = tempfile::tempdir().unwrap();
let root = dir.path().join("repo");
std::fs::create_dir_all(&root).unwrap();
let git = |args: &[&str]| assert!(
Command::new("git").arg("-C").arg(&root).args(args).status().unwrap().success()
);
git(&["init", "-q", "."]);
git(&["-c", "user.email=t@e.x", "-c", "user.name=t", "commit", "-q", "--allow-empty", "-m", "i"]);
let wt = dir.path().join("repo-wt");
git(&["worktree", "add", "-q", "-b", "feature/x", wt.to_str().unwrap()]);
let here = RepositoryId::of(&root).expect("a work tree");
let there = RepositoryId::of(&wt).expect("a linked work tree");
assert_eq!(here, there, "one repository, two checkouts");
assert!(!here.as_str().contains('/'), "a digest, never a path");Implementations§
Source§impl RepositoryId
impl RepositoryId
Sourcepub fn of(root: &Path) -> Option<Self>
pub fn of(root: &Path) -> Option<Self>
The repository the checkout at root belongs to. None where git cannot be asked:
a repository of the layer does not have to be version controlled, and saying so is
better than inventing an identity for one that is not.
use majordomus_cli::session::RepositoryId;
// absence is an answer: a plain directory belongs to no repository, and saying so is
// better than minting an identity nothing could ever match
let plain = tempfile::tempdir().unwrap();
assert!(RepositoryId::of(plain.path()).is_none());Sourcepub fn recorded(value: impl Into<String>) -> Self
pub fn recorded(value: impl Into<String>) -> Self
A value read back from a record that already carries one.
It takes whatever the store wrote, because a store written by an older version of the tool carries an older spelling and refusing to read it would lose the record. What this type guarantees is not the shape of the string; it is that the string is never passed where a checkout, an episode or a provider session is wanted.
use majordomus_cli::session::RepositoryId;
let recorded = RepositoryId::recorded("git@github.com:korczis/prismatic-majordomus.git");
assert_eq!(recorded.as_str(), "git@github.com:korczis/prismatic-majordomus.git");Trait Implementations§
Source§impl Clone for RepositoryId
impl Clone for RepositoryId
Source§fn clone(&self) -> RepositoryId
fn clone(&self) -> RepositoryId
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for RepositoryId
impl Debug for RepositoryId
Source§impl<'de> Deserialize<'de> for RepositoryId
impl<'de> Deserialize<'de> for RepositoryId
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for RepositoryId
Source§impl Hash for RepositoryId
impl Hash for RepositoryId
Source§impl JsonSchema for RepositoryId
impl JsonSchema for RepositoryId
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
$ref keyword. Read moreSource§impl Ord for RepositoryId
impl Ord for RepositoryId
Source§fn cmp(&self, other: &RepositoryId) -> Ordering
fn cmp(&self, other: &RepositoryId) -> Ordering
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for RepositoryId
impl PartialEq for RepositoryId
Source§fn eq(&self, other: &RepositoryId) -> bool
fn eq(&self, other: &RepositoryId) -> bool
self and other values to be equal, and is used by ==.Source§impl PartialOrd for RepositoryId
impl PartialOrd for RepositoryId
Source§impl Serialize for RepositoryId
impl Serialize for RepositoryId
impl StructuralPartialEq for RepositoryId
Auto Trait Implementations§
impl Freeze for RepositoryId
impl RefUnwindSafe for RepositoryId
impl Send for RepositoryId
impl Sync for RepositoryId
impl Unpin for RepositoryId
impl UnsafeUnpin for RepositoryId
impl UnwindSafe for RepositoryId
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.