remote-helper: Make crate binary-only

This crate is not a library, i.e., it is not intended to be depended
upon by other crates. Rather, it implements the `git-remote-rad`
binary.

Reflect this by moving `lib.rs` to `main.rs`, merging it with
`git-remote-rad.rs`.
This commit is contained in:
Lorenz Leutgeb 2025-09-11 18:09:16 +02:00 committed by Fintan Halpenny
parent 66adbffd61
commit 897404164b
4 changed files with 51 additions and 50 deletions

View File

@ -11,7 +11,7 @@ rust-version.workspace = true
[[bin]]
name = "git-remote-rad"
path = "src/git-remote-rad.rs"
path = "src/main.rs"
[dependencies]
dunce = { workspace = true }

View File

@ -1,42 +0,0 @@
use std::env;
use std::process;
use radicle::version::Version;
pub const VERSION: Version = Version {
name: "git-remote-rad",
commit: env!("GIT_HEAD"),
version: env!("RADICLE_VERSION"),
timestamp: env!("SOURCE_DATE_EPOCH"),
};
fn main() {
let mut args = env::args();
if let Some(lvl) = radicle::logger::env_level() {
let logger = radicle::logger::StderrLogger::new(lvl);
log::set_boxed_logger(Box::new(logger))
.expect("no other logger should have been set already");
log::set_max_level(lvl.to_level_filter());
}
if args.nth(1).as_deref() == Some("--version") {
if let Err(e) = VERSION.write(std::io::stdout()) {
eprintln!("error: {e}");
process::exit(1);
};
process::exit(0);
}
let profile = match radicle::Profile::load() {
Ok(profile) => profile,
Err(err) => {
eprintln!("error: couldn't load profile: {err}");
process::exit(1);
}
};
if let Err(err) = radicle_remote_helper::run(profile) {
eprintln!("error: {err}");
process::exit(1);
}
}

View File

@ -1,13 +1,19 @@
#![warn(clippy::unwrap_used)]
//! The Radicle Git remote helper.
//! A Git remote helper for interacting with Radicle storage and notifying
//! `radicle-node`.
//!
//! Communication with the user is done via `stderr` (`eprintln`).
//! Communication with Git tooling is done via `stdout` (`println`).
//! Refer to <https://git-scm.com/docs/gitremote-helpers.html> for documentation
//! on Git remote helpers.
//!
//! Usage of standard streams:
//! - Standard Error ([`eprintln`]) is used for communicating with the user.
//! - Standard Output ([`println`]) is used for communicating with Git tooling.
mod fetch;
mod list;
mod push;
use std::path::PathBuf;
use std::process;
use std::str::FromStr;
use std::{env, fmt, io};
@ -16,11 +22,50 @@ use thiserror::Error;
use radicle::prelude::NodeId;
use radicle::storage::git::transport::local::{Url, UrlError};
use radicle::storage::{ReadRepository, WriteStorage};
use radicle::version::Version;
use radicle::{cob, profile};
use radicle::{git, storage, Profile};
use radicle_cli::git::Rev;
use radicle_cli::terminal as cli;
pub const VERSION: Version = Version {
name: "git-remote-rad",
commit: env!("GIT_HEAD"),
version: env!("RADICLE_VERSION"),
timestamp: env!("SOURCE_DATE_EPOCH"),
};
fn main() {
let mut args = env::args();
if let Some(lvl) = radicle::logger::env_level() {
let logger = radicle::logger::StderrLogger::new(lvl);
log::set_boxed_logger(Box::new(logger))
.expect("no other logger should have been set already");
log::set_max_level(lvl.to_level_filter());
}
if args.nth(1).as_deref() == Some("--version") {
if let Err(e) = VERSION.write(std::io::stdout()) {
eprintln!("error: {e}");
process::exit(1);
};
process::exit(0);
}
let profile = match radicle::Profile::load() {
Ok(profile) => profile,
Err(err) => {
eprintln!("error: couldn't load profile: {err}");
process::exit(1);
}
};
if let Err(err) = run(profile) {
eprintln!("error: {err}");
process::exit(1);
}
}
#[derive(Debug, Error)]
pub enum Error {
/// Failed to parse `base`.

View File

@ -27,7 +27,7 @@ where
/// Calculates the quorum of the [`git::canonical::Canonical`] provided.
///
/// In some cases, it ensures that the [`head`] is attempting to converge
/// In some cases, it ensures that the head commit is attempting to converge
/// with the set of commits of the other [`Did`]s.
///
/// If a quorum is found, then it is also ensured that the new [`head`] is a
@ -40,8 +40,6 @@ where
/// copy, and that checks that any two commits are related in the graph.
///
/// Ensures that the new head and the canonical commit do not diverge.
///
/// [`head`]: crate::push::canonical::Canonical::head
pub fn quorum(self) -> Result<(git::Qualified<'a>, canonical::Object), QuorumError> {
self.canonical
.quorum()