upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src/git/handlers.rs
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2025-12-03 08:54:00 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2025-12-03 08:54:00 +0000
commit2f8ecd482077d82f2d1a937c7f979eaaa87a27b2 (patch)
treecd892cde6ef6fd7ff654377946cab5b95339276f /src/git/handlers.rs
parent62a3855cb96616caf704a0f112fb2ade99fb8b45 (diff)
feat: implement LMDB database backend
- Add nostr-lmdb dependency (v0.44) for persistent storage - Create SharedDatabase type alias for database abstraction - Update all database-related functions to use trait object - Support runtime selection via NGIT_DATABASE_BACKEND env var Database backends: - memory: In-memory (default, fastest, no persistence) - lmdb: LMDB backend (persistent, general purpose) All 34 tests pass with the new implementation.
Diffstat (limited to 'src/git/handlers.rs')
-rw-r--r--src/git/handlers.rs7
1 files changed, 3 insertions, 4 deletions
diff --git a/src/git/handlers.rs b/src/git/handlers.rs
index e84cabb..8e5f5e1 100644
--- a/src/git/handlers.rs
+++ b/src/git/handlers.rs
@@ -4,9 +4,7 @@
4 4
5use http_body_util::Full; 5use http_body_util::Full;
6use hyper::{body::Bytes, Response, StatusCode}; 6use hyper::{body::Bytes, Response, StatusCode};
7use nostr_relay_builder::prelude::MemoryDatabase;
8use std::path::PathBuf; 7use std::path::PathBuf;
9use std::sync::Arc;
10use tokio::io::{AsyncReadExt, AsyncWriteExt}; 8use tokio::io::{AsyncReadExt, AsyncWriteExt};
11use tracing::{debug, error, info, warn}; 9use tracing::{debug, error, info, warn};
12 10
@@ -18,6 +16,7 @@ use super::protocol::{GitService, PktLine};
18use super::subprocess::GitSubprocess; 16use super::subprocess::GitSubprocess;
19use super::try_set_head_if_available; 17use super::try_set_head_if_available;
20 18
19use crate::nostr::builder::SharedDatabase;
21use crate::nostr::events::RepositoryState; 20use crate::nostr::events::RepositoryState;
22 21
23/// Handle GET /info/refs?service=git-{upload,receive}-pack 22/// Handle GET /info/refs?service=git-{upload,receive}-pack
@@ -178,7 +177,7 @@ pub async fn handle_upload_pack(
178pub async fn handle_receive_pack( 177pub async fn handle_receive_pack(
179 repo_path: PathBuf, 178 repo_path: PathBuf,
180 request_body: Bytes, 179 request_body: Bytes,
181 database: Option<Arc<MemoryDatabase>>, 180 database: Option<SharedDatabase>,
182 identifier: &str, 181 identifier: &str,
183 owner_pubkey: &str, 182 owner_pubkey: &str,
184) -> Result<Response<Full<Bytes>>, GitError> { 183) -> Result<Response<Full<Bytes>>, GitError> {
@@ -310,7 +309,7 @@ pub async fn handle_receive_pack(
310/// 5. Validates that pushed refs match the state 309/// 5. Validates that pushed refs match the state
311/// 6. Validates refs/nostr/<event-id> has valid event id and if event exists, `c` tag matches ref 310/// 6. Validates refs/nostr/<event-id> has valid event id and if event exists, `c` tag matches ref
312async fn authorize_push( 311async fn authorize_push(
313 database: &Arc<MemoryDatabase>, 312 database: &SharedDatabase,
314 identifier: &str, 313 identifier: &str,
315 owner_pubkey: &str, 314 owner_pubkey: &str,
316 request_body: &Bytes, 315 request_body: &Bytes,