Remove need to pass public key in cob store
This commit is contained in:
parent
44f3984159
commit
8c22012d61
|
|
@ -80,7 +80,7 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
|
||||||
let storage = &profile.storage;
|
let storage = &profile.storage;
|
||||||
let (_, id) = radicle::rad::cwd()?;
|
let (_, id) = radicle::rad::cwd()?;
|
||||||
let repo = storage.repository_mut(id)?;
|
let repo = storage.repository_mut(id)?;
|
||||||
let mut issues = issue::Issues::open(*signer.public_key(), &repo)?;
|
let mut issues = issue::Issues::open(&repo)?;
|
||||||
|
|
||||||
let mut issue = issues.get_mut(&options.id).map_err(|err| match err {
|
let mut issue = issues.get_mut(&options.id).map_err(|err| match err {
|
||||||
cob::store::Error::NotFound(_, _) => anyhow!("issue not found '{}'", options.id),
|
cob::store::Error::NotFound(_, _) => anyhow!("issue not found '{}'", options.id),
|
||||||
|
|
|
||||||
|
|
@ -102,7 +102,7 @@ fn comment(
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut issues = Issues::open(*signer.public_key(), repo)?;
|
let mut issues = Issues::open(repo)?;
|
||||||
match issues.get_mut(&options.id) {
|
match issues.get_mut(&options.id) {
|
||||||
Ok(mut issue) => {
|
Ok(mut issue) => {
|
||||||
let comment_id = options.reply_to.unwrap_or_else(|| {
|
let comment_id = options.reply_to.unwrap_or_else(|| {
|
||||||
|
|
@ -118,7 +118,7 @@ fn comment(
|
||||||
Err(e) => return Err(e.into()),
|
Err(e) => return Err(e.into()),
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut patches = Patches::open(*signer.public_key(), repo)?;
|
let mut patches = Patches::open(repo)?;
|
||||||
match patches.get_mut(&options.id) {
|
match patches.get_mut(&options.id) {
|
||||||
Ok(mut patch) => {
|
Ok(mut patch) => {
|
||||||
let (revision_id, _) = patch.revisions().last().expect("patch has a revision");
|
let (revision_id, _) = patch.revisions().last().expect("patch has a revision");
|
||||||
|
|
|
||||||
|
|
@ -238,7 +238,7 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
|
||||||
let storage = &profile.storage;
|
let storage = &profile.storage;
|
||||||
let (_, id) = radicle::rad::cwd()?;
|
let (_, id) = radicle::rad::cwd()?;
|
||||||
let repo = storage.repository(id)?;
|
let repo = storage.repository(id)?;
|
||||||
let mut proposals = Proposals::open(*signer.public_key(), &repo)?;
|
let mut proposals = Proposals::open(&repo)?;
|
||||||
let previous = Identity::load(signer.public_key(), &repo)?;
|
let previous = Identity::load(signer.public_key(), &repo)?;
|
||||||
|
|
||||||
let interactive = &options.interactive;
|
let interactive = &options.interactive;
|
||||||
|
|
|
||||||
|
|
@ -197,7 +197,7 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
|
||||||
let storage = &profile.storage;
|
let storage = &profile.storage;
|
||||||
let (_, id) = radicle::rad::cwd()?;
|
let (_, id) = radicle::rad::cwd()?;
|
||||||
let repo = storage.repository_mut(id)?;
|
let repo = storage.repository_mut(id)?;
|
||||||
let mut issues = Issues::open(*signer.public_key(), &repo)?;
|
let mut issues = Issues::open(&repo)?;
|
||||||
|
|
||||||
match options.op {
|
match options.op {
|
||||||
Operation::Open {
|
Operation::Open {
|
||||||
|
|
|
||||||
|
|
@ -140,7 +140,7 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
|
||||||
.identity_doc_of(profile.id())
|
.identity_doc_of(profile.id())
|
||||||
.context(format!("couldn't load project {id} from local state"))?;
|
.context(format!("couldn't load project {id} from local state"))?;
|
||||||
let repository = profile.storage.repository(id)?;
|
let repository = profile.storage.repository(id)?;
|
||||||
let mut patches = Patches::open(*profile.id(), &repository)?;
|
let mut patches = Patches::open(&repository)?;
|
||||||
|
|
||||||
if repo.head_detached()? {
|
if repo.head_detached()? {
|
||||||
anyhow::bail!("HEAD is in a detached state; can't merge");
|
anyhow::bail!("HEAD is in a detached state; can't merge");
|
||||||
|
|
|
||||||
|
|
@ -215,7 +215,7 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
|
||||||
list::run(&repository, &profile, Some(workdir))?;
|
list::run(&repository, &profile, Some(workdir))?;
|
||||||
}
|
}
|
||||||
Operation::Show { ref patch_id } => {
|
Operation::Show { ref patch_id } => {
|
||||||
show::run(&repository, &profile, &workdir, patch_id)?;
|
show::run(&repository, &workdir, patch_id)?;
|
||||||
}
|
}
|
||||||
Operation::Update {
|
Operation::Update {
|
||||||
patch_id,
|
patch_id,
|
||||||
|
|
@ -231,7 +231,7 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
Operation::Checkout { ref patch_id } => {
|
Operation::Checkout { ref patch_id } => {
|
||||||
checkout::run(&repository, &profile, &workdir, patch_id)?;
|
checkout::run(&repository, &workdir, patch_id)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
||||||
|
|
@ -2,16 +2,14 @@ use crate::terminal as term;
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
use radicle::cob::patch::{self, PatchId};
|
use radicle::cob::patch::{self, PatchId};
|
||||||
use radicle::git::{self, RefString};
|
use radicle::git::{self, RefString};
|
||||||
use radicle::profile::Profile;
|
|
||||||
use radicle::storage::git::Repository;
|
use radicle::storage::git::Repository;
|
||||||
|
|
||||||
pub fn run(
|
pub fn run(
|
||||||
storage: &Repository,
|
storage: &Repository,
|
||||||
profile: &Profile,
|
|
||||||
git_workdir: &git::raw::Repository,
|
git_workdir: &git::raw::Repository,
|
||||||
patch_id: &PatchId,
|
patch_id: &PatchId,
|
||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
let patches = patch::Patches::open(profile.public_key, storage)?;
|
let patches = patch::Patches::open(storage)?;
|
||||||
let patch = patches
|
let patch = patches
|
||||||
.get(patch_id)?
|
.get(patch_id)?
|
||||||
.ok_or_else(|| anyhow!("Patch `{patch_id}` not found"))?;
|
.ok_or_else(|| anyhow!("Patch `{patch_id}` not found"))?;
|
||||||
|
|
|
||||||
|
|
@ -232,9 +232,10 @@ pub fn find_unmerged_with_base(
|
||||||
merge_base: Oid,
|
merge_base: Oid,
|
||||||
patches: &Patches,
|
patches: &Patches,
|
||||||
workdir: &git::raw::Repository,
|
workdir: &git::raw::Repository,
|
||||||
|
whoami: &Did,
|
||||||
) -> anyhow::Result<Vec<(PatchId, Patch, Clock)>> {
|
) -> anyhow::Result<Vec<(PatchId, Patch, Clock)>> {
|
||||||
// My patches.
|
// My patches.
|
||||||
let proposed: Vec<_> = patches.proposed_by(&patches.public_key().into())?.collect();
|
let proposed: Vec<_> = patches.proposed_by(whoami)?.collect();
|
||||||
let mut matches = Vec::new();
|
let mut matches = Vec::new();
|
||||||
|
|
||||||
for (id, patch, clock) in proposed {
|
for (id, patch, clock) in proposed {
|
||||||
|
|
|
||||||
|
|
@ -94,7 +94,7 @@ pub fn run(
|
||||||
message: term::patch::Message,
|
message: term::patch::Message,
|
||||||
options: Options,
|
options: Options,
|
||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
let mut patches = patch::Patches::open(profile.public_key, storage)?;
|
let mut patches = patch::Patches::open(storage)?;
|
||||||
let project = storage.project_of(&profile.public_key).context(format!(
|
let project = storage.project_of(&profile.public_key).context(format!(
|
||||||
"couldn't load project {} from local state",
|
"couldn't load project {} from local state",
|
||||||
storage.id
|
storage.id
|
||||||
|
|
@ -117,7 +117,7 @@ pub fn run(
|
||||||
show_patch_commit_info(
|
show_patch_commit_info(
|
||||||
&project,
|
&project,
|
||||||
workdir,
|
workdir,
|
||||||
patches.public_key(),
|
profile.id(),
|
||||||
&head_branch,
|
&head_branch,
|
||||||
&target_peer,
|
&target_peer,
|
||||||
target_oid,
|
target_oid,
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ pub fn run(
|
||||||
workdir: Option<git::raw::Repository>,
|
workdir: Option<git::raw::Repository>,
|
||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
let me = *profile.id();
|
let me = *profile.id();
|
||||||
let patches = Patches::open(*profile.id(), repository)?;
|
let patches = Patches::open(repository)?;
|
||||||
let proposed = patches.proposed()?;
|
let proposed = patches.proposed()?;
|
||||||
|
|
||||||
// Patches the user authored.
|
// Patches the user authored.
|
||||||
|
|
@ -56,7 +56,7 @@ pub fn run(
|
||||||
for (id, patch) in &mut other {
|
for (id, patch) in &mut other {
|
||||||
term::blank();
|
term::blank();
|
||||||
|
|
||||||
print(patches.public_key(), id, patch, &workdir, repository)?;
|
print(profile.id(), id, patch, &workdir, repository)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
term::blank();
|
term::blank();
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,12 @@
|
||||||
use super::common::*;
|
use super::common::*;
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
use crate::terminal as term;
|
|
||||||
use radicle::cob::patch;
|
use radicle::cob::patch;
|
||||||
use radicle::git;
|
use radicle::git;
|
||||||
use radicle::prelude::*;
|
|
||||||
use radicle::storage::git::Repository;
|
use radicle::storage::git::Repository;
|
||||||
|
|
||||||
|
use crate::terminal as term;
|
||||||
|
|
||||||
fn show_patch_diff(
|
fn show_patch_diff(
|
||||||
patch: &patch::Patch,
|
patch: &patch::Patch,
|
||||||
storage: &Repository,
|
storage: &Repository,
|
||||||
|
|
@ -23,11 +23,10 @@ fn show_patch_diff(
|
||||||
|
|
||||||
pub fn run(
|
pub fn run(
|
||||||
storage: &Repository,
|
storage: &Repository,
|
||||||
profile: &Profile,
|
|
||||||
workdir: &git::raw::Repository,
|
workdir: &git::raw::Repository,
|
||||||
patch_id: &PatchId,
|
patch_id: &PatchId,
|
||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
let patches = patch::Patches::open(profile.public_key, storage)?;
|
let patches = patch::Patches::open(storage)?;
|
||||||
let Some(patch) = patches.get(patch_id)? else {
|
let Some(patch) = patches.get(patch_id)? else {
|
||||||
anyhow::bail!("Patch `{patch_id}` not found");
|
anyhow::bail!("Patch `{patch_id}` not found");
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -21,12 +21,14 @@ fn select_patch(
|
||||||
workdir: &git::raw::Repository,
|
workdir: &git::raw::Repository,
|
||||||
head_branch: &git::raw::Branch,
|
head_branch: &git::raw::Branch,
|
||||||
target_oid: git::Oid,
|
target_oid: git::Oid,
|
||||||
|
whoami: &Did,
|
||||||
) -> anyhow::Result<patch::PatchId> {
|
) -> anyhow::Result<patch::PatchId> {
|
||||||
let head_oid = branch_oid(head_branch)?;
|
let head_oid = branch_oid(head_branch)?;
|
||||||
let base_oid = workdir.merge_base(*target_oid, *head_oid)?;
|
let base_oid = workdir.merge_base(*target_oid, *head_oid)?;
|
||||||
|
|
||||||
let mut spinner = term::spinner("Finding patches to update...");
|
let mut spinner = term::spinner("Finding patches to update...");
|
||||||
let mut result = find_unmerged_with_base(*head_oid, *target_oid, base_oid, patches, workdir)?;
|
let mut result =
|
||||||
|
find_unmerged_with_base(*head_oid, *target_oid, base_oid, patches, workdir, whoami)?;
|
||||||
|
|
||||||
let Some((id, patch, _)) = result.pop() else {
|
let Some((id, patch, _)) = result.pop() else {
|
||||||
spinner.failed();
|
spinner.failed();
|
||||||
|
|
@ -103,11 +105,11 @@ pub fn run(
|
||||||
push_to_storage(storage, &head_branch, options)?;
|
push_to_storage(storage, &head_branch, options)?;
|
||||||
|
|
||||||
let (_, target_oid) = get_merge_target(&project, storage, &head_branch)?;
|
let (_, target_oid) = get_merge_target(&project, storage, &head_branch)?;
|
||||||
let mut patches = patch::Patches::open(profile.public_key, storage)?;
|
let mut patches = patch::Patches::open(storage)?;
|
||||||
|
|
||||||
let patch_id = match patch_id {
|
let patch_id = match patch_id {
|
||||||
Some(patch_id) => patch_id,
|
Some(patch_id) => patch_id,
|
||||||
None => select_patch(&patches, workdir, &head_branch, target_oid)?,
|
None => select_patch(&patches, workdir, &head_branch, target_oid, &profile.did())?,
|
||||||
};
|
};
|
||||||
let Ok(mut patch) = patches.get_mut(&patch_id) else {
|
let Ok(mut patch) = patches.get_mut(&patch_id) else {
|
||||||
anyhow::bail!("Patch `{patch_id}` not found");
|
anyhow::bail!("Patch `{patch_id}` not found");
|
||||||
|
|
|
||||||
|
|
@ -139,7 +139,7 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
|
||||||
let _project = repository
|
let _project = repository
|
||||||
.identity_doc_of(profile.id())
|
.identity_doc_of(profile.id())
|
||||||
.context(format!("couldn't load project {id} from local state"))?;
|
.context(format!("couldn't load project {id} from local state"))?;
|
||||||
let mut patches = Patches::open(*profile.id(), &repository)?;
|
let mut patches = Patches::open(&repository)?;
|
||||||
|
|
||||||
let patch_id = options.id;
|
let patch_id = options.id;
|
||||||
let mut patch = patches
|
let mut patch = patches
|
||||||
|
|
|
||||||
|
|
@ -80,7 +80,7 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
|
||||||
let storage = &profile.storage;
|
let storage = &profile.storage;
|
||||||
let (_, id) = radicle::rad::cwd()?;
|
let (_, id) = radicle::rad::cwd()?;
|
||||||
let repo = storage.repository_mut(id)?;
|
let repo = storage.repository_mut(id)?;
|
||||||
let mut issues = issue::Issues::open(*signer.public_key(), &repo)?;
|
let mut issues = issue::Issues::open(&repo)?;
|
||||||
|
|
||||||
let mut issue = issues.get_mut(&options.id).map_err(|err| match err {
|
let mut issue = issues.get_mut(&options.id).map_err(|err| match err {
|
||||||
cob::store::Error::NotFound(_, _) => anyhow!("issue '{}' not found", options.id),
|
cob::store::Error::NotFound(_, _) => anyhow!("issue '{}' not found", options.id),
|
||||||
|
|
|
||||||
|
|
@ -51,8 +51,8 @@ impl Context {
|
||||||
let doc = repo.identity_doc()?.1.verified()?;
|
let doc = repo.identity_doc()?.1.verified()?;
|
||||||
let payload = doc.project()?;
|
let payload = doc.project()?;
|
||||||
let delegates = doc.delegates;
|
let delegates = doc.delegates;
|
||||||
let issues = Issues::open(self.profile.public_key, &repo)?.counts()?;
|
let issues = Issues::open(&repo)?.counts()?;
|
||||||
let patches = Patches::open(self.profile.public_key, &repo)?.counts()?;
|
let patches = Patches::open(&repo)?.counts()?;
|
||||||
|
|
||||||
Ok(project::Info {
|
Ok(project::Info {
|
||||||
payload,
|
payload,
|
||||||
|
|
|
||||||
|
|
@ -49,9 +49,9 @@ async fn delegates_projects_handler(
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
let Ok(issues) = Issues::open(ctx.profile.public_key, &repo) else { return None };
|
let Ok(issues) = Issues::open(&repo) else { return None };
|
||||||
let Ok(issues) = issues.counts() else { return None };
|
let Ok(issues) = issues.counts() else { return None };
|
||||||
let Ok(patches) = Patches::open(ctx.profile.public_key, &repo) else { return None };
|
let Ok(patches) = Patches::open(&repo) else { return None };
|
||||||
let Ok(patches) = patches.counts() else { return None };
|
let Ok(patches) = patches.counts() else { return None };
|
||||||
|
|
||||||
Some(Info {
|
Some(Info {
|
||||||
|
|
|
||||||
|
|
@ -83,9 +83,9 @@ async fn project_root_handler(
|
||||||
let Ok((_, doc)) = repo.identity_doc() else { return None };
|
let Ok((_, doc)) = repo.identity_doc() else { return None };
|
||||||
let Ok(doc) = doc.verified() else { return None };
|
let Ok(doc) = doc.verified() else { return None };
|
||||||
let Ok(payload) = doc.project() else { return None };
|
let Ok(payload) = doc.project() else { return None };
|
||||||
let Ok(issues) = issue::Issues::open(ctx.profile.public_key, &repo) else { return None };
|
let Ok(issues) = issue::Issues::open(&repo) else { return None };
|
||||||
let Ok(issues) = issues.counts() else { return None };
|
let Ok(issues) = issues.counts() else { return None };
|
||||||
let Ok(patches) = patch::Patches::open(ctx.profile.public_key, &repo) else { return None };
|
let Ok(patches) = patch::Patches::open(&repo) else { return None };
|
||||||
let Ok(patches) = patches.counts() else { return None };
|
let Ok(patches) = patches.counts() else { return None };
|
||||||
let delegates = doc.delegates;
|
let delegates = doc.delegates;
|
||||||
|
|
||||||
|
|
@ -395,7 +395,7 @@ async fn issues_handler(
|
||||||
let per_page = per_page.unwrap_or(10);
|
let per_page = per_page.unwrap_or(10);
|
||||||
let storage = &ctx.profile.storage;
|
let storage = &ctx.profile.storage;
|
||||||
let repo = storage.repository(project)?;
|
let repo = storage.repository(project)?;
|
||||||
let issues = issue::Issues::open(ctx.profile.public_key, &repo)?;
|
let issues = issue::Issues::open(&repo)?;
|
||||||
let mut issues: Vec<_> = issues.all()?.filter_map(|r| r.ok()).collect::<Vec<_>>();
|
let mut issues: Vec<_> = issues.all()?.filter_map(|r| r.ok()).collect::<Vec<_>>();
|
||||||
issues.sort_by(|(_, a, _), (_, b, _)| b.timestamp().cmp(&a.timestamp()));
|
issues.sort_by(|(_, a, _), (_, b, _)| b.timestamp().cmp(&a.timestamp()));
|
||||||
let issues = issues
|
let issues = issues
|
||||||
|
|
@ -432,7 +432,7 @@ async fn issue_create_handler(
|
||||||
.signer()
|
.signer()
|
||||||
.map_err(|_| Error::Auth("Unauthorized"))?;
|
.map_err(|_| Error::Auth("Unauthorized"))?;
|
||||||
let repo = storage.repository(project)?;
|
let repo = storage.repository(project)?;
|
||||||
let mut issues = issue::Issues::open(ctx.profile.public_key, &repo)?;
|
let mut issues = issue::Issues::open(&repo)?;
|
||||||
let issue = issues
|
let issue = issues
|
||||||
.create(
|
.create(
|
||||||
issue.title,
|
issue.title,
|
||||||
|
|
@ -466,7 +466,7 @@ async fn issue_update_handler(
|
||||||
let storage = &ctx.profile.storage;
|
let storage = &ctx.profile.storage;
|
||||||
let signer = ctx.profile.signer().unwrap();
|
let signer = ctx.profile.signer().unwrap();
|
||||||
let repo = storage.repository(project)?;
|
let repo = storage.repository(project)?;
|
||||||
let mut issues = issue::Issues::open(ctx.profile.public_key, &repo)?;
|
let mut issues = issue::Issues::open(&repo)?;
|
||||||
let mut issue = issues.get_mut(&issue_id.into())?;
|
let mut issue = issues.get_mut(&issue_id.into())?;
|
||||||
|
|
||||||
match action {
|
match action {
|
||||||
|
|
@ -514,7 +514,7 @@ async fn issue_handler(
|
||||||
) -> impl IntoResponse {
|
) -> impl IntoResponse {
|
||||||
let storage = &ctx.profile.storage;
|
let storage = &ctx.profile.storage;
|
||||||
let repo = storage.repository(project)?;
|
let repo = storage.repository(project)?;
|
||||||
let issue = issue::Issues::open(ctx.profile.public_key, &repo)?
|
let issue = issue::Issues::open(&repo)?
|
||||||
.get(&issue_id.into())?
|
.get(&issue_id.into())?
|
||||||
.ok_or(Error::NotFound)?;
|
.ok_or(Error::NotFound)?;
|
||||||
|
|
||||||
|
|
@ -549,7 +549,7 @@ async fn patch_create_handler(
|
||||||
.signer()
|
.signer()
|
||||||
.map_err(|_| Error::Auth("Unauthorized"))?;
|
.map_err(|_| Error::Auth("Unauthorized"))?;
|
||||||
let repo = storage.repository(project)?;
|
let repo = storage.repository(project)?;
|
||||||
let mut patches = patch::Patches::open(ctx.profile.public_key, &repo)?;
|
let mut patches = patch::Patches::open(&repo)?;
|
||||||
let base_oid = repo.raw().merge_base(*patch.target, *patch.oid)?;
|
let base_oid = repo.raw().merge_base(*patch.target, *patch.oid)?;
|
||||||
|
|
||||||
let patch = patches
|
let patch = patches
|
||||||
|
|
@ -582,7 +582,7 @@ async fn patches_handler(
|
||||||
let per_page = per_page.unwrap_or(10);
|
let per_page = per_page.unwrap_or(10);
|
||||||
let storage = &ctx.profile.storage;
|
let storage = &ctx.profile.storage;
|
||||||
let repo = storage.repository(project)?;
|
let repo = storage.repository(project)?;
|
||||||
let patches = patch::Patches::open(ctx.profile.public_key, &repo)?;
|
let patches = patch::Patches::open(&repo)?;
|
||||||
let mut patches = patches.all()?.filter_map(|r| r.ok()).collect::<Vec<_>>();
|
let mut patches = patches.all()?.filter_map(|r| r.ok()).collect::<Vec<_>>();
|
||||||
patches.sort_by(|(_, a, _), (_, b, _)| b.timestamp().cmp(&a.timestamp()));
|
patches.sort_by(|(_, a, _), (_, b, _)| b.timestamp().cmp(&a.timestamp()));
|
||||||
let patches = patches
|
let patches = patches
|
||||||
|
|
@ -603,7 +603,7 @@ async fn patch_handler(
|
||||||
) -> impl IntoResponse {
|
) -> impl IntoResponse {
|
||||||
let storage = &ctx.profile.storage;
|
let storage = &ctx.profile.storage;
|
||||||
let repo = storage.repository(project)?;
|
let repo = storage.repository(project)?;
|
||||||
let patch = patch::Patches::open(ctx.profile.public_key, &repo)?
|
let patch = patch::Patches::open(&repo)?
|
||||||
.get(&patch_id.into())?
|
.get(&patch_id.into())?
|
||||||
.ok_or(Error::NotFound)?;
|
.ok_or(Error::NotFound)?;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,6 @@ use radicle::git::raw as git2;
|
||||||
use radicle::storage::ReadStorage;
|
use radicle::storage::ReadStorage;
|
||||||
use radicle_cli::commands::rad_init;
|
use radicle_cli::commands::rad_init;
|
||||||
use radicle_crypto::ssh::keystore::MemorySigner;
|
use radicle_crypto::ssh::keystore::MemorySigner;
|
||||||
use radicle_crypto::Signer;
|
|
||||||
|
|
||||||
use crate::api::{auth, Context};
|
use crate::api::{auth, Context};
|
||||||
|
|
||||||
|
|
@ -110,7 +109,7 @@ pub fn seed(dir: &Path) -> Context {
|
||||||
let storage = &profile.storage;
|
let storage = &profile.storage;
|
||||||
let (_, id) = radicle::rad::repo(&workdir).unwrap();
|
let (_, id) = radicle::rad::repo(&workdir).unwrap();
|
||||||
let repo = storage.repository(id).unwrap();
|
let repo = storage.repository(id).unwrap();
|
||||||
let mut issues = Issues::open(*signer.public_key(), &repo).unwrap();
|
let mut issues = Issues::open(&repo).unwrap();
|
||||||
issues
|
issues
|
||||||
.create(
|
.create(
|
||||||
"Issue #1".to_string(),
|
"Issue #1".to_string(),
|
||||||
|
|
@ -122,7 +121,7 @@ pub fn seed(dir: &Path) -> Context {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// eq. rad patch open
|
// eq. rad patch open
|
||||||
let mut patches = Patches::open(*signer.public_key(), &repo).unwrap();
|
let mut patches = Patches::open(&repo).unwrap();
|
||||||
let oid = radicle::git::Oid::from_str(HEAD).unwrap();
|
let oid = radicle::git::Oid::from_str(HEAD).unwrap();
|
||||||
let base = radicle::git::Oid::from_str(HEAD_1).unwrap();
|
let base = radicle::git::Oid::from_str(HEAD_1).unwrap();
|
||||||
patches
|
patches
|
||||||
|
|
|
||||||
|
|
@ -672,11 +672,8 @@ impl<'a> Deref for Proposals<'a> {
|
||||||
|
|
||||||
impl<'a> Proposals<'a> {
|
impl<'a> Proposals<'a> {
|
||||||
/// Open a proposals store.
|
/// Open a proposals store.
|
||||||
pub fn open(
|
pub fn open(repository: &'a storage::Repository) -> Result<Self, store::Error> {
|
||||||
whoami: PublicKey,
|
let raw = store::Store::open(repository)?;
|
||||||
repository: &'a storage::Repository,
|
|
||||||
) -> Result<Self, store::Error> {
|
|
||||||
let raw = store::Store::open(whoami, repository)?;
|
|
||||||
|
|
||||||
Ok(Self { raw })
|
Ok(Self { raw })
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ use crate::cob::store::Transaction;
|
||||||
use crate::cob::thread;
|
use crate::cob::thread;
|
||||||
use crate::cob::thread::{CommentId, Thread};
|
use crate::cob::thread::{CommentId, Thread};
|
||||||
use crate::cob::{store, ActorId, ObjectId, OpId, TypeName};
|
use crate::cob::{store, ActorId, ObjectId, OpId, TypeName};
|
||||||
use crate::crypto::{PublicKey, Signer};
|
use crate::crypto::Signer;
|
||||||
use crate::prelude::Did;
|
use crate::prelude::Did;
|
||||||
use crate::storage::git as storage;
|
use crate::storage::git as storage;
|
||||||
|
|
||||||
|
|
@ -416,11 +416,8 @@ pub struct IssueCounts {
|
||||||
|
|
||||||
impl<'a> Issues<'a> {
|
impl<'a> Issues<'a> {
|
||||||
/// Open an issues store.
|
/// Open an issues store.
|
||||||
pub fn open(
|
pub fn open(repository: &'a storage::Repository) -> Result<Self, store::Error> {
|
||||||
whoami: PublicKey,
|
let raw = store::Store::open(repository)?;
|
||||||
repository: &'a storage::Repository,
|
|
||||||
) -> Result<Self, store::Error> {
|
|
||||||
let raw = store::Store::open(whoami, repository)?;
|
|
||||||
|
|
||||||
Ok(Self { raw })
|
Ok(Self { raw })
|
||||||
}
|
}
|
||||||
|
|
@ -549,7 +546,7 @@ mod test {
|
||||||
fn test_issue_create_and_assign() {
|
fn test_issue_create_and_assign() {
|
||||||
let tmp = tempfile::tempdir().unwrap();
|
let tmp = tempfile::tempdir().unwrap();
|
||||||
let (_, signer, project) = test::setup::context(&tmp);
|
let (_, signer, project) = test::setup::context(&tmp);
|
||||||
let mut issues = Issues::open(*signer.public_key(), &project).unwrap();
|
let mut issues = Issues::open(&project).unwrap();
|
||||||
|
|
||||||
let assignee: ActorId = arbitrary::gen(1);
|
let assignee: ActorId = arbitrary::gen(1);
|
||||||
let assignee_two: ActorId = arbitrary::gen(1);
|
let assignee_two: ActorId = arbitrary::gen(1);
|
||||||
|
|
@ -586,7 +583,7 @@ mod test {
|
||||||
fn test_issue_create_and_reassign() {
|
fn test_issue_create_and_reassign() {
|
||||||
let tmp = tempfile::tempdir().unwrap();
|
let tmp = tempfile::tempdir().unwrap();
|
||||||
let (_, signer, project) = test::setup::context(&tmp);
|
let (_, signer, project) = test::setup::context(&tmp);
|
||||||
let mut issues = Issues::open(*signer.public_key(), &project).unwrap();
|
let mut issues = Issues::open(&project).unwrap();
|
||||||
|
|
||||||
let assignee: ActorId = arbitrary::gen(1);
|
let assignee: ActorId = arbitrary::gen(1);
|
||||||
let assignee_two: ActorId = arbitrary::gen(1);
|
let assignee_two: ActorId = arbitrary::gen(1);
|
||||||
|
|
@ -616,7 +613,7 @@ mod test {
|
||||||
fn test_issue_create_and_get() {
|
fn test_issue_create_and_get() {
|
||||||
let tmp = tempfile::tempdir().unwrap();
|
let tmp = tempfile::tempdir().unwrap();
|
||||||
let (_, signer, project) = test::setup::context(&tmp);
|
let (_, signer, project) = test::setup::context(&tmp);
|
||||||
let mut issues = Issues::open(*signer.public_key(), &project).unwrap();
|
let mut issues = Issues::open(&project).unwrap();
|
||||||
let created = issues
|
let created = issues
|
||||||
.create("My first issue", "Blah blah blah.", &[], &[], &signer)
|
.create("My first issue", "Blah blah blah.", &[], &[], &signer)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
@ -628,7 +625,7 @@ mod test {
|
||||||
|
|
||||||
assert_eq!(created, issue);
|
assert_eq!(created, issue);
|
||||||
assert_eq!(issue.title(), "My first issue");
|
assert_eq!(issue.title(), "My first issue");
|
||||||
assert_eq!(issue.author(), issues.author());
|
assert_eq!(issue.author().id, Did::from(signer.public_key()));
|
||||||
assert_eq!(issue.description(), Some("Blah blah blah."));
|
assert_eq!(issue.description(), Some("Blah blah blah."));
|
||||||
assert_eq!(issue.comments().count(), 1);
|
assert_eq!(issue.comments().count(), 1);
|
||||||
assert_eq!(issue.state(), &State::Open);
|
assert_eq!(issue.state(), &State::Open);
|
||||||
|
|
@ -638,7 +635,7 @@ mod test {
|
||||||
fn test_issue_create_and_change_state() {
|
fn test_issue_create_and_change_state() {
|
||||||
let tmp = tempfile::tempdir().unwrap();
|
let tmp = tempfile::tempdir().unwrap();
|
||||||
let (_, signer, project) = test::setup::context(&tmp);
|
let (_, signer, project) = test::setup::context(&tmp);
|
||||||
let mut issues = Issues::open(*signer.public_key(), &project).unwrap();
|
let mut issues = Issues::open(&project).unwrap();
|
||||||
let mut issue = issues
|
let mut issue = issues
|
||||||
.create("My first issue", "Blah blah blah.", &[], &[], &signer)
|
.create("My first issue", "Blah blah blah.", &[], &[], &signer)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
@ -672,7 +669,7 @@ mod test {
|
||||||
fn test_issue_create_and_unassign() {
|
fn test_issue_create_and_unassign() {
|
||||||
let tmp = tempfile::tempdir().unwrap();
|
let tmp = tempfile::tempdir().unwrap();
|
||||||
let (_, signer, project) = test::setup::context(&tmp);
|
let (_, signer, project) = test::setup::context(&tmp);
|
||||||
let mut issues = Issues::open(*signer.public_key(), &project).unwrap();
|
let mut issues = Issues::open(&project).unwrap();
|
||||||
|
|
||||||
let assignee: ActorId = arbitrary::gen(1);
|
let assignee: ActorId = arbitrary::gen(1);
|
||||||
let assignee_two: ActorId = arbitrary::gen(1);
|
let assignee_two: ActorId = arbitrary::gen(1);
|
||||||
|
|
@ -700,7 +697,7 @@ mod test {
|
||||||
fn test_issue_edit_title() {
|
fn test_issue_edit_title() {
|
||||||
let tmp = tempfile::tempdir().unwrap();
|
let tmp = tempfile::tempdir().unwrap();
|
||||||
let (_, signer, project) = test::setup::context(&tmp);
|
let (_, signer, project) = test::setup::context(&tmp);
|
||||||
let mut issues = Issues::open(*signer.public_key(), &project).unwrap();
|
let mut issues = Issues::open(&project).unwrap();
|
||||||
let mut issue = issues
|
let mut issue = issues
|
||||||
.create("My first issue", "Blah blah blah.", &[], &[], &signer)
|
.create("My first issue", "Blah blah blah.", &[], &[], &signer)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
@ -718,7 +715,7 @@ mod test {
|
||||||
fn test_issue_react() {
|
fn test_issue_react() {
|
||||||
let tmp = tempfile::tempdir().unwrap();
|
let tmp = tempfile::tempdir().unwrap();
|
||||||
let (_, signer, project) = test::setup::context(&tmp);
|
let (_, signer, project) = test::setup::context(&tmp);
|
||||||
let mut issues = Issues::open(*signer.public_key(), &project).unwrap();
|
let mut issues = Issues::open(&project).unwrap();
|
||||||
let mut issue = issues
|
let mut issue = issues
|
||||||
.create("My first issue", "Blah blah blah.", &[], &[], &signer)
|
.create("My first issue", "Blah blah blah.", &[], &[], &signer)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
@ -741,7 +738,7 @@ mod test {
|
||||||
fn test_issue_reply() {
|
fn test_issue_reply() {
|
||||||
let tmp = tempfile::tempdir().unwrap();
|
let tmp = tempfile::tempdir().unwrap();
|
||||||
let (_, signer, project) = test::setup::context(&tmp);
|
let (_, signer, project) = test::setup::context(&tmp);
|
||||||
let mut issues = Issues::open(*signer.public_key(), &project).unwrap();
|
let mut issues = Issues::open(&project).unwrap();
|
||||||
let mut issue = issues
|
let mut issue = issues
|
||||||
.create("My first issue", "Blah blah blah.", &[], &[], &signer)
|
.create("My first issue", "Blah blah blah.", &[], &[], &signer)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
@ -779,7 +776,7 @@ mod test {
|
||||||
fn test_issue_tag() {
|
fn test_issue_tag() {
|
||||||
let tmp = tempfile::tempdir().unwrap();
|
let tmp = tempfile::tempdir().unwrap();
|
||||||
let (_, signer, project) = test::setup::context(&tmp);
|
let (_, signer, project) = test::setup::context(&tmp);
|
||||||
let mut issues = Issues::open(*signer.public_key(), &project).unwrap();
|
let mut issues = Issues::open(&project).unwrap();
|
||||||
let bug_tag = Tag::new("bug").unwrap();
|
let bug_tag = Tag::new("bug").unwrap();
|
||||||
let ux_tag = Tag::new("ux").unwrap();
|
let ux_tag = Tag::new("ux").unwrap();
|
||||||
let wontfix_tag = Tag::new("wontfix").unwrap();
|
let wontfix_tag = Tag::new("wontfix").unwrap();
|
||||||
|
|
@ -810,7 +807,7 @@ mod test {
|
||||||
let tmp = tempfile::tempdir().unwrap();
|
let tmp = tempfile::tempdir().unwrap();
|
||||||
let (_, signer, project) = test::setup::context(&tmp);
|
let (_, signer, project) = test::setup::context(&tmp);
|
||||||
let author = *signer.public_key();
|
let author = *signer.public_key();
|
||||||
let mut issues = Issues::open(*signer.public_key(), &project).unwrap();
|
let mut issues = Issues::open(&project).unwrap();
|
||||||
let mut issue = issues
|
let mut issue = issues
|
||||||
.create("My first issue", "Blah blah blah.", &[], &[], &signer)
|
.create("My first issue", "Blah blah blah.", &[], &[], &signer)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
@ -856,7 +853,7 @@ mod test {
|
||||||
fn test_issue_all() {
|
fn test_issue_all() {
|
||||||
let tmp = tempfile::tempdir().unwrap();
|
let tmp = tempfile::tempdir().unwrap();
|
||||||
let (_, signer, project) = test::setup::context(&tmp);
|
let (_, signer, project) = test::setup::context(&tmp);
|
||||||
let mut issues = Issues::open(*signer.public_key(), &project).unwrap();
|
let mut issues = Issues::open(&project).unwrap();
|
||||||
|
|
||||||
issues.create("First", "Blah", &[], &[], &signer).unwrap();
|
issues.create("First", "Blah", &[], &[], &signer).unwrap();
|
||||||
issues.create("Second", "Blah", &[], &[], &signer).unwrap();
|
issues.create("Second", "Blah", &[], &[], &signer).unwrap();
|
||||||
|
|
@ -880,7 +877,7 @@ mod test {
|
||||||
fn test_issue_multilines() {
|
fn test_issue_multilines() {
|
||||||
let tmp = tempfile::tempdir().unwrap();
|
let tmp = tempfile::tempdir().unwrap();
|
||||||
let (_, signer, project) = test::setup::context(&tmp);
|
let (_, signer, project) = test::setup::context(&tmp);
|
||||||
let mut issues = Issues::open(*signer.public_key(), &project).unwrap();
|
let mut issues = Issues::open(&project).unwrap();
|
||||||
let created = issues
|
let created = issues
|
||||||
.create(
|
.create(
|
||||||
"My first issue",
|
"My first issue",
|
||||||
|
|
@ -898,7 +895,7 @@ mod test {
|
||||||
|
|
||||||
assert_eq!(created, issue);
|
assert_eq!(created, issue);
|
||||||
assert_eq!(issue.title(), "My first issue");
|
assert_eq!(issue.title(), "My first issue");
|
||||||
assert_eq!(issue.author(), issues.author());
|
assert_eq!(issue.author().id, Did::from(signer.public_key()));
|
||||||
assert_eq!(issue.description(), Some("Blah blah blah.\nYah yah yah"));
|
assert_eq!(issue.description(), Some("Blah blah blah.\nYah yah yah"));
|
||||||
assert_eq!(issue.comments().count(), 1);
|
assert_eq!(issue.comments().count(), 1);
|
||||||
assert_eq!(issue.state(), &State::Open);
|
assert_eq!(issue.state(), &State::Open);
|
||||||
|
|
|
||||||
|
|
@ -797,11 +797,8 @@ impl<'a> Deref for Patches<'a> {
|
||||||
|
|
||||||
impl<'a> Patches<'a> {
|
impl<'a> Patches<'a> {
|
||||||
/// Open an patches store.
|
/// Open an patches store.
|
||||||
pub fn open(
|
pub fn open(repository: &'a storage::Repository) -> Result<Self, store::Error> {
|
||||||
whoami: PublicKey,
|
let raw = store::Store::open(repository)?;
|
||||||
repository: &'a storage::Repository,
|
|
||||||
) -> Result<Self, store::Error> {
|
|
||||||
let raw = store::Store::open(whoami, repository)?;
|
|
||||||
|
|
||||||
Ok(Self { raw })
|
Ok(Self { raw })
|
||||||
}
|
}
|
||||||
|
|
@ -1071,7 +1068,7 @@ mod test {
|
||||||
fn test_patch_create_and_get() {
|
fn test_patch_create_and_get() {
|
||||||
let tmp = tempfile::tempdir().unwrap();
|
let tmp = tempfile::tempdir().unwrap();
|
||||||
let (_, signer, project) = test::setup::context(&tmp);
|
let (_, signer, project) = test::setup::context(&tmp);
|
||||||
let mut patches = Patches::open(*signer.public_key(), &project).unwrap();
|
let mut patches = Patches::open(&project).unwrap();
|
||||||
let author: Did = signer.public_key().into();
|
let author: Did = signer.public_key().into();
|
||||||
let target = MergeTarget::Delegates;
|
let target = MergeTarget::Delegates;
|
||||||
let oid = git::Oid::from_str("e2a85016a458cd809c0ecee81f8c99613b0b0945").unwrap();
|
let oid = git::Oid::from_str("e2a85016a458cd809c0ecee81f8c99613b0b0945").unwrap();
|
||||||
|
|
@ -1113,7 +1110,7 @@ mod test {
|
||||||
fn test_patch_discussion() {
|
fn test_patch_discussion() {
|
||||||
let tmp = tempfile::tempdir().unwrap();
|
let tmp = tempfile::tempdir().unwrap();
|
||||||
let (_, signer, project) = test::setup::context(&tmp);
|
let (_, signer, project) = test::setup::context(&tmp);
|
||||||
let mut patches = Patches::open(*signer.public_key(), &project).unwrap();
|
let mut patches = Patches::open(&project).unwrap();
|
||||||
let patch = patches
|
let patch = patches
|
||||||
.create(
|
.create(
|
||||||
"My first patch",
|
"My first patch",
|
||||||
|
|
@ -1147,7 +1144,7 @@ mod test {
|
||||||
let (_, signer, project) = test::setup::context(&tmp);
|
let (_, signer, project) = test::setup::context(&tmp);
|
||||||
let oid = git::Oid::from_str("e2a85016a458cd809c0ecee81f8c99613b0b0945").unwrap();
|
let oid = git::Oid::from_str("e2a85016a458cd809c0ecee81f8c99613b0b0945").unwrap();
|
||||||
let base = git::Oid::from_str("cb18e95ada2bb38aadd8e6cef0963ce37a87add3").unwrap();
|
let base = git::Oid::from_str("cb18e95ada2bb38aadd8e6cef0963ce37a87add3").unwrap();
|
||||||
let mut patches = Patches::open(*signer.public_key(), &project).unwrap();
|
let mut patches = Patches::open(&project).unwrap();
|
||||||
let mut patch = patches
|
let mut patch = patches
|
||||||
.create(
|
.create(
|
||||||
"My first patch",
|
"My first patch",
|
||||||
|
|
@ -1181,7 +1178,7 @@ mod test {
|
||||||
let (_, signer, project) = test::setup::context(&tmp);
|
let (_, signer, project) = test::setup::context(&tmp);
|
||||||
let base = git::Oid::from_str("cb18e95ada2bb38aadd8e6cef0963ce37a87add3").unwrap();
|
let base = git::Oid::from_str("cb18e95ada2bb38aadd8e6cef0963ce37a87add3").unwrap();
|
||||||
let oid = git::Oid::from_str("518d5069f94c03427f694bb494ac1cd7d1339380").unwrap();
|
let oid = git::Oid::from_str("518d5069f94c03427f694bb494ac1cd7d1339380").unwrap();
|
||||||
let mut patches = Patches::open(*signer.public_key(), &project).unwrap();
|
let mut patches = Patches::open(&project).unwrap();
|
||||||
let mut patch = patches
|
let mut patch = patches
|
||||||
.create(
|
.create(
|
||||||
"My first patch",
|
"My first patch",
|
||||||
|
|
@ -1300,7 +1297,7 @@ mod test {
|
||||||
let (_, signer, project) = test::setup::context(&tmp);
|
let (_, signer, project) = test::setup::context(&tmp);
|
||||||
let base = git::Oid::from_str("cb18e95ada2bb38aadd8e6cef0963ce37a87add3").unwrap();
|
let base = git::Oid::from_str("cb18e95ada2bb38aadd8e6cef0963ce37a87add3").unwrap();
|
||||||
let oid = git::Oid::from_str("518d5069f94c03427f694bb494ac1cd7d1339380").unwrap();
|
let oid = git::Oid::from_str("518d5069f94c03427f694bb494ac1cd7d1339380").unwrap();
|
||||||
let mut patches = Patches::open(*signer.public_key(), &project).unwrap();
|
let mut patches = Patches::open(&project).unwrap();
|
||||||
let mut patch = patches
|
let mut patch = patches
|
||||||
.create(
|
.create(
|
||||||
"My first patch",
|
"My first patch",
|
||||||
|
|
@ -1354,7 +1351,7 @@ mod test {
|
||||||
let base = git::Oid::from_str("af08e95ada2bb38aadd8e6cef0963ce37a87add3").unwrap();
|
let base = git::Oid::from_str("af08e95ada2bb38aadd8e6cef0963ce37a87add3").unwrap();
|
||||||
let rev0_oid = git::Oid::from_str("518d5069f94c03427f694bb494ac1cd7d1339380").unwrap();
|
let rev0_oid = git::Oid::from_str("518d5069f94c03427f694bb494ac1cd7d1339380").unwrap();
|
||||||
let rev1_oid = git::Oid::from_str("cb18e95ada2bb38aadd8e6cef0963ce37a87add3").unwrap();
|
let rev1_oid = git::Oid::from_str("cb18e95ada2bb38aadd8e6cef0963ce37a87add3").unwrap();
|
||||||
let mut patches = Patches::open(*signer.public_key(), &project).unwrap();
|
let mut patches = Patches::open(&project).unwrap();
|
||||||
let mut patch = patches
|
let mut patch = patches
|
||||||
.create(
|
.create(
|
||||||
"My first patch",
|
"My first patch",
|
||||||
|
|
|
||||||
|
|
@ -10,11 +10,9 @@ use rand::rngs::StdRng;
|
||||||
use rand::{RngCore as _, SeedableRng};
|
use rand::{RngCore as _, SeedableRng};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::cob::common::Author;
|
|
||||||
use crate::cob::op::{Nonce, Op, OpId, Ops};
|
use crate::cob::op::{Nonce, Op, OpId, Ops};
|
||||||
use crate::cob::CollaborativeObject;
|
use crate::cob::CollaborativeObject;
|
||||||
use crate::cob::{ActorId, Create, History, ObjectId, TypeName, Update};
|
use crate::cob::{ActorId, Create, History, ObjectId, TypeName, Update};
|
||||||
use crate::crypto::PublicKey;
|
|
||||||
use crate::git;
|
use crate::git;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use crate::storage::git as storage;
|
use crate::storage::git as storage;
|
||||||
|
|
@ -90,7 +88,6 @@ pub enum Error {
|
||||||
|
|
||||||
/// Storage for collaborative objects of a specific type `T` in a single repository.
|
/// Storage for collaborative objects of a specific type `T` in a single repository.
|
||||||
pub struct Store<'a, T> {
|
pub struct Store<'a, T> {
|
||||||
whoami: PublicKey,
|
|
||||||
parent: git::Oid,
|
parent: git::Oid,
|
||||||
repo: &'a storage::Repository,
|
repo: &'a storage::Repository,
|
||||||
witness: PhantomData<T>,
|
witness: PhantomData<T>,
|
||||||
|
|
@ -105,29 +102,18 @@ impl<'a, T> AsRef<storage::Repository> for Store<'a, T> {
|
||||||
|
|
||||||
impl<'a, T> Store<'a, T> {
|
impl<'a, T> Store<'a, T> {
|
||||||
/// Open a new generic store.
|
/// Open a new generic store.
|
||||||
pub fn open(whoami: PublicKey, repo: &'a storage::Repository) -> Result<Self, Error> {
|
pub fn open(repo: &'a storage::Repository) -> Result<Self, Error> {
|
||||||
let rng = rng::std();
|
let rng = rng::std();
|
||||||
let identity = repo.identity()?;
|
let identity = repo.identity()?;
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
parent: identity.current,
|
parent: identity.current,
|
||||||
whoami,
|
|
||||||
repo,
|
repo,
|
||||||
witness: PhantomData,
|
witness: PhantomData,
|
||||||
rng,
|
rng,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get this store's author.
|
|
||||||
pub fn author(&self) -> Author {
|
|
||||||
Author::new(self.whoami)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get the public key associated with this store.
|
|
||||||
pub fn public_key(&self) -> &PublicKey {
|
|
||||||
&self.whoami
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Derive a new RNG from the existing one.
|
/// Derive a new RNG from the existing one.
|
||||||
pub fn rng(&self) -> StdRng {
|
pub fn rng(&self) -> StdRng {
|
||||||
StdRng::from_rng(self.rng.clone()).expect("Store::rng: failed to derive RNG")
|
StdRng::from_rng(self.rng.clone()).expect("Store::rng: failed to derive RNG")
|
||||||
|
|
@ -230,7 +216,7 @@ where
|
||||||
|
|
||||||
/// Remove an object.
|
/// Remove an object.
|
||||||
pub fn remove<G: Signer>(&self, id: &ObjectId, signer: &G) -> Result<(), Error> {
|
pub fn remove<G: Signer>(&self, id: &ObjectId, signer: &G) -> Result<(), Error> {
|
||||||
cob::remove(self.repo, &self.whoami, T::type_name(), id)?;
|
cob::remove(self.repo, signer.public_key(), T::type_name(), id)?;
|
||||||
self.repo.sign_refs(signer).map_err(Error::SignRefs)?;
|
self.repo.sign_refs(signer).map_err(Error::SignRefs)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue