From d2ac69816567f092fe0d4661723bc43778cb481b Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Mon, 1 Dec 2025 14:31:32 +0000 Subject: fix cargo clippy and fmt warnings --- src/git/handlers.rs | 1 - src/git/mod.rs | 13 +++++++------ src/git/protocol.rs | 18 +++++++++--------- src/git/subprocess.rs | 34 ++++++++++++++-------------------- 4 files changed, 30 insertions(+), 36 deletions(-) (limited to 'src/git') diff --git a/src/git/handlers.rs b/src/git/handlers.rs index 00f2449..e84cabb 100644 --- a/src/git/handlers.rs +++ b/src/git/handlers.rs @@ -5,7 +5,6 @@ use http_body_util::Full; use hyper::{body::Bytes, Response, StatusCode}; use nostr_relay_builder::prelude::MemoryDatabase; -use nostr_sdk::EventId; use std::path::PathBuf; use std::sync::Arc; use tokio::io::{AsyncReadExt, AsyncWriteExt}; diff --git a/src/git/mod.rs b/src/git/mod.rs index 494f8b9..a783782 100644 --- a/src/git/mod.rs +++ b/src/git/mod.rs @@ -306,11 +306,7 @@ pub fn parse_git_url(path: &str) -> Option<(&str, &str, &str)> { let subpath = parts[2]; // Extract identifier (remove .git suffix if present for the middle part) - let identifier = if repo_part.ends_with(".git") { - &repo_part[..repo_part.len() - 4] - } else { - repo_part - }; + let identifier = repo_part.strip_suffix(".git").unwrap_or(repo_part); Some((npub, identifier, subpath)) } @@ -343,7 +339,12 @@ mod tests { // Initialize bare repository Command::new("git") - .args(["init", "--bare", "--initial-branch=main", bare_repo.to_str().unwrap()]) + .args([ + "init", + "--bare", + "--initial-branch=main", + bare_repo.to_str().unwrap(), + ]) .output() .unwrap(); diff --git a/src/git/protocol.rs b/src/git/protocol.rs index 93177de..8592c27 100644 --- a/src/git/protocol.rs +++ b/src/git/protocol.rs @@ -55,11 +55,11 @@ impl PktLine { return Err(ProtocolError::InsufficientData); } - let len_str = std::str::from_utf8(&input[0..4]) - .map_err(|_| ProtocolError::InvalidLength)?; - - let len = u16::from_str_radix(len_str, 16) - .map_err(|_| ProtocolError::InvalidLength)? as usize; + let len_str = + std::str::from_utf8(&input[0..4]).map_err(|_| ProtocolError::InvalidLength)?; + + let len = + u16::from_str_radix(len_str, 16).map_err(|_| ProtocolError::InvalidLength)? as usize; if len == 0 { // Flush packet @@ -81,19 +81,19 @@ impl PktLine { /// Parse all pkt-lines from bytes pub fn parse_all(mut input: &[u8]) -> Result, ProtocolError> { let mut packets = Vec::new(); - + while !input.is_empty() { let (packet, remaining) = Self::parse(input)?; let is_flush = matches!(packet, PktLine::Flush); packets.push(packet); input = remaining; - + // Stop at flush packet if is_flush { break; } } - + Ok(packets) } } @@ -259,4 +259,4 @@ mod tests { "application/x-git-upload-pack-result" ); } -} \ No newline at end of file +} diff --git a/src/git/subprocess.rs b/src/git/subprocess.rs index c95bce5..2d9a981 100644 --- a/src/git/subprocess.rs +++ b/src/git/subprocess.rs @@ -28,9 +28,9 @@ impl GitSubprocess { advertise: bool, ) -> std::io::Result { let repo_path = repo_path.as_ref(); - + let mut cmd = Command::new("git"); - + // GRASP-01 requirement: MUST include `allow-reachable-sha1-in-want` and // `allow-tip-sha1-in-want` in advertisement and serve available oids. // These config options must be passed before the command name. @@ -38,22 +38,22 @@ impl GitSubprocess { cmd.arg("uploadpack.allowReachableSHA1InWant=true"); cmd.arg("-c"); cmd.arg("uploadpack.allowTipSHA1InWant=true"); - + cmd.arg(service.command_name()); - + if advertise { cmd.arg("--advertise-refs"); } - + cmd.arg("--stateless-rpc"); cmd.arg(repo_path); - + cmd.stdin(Stdio::piped()); cmd.stdout(Stdio::piped()); cmd.stderr(Stdio::piped()); - + let child = cmd.spawn()?; - + Ok(Self { child }) } @@ -101,8 +101,8 @@ impl GitSubprocess { #[cfg(test)] mod tests { use super::*; - use tempfile::TempDir; use std::process::Command as StdCommand; + use tempfile::TempDir; fn create_bare_repo() -> TempDir { let dir = TempDir::new().unwrap(); @@ -118,11 +118,8 @@ mod tests { #[tokio::test] async fn test_spawn_upload_pack_advertise() { let repo = create_bare_repo(); - let mut proc = GitSubprocess::spawn( - GitService::UploadPack, - repo.path(), - true, - ).expect("Failed to spawn git"); + let mut proc = GitSubprocess::spawn(GitService::UploadPack, repo.path(), true) + .expect("Failed to spawn git"); // Should have spawned successfully assert!(proc.stdout().is_some()); @@ -135,15 +132,12 @@ mod tests { #[tokio::test] async fn test_spawn_receive_pack() { let repo = create_bare_repo(); - let mut proc = GitSubprocess::spawn( - GitService::ReceivePack, - repo.path(), - false, - ).expect("Failed to spawn git"); + let mut proc = GitSubprocess::spawn(GitService::ReceivePack, repo.path(), false) + .expect("Failed to spawn git"); assert!(proc.stdout().is_some()); assert!(proc.stdin().is_some()); let _ = proc.kill().await; } -} \ No newline at end of file +} -- cgit v1.2.3