Remove need to pass public key in cob store

This commit is contained in:
Alexis Sellier
2023-03-06 10:56:20 +01:00
parent 44f3984159
commit 8c22012d61
22 changed files with 69 additions and 93 deletions
+1 -3
View File
@@ -2,16 +2,14 @@ use crate::terminal as term;
use anyhow::anyhow;
use radicle::cob::patch::{self, PatchId};
use radicle::git::{self, RefString};
use radicle::profile::Profile;
use radicle::storage::git::Repository;
pub fn run(
storage: &Repository,
profile: &Profile,
git_workdir: &git::raw::Repository,
patch_id: &PatchId,
) -> anyhow::Result<()> {
let patches = patch::Patches::open(profile.public_key, storage)?;
let patches = patch::Patches::open(storage)?;
let patch = patches
.get(patch_id)?
.ok_or_else(|| anyhow!("Patch `{patch_id}` not found"))?;
+2 -1
View File
@@ -232,9 +232,10 @@ pub fn find_unmerged_with_base(
merge_base: Oid,
patches: &Patches,
workdir: &git::raw::Repository,
whoami: &Did,
) -> anyhow::Result<Vec<(PatchId, Patch, Clock)>> {
// 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();
for (id, patch, clock) in proposed {
+2 -2
View File
@@ -94,7 +94,7 @@ pub fn run(
message: term::patch::Message,
options: Options,
) -> 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!(
"couldn't load project {} from local state",
storage.id
@@ -117,7 +117,7 @@ pub fn run(
show_patch_commit_info(
&project,
workdir,
patches.public_key(),
profile.id(),
&head_branch,
&target_peer,
target_oid,
+2 -2
View File
@@ -18,7 +18,7 @@ pub fn run(
workdir: Option<git::raw::Repository>,
) -> anyhow::Result<()> {
let me = *profile.id();
let patches = Patches::open(*profile.id(), repository)?;
let patches = Patches::open(repository)?;
let proposed = patches.proposed()?;
// Patches the user authored.
@@ -56,7 +56,7 @@ pub fn run(
for (id, patch) in &mut other {
term::blank();
print(patches.public_key(), id, patch, &workdir, repository)?;
print(profile.id(), id, patch, &workdir, repository)?;
}
}
term::blank();
+3 -4
View File
@@ -1,12 +1,12 @@
use super::common::*;
use super::*;
use crate::terminal as term;
use radicle::cob::patch;
use radicle::git;
use radicle::prelude::*;
use radicle::storage::git::Repository;
use crate::terminal as term;
fn show_patch_diff(
patch: &patch::Patch,
storage: &Repository,
@@ -23,11 +23,10 @@ fn show_patch_diff(
pub fn run(
storage: &Repository,
profile: &Profile,
workdir: &git::raw::Repository,
patch_id: &PatchId,
) -> 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 {
anyhow::bail!("Patch `{patch_id}` not found");
};
+5 -3
View File
@@ -21,12 +21,14 @@ fn select_patch(
workdir: &git::raw::Repository,
head_branch: &git::raw::Branch,
target_oid: git::Oid,
whoami: &Did,
) -> anyhow::Result<patch::PatchId> {
let head_oid = branch_oid(head_branch)?;
let base_oid = workdir.merge_base(*target_oid, *head_oid)?;
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 {
spinner.failed();
@@ -103,11 +105,11 @@ pub fn run(
push_to_storage(storage, &head_branch, options)?;
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 {
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 {
anyhow::bail!("Patch `{patch_id}` not found");