This commit is contained in:
2026-08-31 13:37:02 +07:00
parent 43ea3708d2
commit a2ef6bb1a3
8 changed files with 143 additions and 46 deletions
+1 -25
View File
@@ -10,7 +10,7 @@ use nostr::event::IntoEventBuilder;
use nostr_connect::prelude::*;
use nostr_sdk::client::SyncSummary;
use nostr_sdk::prelude::*;
use signed_core::{Announcement, build_state, filters, repo_addr};
use signed_core::{Announcement, build_state, filters, identifier_from_name, repo_addr};
use signed_nostr::{SignedAuthUrlHandler, UniversalSigner, Update};
use crate::git_store::GitStore;
@@ -1237,21 +1237,6 @@ fn with_master_key(uri: &str, keys: &Keys) -> String {
format!("{uri}{separator}master={nsec}")
}
/// Derive a repository identifier (d-tag) from the repo name, matching ngit
/// and gitworkshop: spaces become hyphens, other non-alphanumeric characters
/// (except `/`) become hyphens, case is preserved.
fn identifier_from_name(name: &str) -> String {
name.chars()
.map(|c| {
if c.is_ascii_alphanumeric() || c == '/' {
c
} else {
'-'
}
})
.collect()
}
/// A `https://<host>` (or `http://<host>` for `ws://` grasp servers, like
/// ngit) base URL for a grasp server. The repository then lives at
/// `{base}/{npub}/{repo-id}.git`.
@@ -1336,15 +1321,6 @@ fn extract_master_key(credential: &str) -> (&str, Keys) {
mod tests {
use super::*;
#[test]
fn identifier_from_name_slugs_like_gitworkshop() {
assert_eq!(identifier_from_name("My Repo"), "My-Repo");
assert_eq!(identifier_from_name("my-repo"), "my-repo");
assert_eq!(identifier_from_name("Foo_Bar!"), "Foo-Bar-");
assert_eq!(identifier_from_name("a/b"), "a/b");
assert_eq!(identifier_from_name("Café"), "Caf-");
}
#[test]
fn grasp_base_url_maps_schemes_like_ngit() {
let wss = RelayUrl::parse("wss://relay.ngit.dev").expect("url");
+16 -1
View File
@@ -1,4 +1,4 @@
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use std::sync::Arc;
use anyhow::Error;
@@ -52,6 +52,21 @@ impl LocalReposStore {
store
}
/// Forget a repository that has just been published to NIP-34, so it
/// leaves the local list immediately. A later rescan re-discovers it
/// from disk; the sidebar additionally hides published repositories by
/// identifier.
pub fn remove(&mut self, path: &Path, cx: &mut Context<Self>) {
self.repos = Arc::new(
self.repos
.iter()
.filter(|repo| repo.as_path() != path)
.cloned()
.collect(),
);
cx.notify();
}
/// Re-run the scan. Requests that arrive while a scan is running are
/// folded into one follow-up scan; the results replace the list atomically.
pub fn rescan(&mut self, cx: &mut Context<Self>) {