upleb.uk

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

summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/bin/ngit/sub_commands/init.rs90
1 files changed, 12 insertions, 78 deletions
diff --git a/src/bin/ngit/sub_commands/init.rs b/src/bin/ngit/sub_commands/init.rs
index ab14cb9..95d7aae 100644
--- a/src/bin/ngit/sub_commands/init.rs
+++ b/src/bin/ngit/sub_commands/init.rs
@@ -12,7 +12,6 @@ use anyhow::{Context, Result, bail};
12use console::{Style, Term}; 12use console::{Style, Term};
13use git2::Oid; 13use git2::Oid;
14use ngit::{ 14use ngit::{
15 UrlWithoutSlash,
16 cli_interactor::{ 15 cli_interactor::{
17 PromptChoiceParms, PromptConfirmParms, cli_error, multi_select_with_custom_value, 16 PromptChoiceParms, PromptConfirmParms, cli_error, multi_select_with_custom_value,
18 show_multi_input_prompt_success, 17 show_multi_input_prompt_success,
@@ -109,10 +108,10 @@ struct ResolvedFields {
109 description: String, 108 description: String,
110 git_servers: Vec<String>, 109 git_servers: Vec<String>,
111 relays: Vec<RelayUrl>, 110 relays: Vec<RelayUrl>,
112 blossoms: Vec<Url>,
113 web: Vec<String>, 111 web: Vec<String>,
114 maintainers: Vec<PublicKey>, 112 maintainers: Vec<PublicKey>,
115 earliest_unique_commit: String, 113 earliest_unique_commit: String,
114 blossoms: Vec<Url>,
116 hashtags: Vec<String>, 115 hashtags: Vec<String>,
117 selected_grasp_servers: Vec<String>, 116 selected_grasp_servers: Vec<String>,
118} 117}
@@ -159,12 +158,6 @@ fn is_grasp_derived_relay(relay: &str, grasp_servers: &[String]) -> bool {
159 }) 158 })
160} 159}
161 160
162/// Check if a blossom URL corresponds to one of the given grasp servers.
163fn is_grasp_derived_blossom(blossom: &str, grasp_servers: &[String]) -> bool {
164 // Blossom URLs are https://{grasp_server} — same normalization as relays
165 is_grasp_derived_relay(blossom, grasp_servers)
166}
167
168fn dir_name_fallback() -> String { 161fn dir_name_fallback() -> String {
169 env::current_dir() 162 env::current_dir()
170 .ok() 163 .ok()
@@ -231,18 +224,16 @@ fn resolve_web(
231 vec![gitworkshop_url.to_string()] 224 vec![gitworkshop_url.to_string()]
232} 225}
233 226
234/// Derive clone-urls, relays, and blossoms from selected grasp servers. 227/// Derive clone-urls and relays from selected grasp servers.
235/// 228///
236/// For each grasp server, adds/replaces the corresponding clone URL in 229/// For each grasp server, adds/replaces the corresponding clone URL in
237/// `git_servers`, adds a relay URL to `relays`, and adds a blossom URL to 230/// `git_servers` and adds a relay URL to `relays`. Grasp-derived infrastructure
238/// `blossoms`. Grasp-derived infrastructure is always added — the other 231/// is always added — the other lists (`git_servers`, `relays`)
239/// lists (`git_servers`, `relays`, `blossoms`) contain *additional* 232/// contain *additional* infrastructure beyond what grasp servers provide.
240/// infrastructure beyond what grasp servers provide.
241fn apply_grasp_infrastructure( 233fn apply_grasp_infrastructure(
242 grasp_servers: &[String], 234 grasp_servers: &[String],
243 git_servers: &mut Vec<String>, 235 git_servers: &mut Vec<String>,
244 relays: &mut Vec<String>, 236 relays: &mut Vec<String>,
245 blossoms: &mut Vec<String>,
246 public_key: &PublicKey, 237 public_key: &PublicKey,
247 identifier: &str, 238 identifier: &str,
248) -> Result<()> { 239) -> Result<()> {
@@ -282,12 +273,6 @@ fn apply_grasp_infrastructure(
282 if !relays.contains(&relay_url) { 273 if !relays.contains(&relay_url) {
283 relays.push(relay_url); 274 relays.push(relay_url);
284 } 275 }
285
286 // Always add grasp-derived blossom
287 let blossom = format_grasp_server_url_as_blossom_url(grasp_server)?;
288 if !blossoms.contains(&blossom) {
289 blossoms.push(blossom);
290 }
291 } 276 }
292 Ok(()) 277 Ok(())
293} 278}
@@ -474,9 +459,6 @@ pub struct SubCommandArgs {
474 /// additional git server URLs beyond grasp servers 459 /// additional git server URLs beyond grasp servers
475 clone: Vec<String>, 460 clone: Vec<String>,
476 #[clap(long, value_parser, num_args = 1..)] 461 #[clap(long, value_parser, num_args = 1..)]
477 /// additional blossom servers beyond grasp servers
478 blossoms: Vec<String>,
479 #[clap(long, value_parser, num_args = 1..)]
480 /// homepage 462 /// homepage
481 web: Vec<String>, 463 web: Vec<String>,
482 #[clap(long, value_parser, num_args = 1..)] 464 #[clap(long, value_parser, num_args = 1..)]
@@ -496,7 +478,6 @@ impl SubCommandArgs {
496 || !self.relay.is_empty() 478 || !self.relay.is_empty()
497 || !self.grasp_server.is_empty() 479 || !self.grasp_server.is_empty()
498 || !self.web.is_empty() 480 || !self.web.is_empty()
499 || !self.blossoms.is_empty()
500 || !self.other_maintainers.is_empty() 481 || !self.other_maintainers.is_empty()
501 || self.earliest_unique_commit.is_some() 482 || self.earliest_unique_commit.is_some()
502 } 483 }
@@ -718,7 +699,7 @@ fn resolve_fields(
718 resolve_grasp_servers(args, cli, state, user_ref, client, &identifier, interactive)?; 699 resolve_grasp_servers(args, cli, state, user_ref, client, &identifier, interactive)?;
719 700
720 // --- Base infrastructure (flag > my event > fallback) --- 701 // --- Base infrastructure (flag > my event > fallback) ---
721 // Grasp-derived infrastructure (my clone URLs, relays, blossoms) is handled 702 // Grasp-derived infrastructure (my clone URLs, relays) is handled
722 // by apply_grasp_infrastructure below. Defaults here are *additional* 703 // by apply_grasp_infrastructure below. Defaults here are *additional*
723 // infrastructure only. My own grasp-format clone URLs are filtered out so 704 // infrastructure only. My own grasp-format clone URLs are filtered out so
724 // they get re-derived from the resolved grasp servers. Grasp-format clone 705 // they get re-derived from the resolved grasp servers. Grasp-format clone
@@ -779,17 +760,6 @@ fn resolve_fields(
779 client.get_relay_default_set().clone() 760 client.get_relay_default_set().clone()
780 }; 761 };
781 762
782 let blossoms_default: Vec<String> = if let Some(ref mr) = my_ref {
783 // Keep blossoms that don't correspond to my grasp servers
784 mr.blossoms
785 .iter()
786 .map(UrlWithoutSlash::to_string_without_trailing_slash)
787 .filter(|b| !is_grasp_derived_blossom(b, &my_existing_grasp_servers))
788 .collect()
789 } else {
790 vec![]
791 };
792
793 let mut git_servers = if args.clone.is_empty() { 763 let mut git_servers = if args.clone.is_empty() {
794 git_servers_default 764 git_servers_default
795 } else { 765 } else {
@@ -800,17 +770,11 @@ fn resolve_fields(
800 } else { 770 } else {
801 args.relay.clone() 771 args.relay.clone()
802 }; 772 };
803 let mut blossom_strings = if args.blossoms.is_empty() {
804 blossoms_default
805 } else {
806 args.blossoms.clone()
807 };
808 773
809 apply_grasp_infrastructure( 774 apply_grasp_infrastructure(
810 &selected_grasp_servers, 775 &selected_grasp_servers,
811 &mut git_servers, 776 &mut git_servers,
812 &mut relay_strings, 777 &mut relay_strings,
813 &mut blossom_strings,
814 &user_ref.public_key, 778 &user_ref.public_key,
815 &identifier, 779 &identifier,
816 )?; 780 )?;
@@ -911,33 +875,6 @@ fn resolve_fields(
911 .collect() 875 .collect()
912 }; 876 };
913 877
914 // --- Blossoms ---
915 let blossoms: Vec<Url> = if !args.blossoms.is_empty() || !interactive {
916 blossom_strings
917 .iter()
918 .filter_map(|b| Url::parse(b).ok())
919 .collect()
920 } else if !simple_mode {
921 let selections: Vec<bool> = vec![true; blossom_strings.len()];
922 let selected = multi_select_with_custom_value(
923 "blossom servers",
924 "blossom server",
925 blossom_strings,
926 selections,
927 |s| {
928 format_grasp_server_url_as_blossom_url(s)
929 .context(format!("Invalid blossom URL format: {s}"))
930 },
931 )?;
932 show_multi_input_prompt_success("blossom servers", &selected);
933 selected.iter().filter_map(|b| Url::parse(b).ok()).collect()
934 } else {
935 blossom_strings
936 .iter()
937 .filter_map(|b| Url::parse(b).ok())
938 .collect()
939 };
940
941 // --- Maintainers --- 878 // --- Maintainers ---
942 let maintainers_default = if let Some(ref mr) = my_ref { 879 let maintainers_default = if let Some(ref mr) = my_ref {
943 let mut m = vec![*my_pubkey]; 880 let mut m = vec![*my_pubkey];
@@ -1113,6 +1050,11 @@ fn resolve_fields(
1113 euc_default 1050 euc_default
1114 }; 1051 };
1115 1052
1053 // --- Blossoms (preserve from latest event) ---
1054 let blossoms = latest
1055 .as_ref()
1056 .map_or_else(Vec::new, |lr| lr.blossoms.clone());
1057
1116 // --- Hashtags (shared metadata — from latest event, like name/description/web) 1058 // --- Hashtags (shared metadata — from latest event, like name/description/web)
1117 // --- 1059 // ---
1118 let hashtags = latest 1060 let hashtags = latest
@@ -1125,10 +1067,10 @@ fn resolve_fields(
1125 description, 1067 description,
1126 git_servers, 1068 git_servers,
1127 relays, 1069 relays,
1128 blossoms,
1129 web, 1070 web,
1130 maintainers, 1071 maintainers,
1131 earliest_unique_commit, 1072 earliest_unique_commit,
1073 blossoms,
1132 hashtags, 1074 hashtags,
1133 selected_grasp_servers, 1075 selected_grasp_servers,
1134 }) 1076 })
@@ -1574,14 +1516,6 @@ fn format_grasp_server_url_as_clone_url(
1574 )) 1516 ))
1575} 1517}
1576 1518
1577fn format_grasp_server_url_as_blossom_url(url: &str) -> Result<String> {
1578 let grasp_server_url = normalize_grasp_server_url(url)?;
1579 if grasp_server_url.contains("http://") {
1580 return Ok(grasp_server_url);
1581 }
1582 Ok(format!("https://{grasp_server_url}"))
1583}
1584
1585fn parse_relay_url(s: &str) -> Result<RelayUrl> { 1519fn parse_relay_url(s: &str) -> Result<RelayUrl> {
1586 // Attempt to parse the original string 1520 // Attempt to parse the original string
1587 match RelayUrl::parse(s) { 1521 match RelayUrl::parse(s) {