mirror of
https://seed.radicle.dev/rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5.git
synced 2026-11-21 02:20:43 +08:00
radicle/git/refs/storage: Tune glob helpers
Rename `cob` to `cob_with_namespace` and `cobs` to `cob` to make room for a new `cobs` that can be used to list all COBs (by type) in a repo.
This commit is contained in:
@@ -1614,7 +1614,7 @@ fn missing_delegate_default_branch() {
|
||||
"Further investigation into delegates",
|
||||
);
|
||||
let assert_bobs_issue_exists = |repo: &Repository| {
|
||||
let issue_ref = radicle::git::refs::storage::cob(
|
||||
let issue_ref = radicle::git::refs::storage::cob_with_namespace(
|
||||
bob.signer.public_key(),
|
||||
&radicle::cob::issue::TYPENAME,
|
||||
&issue,
|
||||
|
||||
@@ -1475,7 +1475,8 @@ mod test {
|
||||
fn write_non_commit_cob_ref(repo: &storage::git::Repository, issue: &IssueId) {
|
||||
let mallory = SigningKey::mock(!1);
|
||||
let blob = repo.backend.blob(b"not a commit").unwrap();
|
||||
let name = crate::git::refs::storage::cob(mallory.public_key(), &TYPENAME, issue);
|
||||
let name =
|
||||
crate::git::refs::storage::cob_with_namespace(mallory.public_key(), &TYPENAME, issue);
|
||||
|
||||
repo.backend
|
||||
.reference(name.as_str(), blob, true, "mallory")
|
||||
@@ -1544,7 +1545,8 @@ mod test {
|
||||
.unwrap();
|
||||
let id = issue.id;
|
||||
|
||||
let own = crate::git::refs::storage::cob(node.signer.public_key(), &TYPENAME, &id);
|
||||
let own =
|
||||
crate::git::refs::storage::cob_with_namespace(node.signer.public_key(), &TYPENAME, &id);
|
||||
repo.backend
|
||||
.find_reference(own.as_str())
|
||||
.unwrap()
|
||||
|
||||
@@ -355,7 +355,7 @@ where
|
||||
/// Remove an object.
|
||||
pub fn remove(&mut self, id: &ObjectId) -> Result<(), Error> {
|
||||
let namespace = self.access.signer.public_key();
|
||||
let name = git::refs::storage::cob(namespace, self.scope.type_name, id);
|
||||
let name = git::refs::storage::cob_with_namespace(namespace, self.scope.type_name, id);
|
||||
match self.repo.reference_oid(namespace, &name.strip_namespace()) {
|
||||
Ok(_) => {
|
||||
cob::remove(self.repo, namespace, self.scope.type_name, id)?;
|
||||
|
||||
@@ -69,7 +69,7 @@ impl CobRange {
|
||||
/// The range will be from the root, given by the [`ObjectId`], to the
|
||||
/// reference tips of all remote namespaces.
|
||||
pub fn new(typename: &TypeName, object_id: &ObjectId) -> Self {
|
||||
let glob = crate::storage::refs::cobs(typename, object_id);
|
||||
let glob = crate::storage::refs::cob(typename, object_id);
|
||||
Self {
|
||||
root: **object_id,
|
||||
until: iter::Until::Glob(glob),
|
||||
|
||||
@@ -245,7 +245,7 @@ pub mod refs {
|
||||
///
|
||||
/// `refs/namespaces/<remote>/refs/cobs/<typename>/<object_id>`
|
||||
///
|
||||
pub fn cob<'a>(
|
||||
pub fn cob_with_namespace<'a>(
|
||||
remote: &RemoteId,
|
||||
typename: &cob::TypeName,
|
||||
object_id: &cob::ObjectId,
|
||||
@@ -262,13 +262,24 @@ pub mod refs {
|
||||
///
|
||||
/// `refs/namespaces/*/refs/cobs/<typename>/<object_id>`
|
||||
///
|
||||
pub fn cobs(typename: &cob::TypeName, object_id: &cob::ObjectId) -> refspec::PatternString {
|
||||
pub fn cob(typename: &cob::TypeName, object_id: &cob::ObjectId) -> refspec::PatternString {
|
||||
pattern!("refs/namespaces/*")
|
||||
.join(refname!("refs/cobs"))
|
||||
.join(Component::from(typename))
|
||||
.join(Component::from(object_id))
|
||||
}
|
||||
|
||||
/// All collaborative objects, identified by `typename`, for all remotes.
|
||||
///
|
||||
/// `refs/namespaces/*/refs/cobs/<typename>/<object_id>`
|
||||
///
|
||||
pub fn cobs(typename: &cob::TypeName) -> refspec::PatternString {
|
||||
pattern!("refs/namespaces/*")
|
||||
.join(refname!("refs/cobs"))
|
||||
.join(Component::from(typename))
|
||||
.join_pattern(refspec::STAR)
|
||||
}
|
||||
|
||||
/// Draft references.
|
||||
///
|
||||
/// These references are not replicated or signed.
|
||||
|
||||
@@ -1061,7 +1061,11 @@ impl Doc {
|
||||
let cob = identity::Identity::initialize(self, repo, signer)?;
|
||||
let public_key = signer.public_key();
|
||||
let id_ref = git::refs::storage::id(public_key);
|
||||
let cob_ref = git::refs::storage::cob(public_key, &crate::cob::identity::TYPENAME, &cob.id);
|
||||
let cob_ref = git::refs::storage::cob_with_namespace(
|
||||
public_key,
|
||||
&crate::cob::identity::TYPENAME,
|
||||
&cob.id,
|
||||
);
|
||||
// Set `…/refs/rad/id` -> `…/refs/cobs/xyz.radicle.id/<id>`
|
||||
repo.backend.reference_symbolic(
|
||||
id_ref.as_str(),
|
||||
|
||||
@@ -113,7 +113,7 @@ impl cob::object::Storage for Repository {
|
||||
object_id: &cob::ObjectId,
|
||||
) -> Result<cob::object::Objects, Self::ObjectsError> {
|
||||
self.backend
|
||||
.references_glob(git::refs::storage::cobs(typename, object_id).as_str())?
|
||||
.references_glob(&git::refs::storage::cob(typename, object_id))?
|
||||
.try_fold(cob::object::Objects::default(), |mut objects, reference| {
|
||||
if let Some(reference) = cob_reference(reference?)? {
|
||||
objects.push(reference);
|
||||
@@ -173,7 +173,7 @@ impl cob::object::Storage for Repository {
|
||||
entry: &cob::EntryId,
|
||||
) -> Result<(), Self::UpdateError> {
|
||||
self.backend.reference(
|
||||
git::refs::storage::cob(namespace, typename, object_id).as_str(),
|
||||
git::refs::storage::cob_with_namespace(namespace, typename, object_id).as_str(),
|
||||
(*entry).into(),
|
||||
true,
|
||||
&format!(
|
||||
@@ -190,9 +190,9 @@ impl cob::object::Storage for Repository {
|
||||
typename: &cob::TypeName,
|
||||
object_id: &cob::ObjectId,
|
||||
) -> Result<(), Self::RemoveError> {
|
||||
let mut reference = self
|
||||
.backend
|
||||
.find_reference(git::refs::storage::cob(namespace, typename, object_id).as_str())?;
|
||||
let mut reference = self.backend.find_reference(
|
||||
git::refs::storage::cob_with_namespace(namespace, typename, object_id).as_str(),
|
||||
)?;
|
||||
|
||||
reference.delete()
|
||||
}
|
||||
@@ -415,7 +415,7 @@ impl<R: storage::WriteRepository> cob::object::Storage for DraftStore<'_, R> {
|
||||
// First get the signed COB tips of all remotes for this object.
|
||||
let signed = self
|
||||
.repo
|
||||
.references_glob(&git::refs::storage::cobs(typename, object_id))?;
|
||||
.references_glob(&git::refs::storage::cob(typename, object_id))?;
|
||||
|
||||
for (r, id) in signed {
|
||||
let r = cob::object::Reference {
|
||||
|
||||
Reference in New Issue
Block a user