refactor
This commit is contained in:
@@ -7,7 +7,7 @@ use anyhow::{Context, Result, bail};
|
||||
use gix::diff::blob::unified_diff::{ConsumeHunk, DiffLineKind as GixLineKind, HunkHeader};
|
||||
use gix::interrupt::IS_INTERRUPTED;
|
||||
use gix::progress::Discard;
|
||||
use signed_core::RepoAddr;
|
||||
use signed_core::{Announcement, RepoAddr};
|
||||
|
||||
/// On-disk cache of cloned repositories, keyed by owner pubkey / repo id.
|
||||
#[derive(Debug, Clone)]
|
||||
@@ -1061,6 +1061,15 @@ pub fn sanitize_path_component(id: &str) -> String {
|
||||
sanitized
|
||||
}
|
||||
|
||||
/// The refs namespace of a fork's import in the target mirror.
|
||||
pub fn fork_namespace(announcement: &Announcement) -> String {
|
||||
format!(
|
||||
"{}/{}",
|
||||
announcement.owner.to_hex(),
|
||||
sanitize_path_component(&announcement.id)
|
||||
)
|
||||
}
|
||||
|
||||
/// In-memory object cache for history walks, see [`open_with_cache`].
|
||||
///
|
||||
/// Without one, a walk re-decodes the same commit objects from the object database.
|
||||
@@ -2378,6 +2387,21 @@ mod tests {
|
||||
assert_eq!(sanitize_path_component("a/../b"), "a_.._b");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fork_namespace_combines_owner_and_sanitized_id() {
|
||||
let keys = Keys::generate();
|
||||
let event = EventBuilder::new(Kind::GitRepoAnnouncement, "")
|
||||
.tags([Tag::parse(["d", "my/repo"]).expect("valid tag")])
|
||||
.finalize(&keys)
|
||||
.expect("signed event");
|
||||
let announcement = Announcement::from_event(&event).expect("parses");
|
||||
|
||||
assert_eq!(
|
||||
fork_namespace(&announcement),
|
||||
format!("{}/my_repo", keys.public_key().to_hex())
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn repo_path_stays_inside_root() {
|
||||
let cache = GitCache::new("/cache".into());
|
||||
|
||||
Reference in New Issue
Block a user