diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2025-12-01 14:31:32 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2025-12-01 15:22:38 +0000 |
| commit | d2ac69816567f092fe0d4661723bc43778cb481b (patch) | |
| tree | e8b51b61a6a7b0ab1a214adebe4e237143b01f0b /src/git | |
| parent | 7a78815e29b01c83f3d0ec195ba717a2eba8cd37 (diff) | |
fix cargo clippy and fmt warnings
Diffstat (limited to 'src/git')
| -rw-r--r-- | src/git/handlers.rs | 1 | ||||
| -rw-r--r-- | src/git/mod.rs | 13 | ||||
| -rw-r--r-- | src/git/protocol.rs | 18 | ||||
| -rw-r--r-- | src/git/subprocess.rs | 34 |
4 files changed, 30 insertions, 36 deletions
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 @@ | |||
| 5 | use http_body_util::Full; | 5 | use http_body_util::Full; |
| 6 | use hyper::{body::Bytes, Response, StatusCode}; | 6 | use hyper::{body::Bytes, Response, StatusCode}; |
| 7 | use nostr_relay_builder::prelude::MemoryDatabase; | 7 | use nostr_relay_builder::prelude::MemoryDatabase; |
| 8 | use nostr_sdk::EventId; | ||
| 9 | use std::path::PathBuf; | 8 | use std::path::PathBuf; |
| 10 | use std::sync::Arc; | 9 | use std::sync::Arc; |
| 11 | use tokio::io::{AsyncReadExt, AsyncWriteExt}; | 10 | 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)> { | |||
| 306 | let subpath = parts[2]; | 306 | let subpath = parts[2]; |
| 307 | 307 | ||
| 308 | // Extract identifier (remove .git suffix if present for the middle part) | 308 | // Extract identifier (remove .git suffix if present for the middle part) |
| 309 | let identifier = if repo_part.ends_with(".git") { | 309 | let identifier = repo_part.strip_suffix(".git").unwrap_or(repo_part); |
| 310 | &repo_part[..repo_part.len() - 4] | ||
| 311 | } else { | ||
| 312 | repo_part | ||
| 313 | }; | ||
| 314 | 310 | ||
| 315 | Some((npub, identifier, subpath)) | 311 | Some((npub, identifier, subpath)) |
| 316 | } | 312 | } |
| @@ -343,7 +339,12 @@ mod tests { | |||
| 343 | 339 | ||
| 344 | // Initialize bare repository | 340 | // Initialize bare repository |
| 345 | Command::new("git") | 341 | Command::new("git") |
| 346 | .args(["init", "--bare", "--initial-branch=main", bare_repo.to_str().unwrap()]) | 342 | .args([ |
| 343 | "init", | ||
| 344 | "--bare", | ||
| 345 | "--initial-branch=main", | ||
| 346 | bare_repo.to_str().unwrap(), | ||
| 347 | ]) | ||
| 347 | .output() | 348 | .output() |
| 348 | .unwrap(); | 349 | .unwrap(); |
| 349 | 350 | ||
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 { | |||
| 55 | return Err(ProtocolError::InsufficientData); | 55 | return Err(ProtocolError::InsufficientData); |
| 56 | } | 56 | } |
| 57 | 57 | ||
| 58 | let len_str = std::str::from_utf8(&input[0..4]) | 58 | let len_str = |
| 59 | .map_err(|_| ProtocolError::InvalidLength)?; | 59 | std::str::from_utf8(&input[0..4]).map_err(|_| ProtocolError::InvalidLength)?; |
| 60 | 60 | ||
| 61 | let len = u16::from_str_radix(len_str, 16) | 61 | let len = |
| 62 | .map_err(|_| ProtocolError::InvalidLength)? as usize; | 62 | u16::from_str_radix(len_str, 16).map_err(|_| ProtocolError::InvalidLength)? as usize; |
| 63 | 63 | ||
| 64 | if len == 0 { | 64 | if len == 0 { |
| 65 | // Flush packet | 65 | // Flush packet |
| @@ -81,19 +81,19 @@ impl PktLine { | |||
| 81 | /// Parse all pkt-lines from bytes | 81 | /// Parse all pkt-lines from bytes |
| 82 | pub fn parse_all(mut input: &[u8]) -> Result<Vec<Self>, ProtocolError> { | 82 | pub fn parse_all(mut input: &[u8]) -> Result<Vec<Self>, ProtocolError> { |
| 83 | let mut packets = Vec::new(); | 83 | let mut packets = Vec::new(); |
| 84 | 84 | ||
| 85 | while !input.is_empty() { | 85 | while !input.is_empty() { |
| 86 | let (packet, remaining) = Self::parse(input)?; | 86 | let (packet, remaining) = Self::parse(input)?; |
| 87 | let is_flush = matches!(packet, PktLine::Flush); | 87 | let is_flush = matches!(packet, PktLine::Flush); |
| 88 | packets.push(packet); | 88 | packets.push(packet); |
| 89 | input = remaining; | 89 | input = remaining; |
| 90 | 90 | ||
| 91 | // Stop at flush packet | 91 | // Stop at flush packet |
| 92 | if is_flush { | 92 | if is_flush { |
| 93 | break; | 93 | break; |
| 94 | } | 94 | } |
| 95 | } | 95 | } |
| 96 | 96 | ||
| 97 | Ok(packets) | 97 | Ok(packets) |
| 98 | } | 98 | } |
| 99 | } | 99 | } |
| @@ -259,4 +259,4 @@ mod tests { | |||
| 259 | "application/x-git-upload-pack-result" | 259 | "application/x-git-upload-pack-result" |
| 260 | ); | 260 | ); |
| 261 | } | 261 | } |
| 262 | } \ No newline at end of file | 262 | } |
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 { | |||
| 28 | advertise: bool, | 28 | advertise: bool, |
| 29 | ) -> std::io::Result<Self> { | 29 | ) -> std::io::Result<Self> { |
| 30 | let repo_path = repo_path.as_ref(); | 30 | let repo_path = repo_path.as_ref(); |
| 31 | 31 | ||
| 32 | let mut cmd = Command::new("git"); | 32 | let mut cmd = Command::new("git"); |
| 33 | 33 | ||
| 34 | // GRASP-01 requirement: MUST include `allow-reachable-sha1-in-want` and | 34 | // GRASP-01 requirement: MUST include `allow-reachable-sha1-in-want` and |
| 35 | // `allow-tip-sha1-in-want` in advertisement and serve available oids. | 35 | // `allow-tip-sha1-in-want` in advertisement and serve available oids. |
| 36 | // These config options must be passed before the command name. | 36 | // These config options must be passed before the command name. |
| @@ -38,22 +38,22 @@ impl GitSubprocess { | |||
| 38 | cmd.arg("uploadpack.allowReachableSHA1InWant=true"); | 38 | cmd.arg("uploadpack.allowReachableSHA1InWant=true"); |
| 39 | cmd.arg("-c"); | 39 | cmd.arg("-c"); |
| 40 | cmd.arg("uploadpack.allowTipSHA1InWant=true"); | 40 | cmd.arg("uploadpack.allowTipSHA1InWant=true"); |
| 41 | 41 | ||
| 42 | cmd.arg(service.command_name()); | 42 | cmd.arg(service.command_name()); |
| 43 | 43 | ||
| 44 | if advertise { | 44 | if advertise { |
| 45 | cmd.arg("--advertise-refs"); | 45 | cmd.arg("--advertise-refs"); |
| 46 | } | 46 | } |
| 47 | 47 | ||
| 48 | cmd.arg("--stateless-rpc"); | 48 | cmd.arg("--stateless-rpc"); |
| 49 | cmd.arg(repo_path); | 49 | cmd.arg(repo_path); |
| 50 | 50 | ||
| 51 | cmd.stdin(Stdio::piped()); | 51 | cmd.stdin(Stdio::piped()); |
| 52 | cmd.stdout(Stdio::piped()); | 52 | cmd.stdout(Stdio::piped()); |
| 53 | cmd.stderr(Stdio::piped()); | 53 | cmd.stderr(Stdio::piped()); |
| 54 | 54 | ||
| 55 | let child = cmd.spawn()?; | 55 | let child = cmd.spawn()?; |
| 56 | 56 | ||
| 57 | Ok(Self { child }) | 57 | Ok(Self { child }) |
| 58 | } | 58 | } |
| 59 | 59 | ||
| @@ -101,8 +101,8 @@ impl GitSubprocess { | |||
| 101 | #[cfg(test)] | 101 | #[cfg(test)] |
| 102 | mod tests { | 102 | mod tests { |
| 103 | use super::*; | 103 | use super::*; |
| 104 | use tempfile::TempDir; | ||
| 105 | use std::process::Command as StdCommand; | 104 | use std::process::Command as StdCommand; |
| 105 | use tempfile::TempDir; | ||
| 106 | 106 | ||
| 107 | fn create_bare_repo() -> TempDir { | 107 | fn create_bare_repo() -> TempDir { |
| 108 | let dir = TempDir::new().unwrap(); | 108 | let dir = TempDir::new().unwrap(); |
| @@ -118,11 +118,8 @@ mod tests { | |||
| 118 | #[tokio::test] | 118 | #[tokio::test] |
| 119 | async fn test_spawn_upload_pack_advertise() { | 119 | async fn test_spawn_upload_pack_advertise() { |
| 120 | let repo = create_bare_repo(); | 120 | let repo = create_bare_repo(); |
| 121 | let mut proc = GitSubprocess::spawn( | 121 | let mut proc = GitSubprocess::spawn(GitService::UploadPack, repo.path(), true) |
| 122 | GitService::UploadPack, | 122 | .expect("Failed to spawn git"); |
| 123 | repo.path(), | ||
| 124 | true, | ||
| 125 | ).expect("Failed to spawn git"); | ||
| 126 | 123 | ||
| 127 | // Should have spawned successfully | 124 | // Should have spawned successfully |
| 128 | assert!(proc.stdout().is_some()); | 125 | assert!(proc.stdout().is_some()); |
| @@ -135,15 +132,12 @@ mod tests { | |||
| 135 | #[tokio::test] | 132 | #[tokio::test] |
| 136 | async fn test_spawn_receive_pack() { | 133 | async fn test_spawn_receive_pack() { |
| 137 | let repo = create_bare_repo(); | 134 | let repo = create_bare_repo(); |
| 138 | let mut proc = GitSubprocess::spawn( | 135 | let mut proc = GitSubprocess::spawn(GitService::ReceivePack, repo.path(), false) |
| 139 | GitService::ReceivePack, | 136 | .expect("Failed to spawn git"); |
| 140 | repo.path(), | ||
| 141 | false, | ||
| 142 | ).expect("Failed to spawn git"); | ||
| 143 | 137 | ||
| 144 | assert!(proc.stdout().is_some()); | 138 | assert!(proc.stdout().is_some()); |
| 145 | assert!(proc.stdin().is_some()); | 139 | assert!(proc.stdin().is_some()); |
| 146 | 140 | ||
| 147 | let _ = proc.kill().await; | 141 | let _ = proc.kill().await; |
| 148 | } | 142 | } |
| 149 | } \ No newline at end of file | 143 | } |