Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
remote-helper: wire in the GitService
Adrian Duke committed 2 months ago
commit 1663d29e1f1383c0cbbd1d276a0c20469c119fa2
parent 1414f84ff9644624ea7caf2c0ce150de1e84f5fd
2 files changed +14 -14
modified crates/radicle-remote-helper/src/fetch.rs
@@ -4,8 +4,8 @@ use std::{io, process::ExitStatus};
use thiserror::Error;

use radicle::git;
-
use radicle::storage::ReadRepository;

+
use crate::service::GitService;
use crate::{read_line, Verbosity};

#[derive(Debug, Error)]
@@ -33,9 +33,10 @@ pub enum Error {
}

/// Run a git fetch command.
-
pub fn run<R: ReadRepository>(
+
pub fn run<G: GitService>(
    mut refs: Vec<(git::Oid, git::fmt::RefString)>,
-
    stored: R,
+
    stored: radicle::storage::git::Repository,
+
    git: &G,
    stdin: &io::Stdin,
    verbosity: Verbosity,
) -> Result<(), Error> {
@@ -58,7 +59,7 @@ pub fn run<R: ReadRepository>(
    }

    // Verify them and prepare the final refspecs.
-
    let oids = refs.into_iter().map(|(oid, _)| oid);
+
    let oids = refs.into_iter().map(|(oid, _)| oid).collect();

    // Rely on the environment variable `GIT_DIR` pointing at the repository.
    let working = None;
@@ -72,7 +73,7 @@ pub fn run<R: ReadRepository>(
    // used in the working copy, this will always result in the object
    // missing. This seems to only be an issue with `libgit2`/`git2`
    // and not `git` itself.
-
    let output = git::process::fetch_pack(working, &stored, oids, verbosity.into())?;
+
    let output = git.fetch_pack(working, &stored, oids, verbosity.into())?;

    if !output.status.success() {
        return Err(Error::FetchPackFailed {
@@ -82,8 +83,5 @@ pub fn run<R: ReadRepository>(
        });
    }

-
    // Nb. An empty line means we're done.
-
    println!();
-

    Ok(())
}
modified crates/radicle-remote-helper/src/main.rs
@@ -19,6 +19,7 @@
mod fetch;
mod list;
mod push;
+
mod service;

use std::path::PathBuf;
use std::process;
@@ -241,6 +242,7 @@ pub fn run(profile: radicle::Profile) -> Result<(), Error> {
    let mut line = String::new();
    let mut opts = Options::default();
    let mut expected_refs = Vec::new();
+
    let git = service::RealGitService;

    if let Err(e) = radicle::io::set_file_limit(4096) {
        if debug {
@@ -290,12 +292,12 @@ pub fn run(profile: radicle::Profile) -> Result<(), Error> {
                let oid = git::Oid::from_str(oid)?;
                let refstr = git::fmt::RefString::try_from(*refstr)?;

-
                return Ok(fetch::run(
-
                    vec![(oid, refstr)],
-
                    stored,
-
                    &stdin,
-
                    opts.verbosity,
-
                )?);
+
                fetch::run(vec![(oid, refstr)], stored, &git, &stdin, opts.verbosity)?;
+

+
                // Nb. An empty line means we're done
+
                println!();
+

+
                return Ok(());
            }
            ["push", refspec] => {
                return Ok(push::run(