mirror of
https://relay.ngit.dev/npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr/ngit-grasp.git
synced 2026-10-05 23:18:24 +00:00
Adds the `/prs/<npub>/<identifier>.git/*` URL space behind the existing
`NGIT_GRASP06_ENABLE` flag. Fetches synthesise an empty bare repo per
request (via `git init --bare` in a tempdir) when no real repo exists
on disk; if a real repo exists at `<git_data_path>/prs/<hex>/<id>.git`
it delegates to the standard `handle_info_refs` / `handle_upload_pack`.
The receive-pack endpoint is a deliberate stub that returns HTTP 200
with an ERR pkt-line ("GRASP-06 receive-pack not yet implemented"),
matching `build_git_protocol_error_response`'s shape so git clients
print the message and exit non-zero rather than seeing a 404. The real
receive-pack handler is not yet implemented.
Module layout under `src/grasp06/`:
paths.rs — PRS_URL_PREFIX, PRS_DISK_PREFIX, prs_repo_path,
prs_base_path, is_prs_repo_path (hex on disk).
endpoint.rs — PrsUrl + parse_prs_url (npub-only, percent-decoded id).
fetch.rs — handle_prs_info_refs, handle_prs_upload_pack, and the
receive-pack stub.
Routing is wired into HttpService::call ahead of `parse_git_url` so
`/prs/...` paths can't be misclassified as standard owner repos. When
the flag is off the branch is skipped and `/prs/*` falls through to
the existing 404 path (preserving the discovery-gate contract).
Tests flipped green:
- prs_fetch_unknown_path_serves_empty_repo_with_grasp_06
- prs_push_other_refs_rejected_with_grasp_06 (ERR pkt-line)
- standard_push_does_not_mirror_to_prs_with_grasp_06
Tests still green (no regression):
- prs_namespace_404_when_grasp06_not_advertised_no_grasp_06
- nip11_advertises_grasp_06_when_enabled
- pr_event_rejected_when_clone_tag_does_not_name_prs_endpoint_with_grasp_06
Tests still red (deferred):
- prs_push_refs_nostr_event_id_accepted_with_grasp_06
- pr_event_accepted_when_clone_tag_names_prs_endpoint_with_grasp_06
- prs_push_mirrors_to_announced_repo_with_grasp_06
`tempfile` is promoted from a dev-dependency to a runtime dependency
because the empty-repo synthesis path needs it. No new config options,
so the four-place config-sync contract is unaffected.
90 lines
3.0 KiB
Rust
90 lines
3.0 KiB
Rust
//! On-disk path conventions for the GRASP-06 `/prs/` endpoint.
|
|
//!
|
|
//! Repositories submitted via `/prs/<npub>/<identifier>.git` are stored
|
|
//! under a dedicated subtree of the git data directory so existing
|
|
//! subsystems (cleanup, sync, listings) can exclude them with a single
|
|
//! path-prefix check. The submitter pubkey is stored as **hex** on disk;
|
|
//! the identifier is stored verbatim (URL percent-decoding happens at
|
|
//! parse time in [`crate::grasp06::endpoint`]).
|
|
//!
|
|
//! ```text
|
|
//! <git_data_path>/
|
|
//! prs/ <-- PRS_DISK_PREFIX
|
|
//! <submitter-hex>/
|
|
//! <identifier>.git/
|
|
//! ```
|
|
|
|
use std::path::{Path, PathBuf};
|
|
|
|
/// URL prefix used in HTTP paths: `/prs/<npub>/<identifier>.git/...`.
|
|
pub const PRS_URL_PREFIX: &str = "prs";
|
|
|
|
/// Directory name used on disk under `<git_data_path>`. Kept identical to
|
|
/// `PRS_URL_PREFIX` so an operator scanning the filesystem can match the
|
|
/// URL space at a glance.
|
|
pub const PRS_DISK_PREFIX: &str = "prs";
|
|
|
|
/// Return the base directory under which all `/prs/` repos live.
|
|
pub fn prs_base_path(git_data_path: &Path) -> PathBuf {
|
|
git_data_path.join(PRS_DISK_PREFIX)
|
|
}
|
|
|
|
/// Build the on-disk path for `/prs/<npub>/<identifier>.git`.
|
|
///
|
|
/// `submitter_hex` is the 64-character lowercase hex of the submitter's
|
|
/// public key. `identifier` is the percent-decoded NIP-34 `d` value as
|
|
/// stored on disk (verbatim).
|
|
pub fn prs_repo_path(git_data_path: &Path, submitter_hex: &str, identifier: &str) -> PathBuf {
|
|
let identifier = identifier.strip_suffix(".git").unwrap_or(identifier);
|
|
prs_base_path(git_data_path)
|
|
.join(submitter_hex)
|
|
.join(format!("{}.git", identifier))
|
|
}
|
|
|
|
/// True if `path` is inside the `/prs/` subtree of `git_data_path`.
|
|
///
|
|
/// Used by future cleanup and sync subsystems to skip these repos —
|
|
/// they have their own lifecycle (zero-ref cleanup, no announcement
|
|
/// promotion) and must not be treated as standard owner repos.
|
|
pub fn is_prs_repo_path(path: &Path, git_data_path: &Path) -> bool {
|
|
path.starts_with(prs_base_path(git_data_path))
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn prs_base_path_appends_prs() {
|
|
assert_eq!(
|
|
prs_base_path(Path::new("/data/git")),
|
|
PathBuf::from("/data/git/prs")
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn prs_repo_path_uses_hex_pubkey() {
|
|
let p = prs_repo_path(Path::new("/data/git"), "deadbeef", "my-repo");
|
|
assert_eq!(p, PathBuf::from("/data/git/prs/deadbeef/my-repo.git"));
|
|
}
|
|
|
|
#[test]
|
|
fn prs_repo_path_strips_trailing_git() {
|
|
let p = prs_repo_path(Path::new("/data/git"), "deadbeef", "my-repo.git");
|
|
assert_eq!(p, PathBuf::from("/data/git/prs/deadbeef/my-repo.git"));
|
|
}
|
|
|
|
#[test]
|
|
fn is_prs_repo_path_detects_subtree() {
|
|
let root = Path::new("/data/git");
|
|
assert!(is_prs_repo_path(
|
|
&PathBuf::from("/data/git/prs/abc/repo.git"),
|
|
root
|
|
));
|
|
assert!(!is_prs_repo_path(
|
|
&PathBuf::from("/data/git/npub1xyz/repo.git"),
|
|
root
|
|
));
|
|
}
|
|
}
|