Radish alpha
h
rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5
Radicle Heartwood Protocol & Stack
Radicle
Git
cli: Don't use 'signer' where not necessary
Merged levitte opened 1 year ago

In the ‘clone’ command, a ‘signer’ is instanciated just to get the public key. In the ‘job’ command, a ‘signer’ is instanciated early, even when the subcommand doesn’t use it.

That’s unnecessary, and infers the potential use of RAD_PASSPHRASE. In those cases, avoid instanciating a ‘signer’.

2 files changed +7 -7 538648c5 9abedf44
modified radicle-cli/src/commands/clone.rs
@@ -133,7 +133,6 @@ impl Args for Options {

pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
    let profile = ctx.profile()?;
-
    let signer = term::signer(&profile)?;
    let mut node = radicle::Node::new(profile.socket());

    if !node.is_running() {
@@ -148,7 +147,6 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
        options.scope,
        options.sync.with_profile(&profile),
        &mut node,
-
        &signer,
        &profile,
    )?;
    let delegates = doc
@@ -229,16 +227,15 @@ pub enum CloneError {
    Fetch(#[from] sync::FetchError),
}

-
pub fn clone<G: Signer>(
+
pub fn clone(
    id: RepoId,
    directory: Option<PathBuf>,
    scope: Scope,
    settings: SyncSettings,
    node: &mut Node,
-
    signer: &G,
    profile: &Profile,
) -> Result<(raw::Repository, storage::git::Repository, Doc, Project), CloneError> {
-
    let me = *signer.public_key();
+
    let me = profile.id();

    // Seed repository.
    if node.seed(id, scope)? {
@@ -283,7 +280,7 @@ pub fn clone<G: Signer>(
        "Creating checkout in ./{}..",
        term::format::tertiary(path.display())
    ));
-
    let working = rad::checkout(id, &me, path, &profile.storage)?;
+
    let working = rad::checkout(id, me, path, &profile.storage)?;

    spinner.finish();

modified radicle-cli/src/commands/job.rs
@@ -205,7 +205,6 @@ impl Args for Options {

pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
    let profile = ctx.profile()?;
-
    let signer = term::signer(&profile)?;
    let (_, rid) = radicle::rad::cwd()?;
    let repo = profile.storage.repository_mut(rid)?;
    let announce = options.announce
@@ -222,6 +221,7 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {

    match options.op {
        Operation::Trigger { commit } => {
+
            let signer = term::signer(&profile)?;
            trigger(&commit, &mut ci_store, &repo, &signer, options.quiet)?;
        }
        Operation::Start {
@@ -229,6 +229,7 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
            run_id,
            info_url,
        } => {
+
            let signer = term::signer(&profile)?;
            start(&job_id, &run_id, info_url, &mut ci_store, &repo, &signer)?;
        }
        Operation::List => {
@@ -238,9 +239,11 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
            show(&job_id, &ci_store, &repo)?;
        }
        Operation::Finish { job_id, reason } => {
+
            let signer = term::signer(&profile)?;
            finish(&job_id, reason, &mut ci_store, &repo, &signer)?;
        }
        Operation::Delete { job_id } => {
+
            let signer = term::signer(&profile)?;
            let job_id = job_id.resolve(&repo.backend)?;
            ci_store.remove(&job_id, &signer)?;
        }