What is Nostr?
Kind 1617
git patch: feat(blossom): blossom as remote via external bin
Author Public Key
npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr
Published at
2024-11-18 16:43:46
Kind type
1617
Event JSON
{ "id": "7211667174a4d4964401e8d03c49b561112247674ebc50b3b08a01b50af77fdf", "pubkey": "a008def15796fba9a0d6fab04e8fd57089285d9fd505da5a83fe8aad57a3564d", "created_at": 1731948226, "kind": 1617, "tags": [ [ "a", "30617:a008def15796fba9a0d6fab04e8fd57089285d9fd505da5a83fe8aad57a3564d:ngit" ], [ "r", "26689f97810fc656c7134c76e2a37d33b2e40ce7" ], [ "r", "5ac09c580272d5116c2f57b4370e274b204f21bb" ], [ "alt", "git patch: feat(blossom): blossom as remote via external bin" ], [ "t", "root" ], [ "branch-name", "blossom-remote-via-external-binaries" ], [ "p", "a008def15796fba9a0d6fab04e8fd57089285d9fd505da5a83fe8aad57a3564d" ], [ "commit", "5ac09c580272d5116c2f57b4370e274b204f21bb" ], [ "parent-commit", "ae87aedae9696f4c855ac3dc47e61faec9d07c15" ], [ "commit-pgp-sig", "-----BEGIN PGP SIGNATURE-----\n\niQIzBAABCAAdFiEEsRaN4Kb3mvfPwNXpaOFUhtc/deEFAmc7bmoACgkQaOFUhtc/\ndeHpmw//V1WqENea7rEbungucbGuHtFLh7jgDtrukS7PMQGKe+6SB2Qn1VPfaTTz\nnESWMoehYogJbdEGlwO2umhAHpFBI1p52VCsLcFGi5x3m6edmO5H826PSOuNKPSR\nuOhihqvGZtbplm62HdkcY44XhAtKy77I307w8zUQwme02aC5XMtNOt7VR8gxd8da\nDlI9oigbZlAdjVRzGRr9PB3Thb3W66P4inuWiMtXu4E7aKdWifF1rKbPr+GbFaKV\nccVPJ37Su3xXpAoktIJ+hxhOo2owM39x1+OhP9+Pbatnjv72tutNDeiSWChVPZ+C\nREHKxj0qHk/IaWBWpR2wDTcQDqiE8Dnf0TBoGuoCEhF9KBWIL3xLXPwSlu9PUyHb\nZT3ffT+RbQXyMgSU8t73wUj4EHkFl3HeP6Go6jzNc2XSxH299yVoGpE+D9icejNn\nIYFDrEiiq506LAWqY8ryuTArpUPZmtWHxFLFq5WvhD9HR8AjvuVn53r74D8Dzovi\nEmwzOWCxXvaQr2KPDTIFI2o0IXzUVP9uhIg2g0zdstgPP5QugDjV0AukOJ2yg5S3\njs/sAASdDFMfF3adM94MRPGMZJbef+7FDS9WxwjVXKzrznvNKm/QDLR+y8YqF6qg\nwGe9+Y+6mi9BS3thNY/oOB4/QzPDjzmlFkKMrrBFnxcuaqIXFsA=\n=+vBc\n-----END PGP SIGNATURE-----" ], [ "description", "feat(blossom): blossom as remote via external bin\n\nfollowing conversations with\nnostr:npub1elta7cneng3w8p9y4dw633qzdjr4kyvaparuyuttyrx6e8xp7xnq32cume\nthis minimum viable attempt at adapting git-remote-nostr so that his\napproach / work on git via blossom can be intergrated.\n\nit requires 2 binaries in PATH called:\n\n1. git-remote-blossom-fetch which must take multiple commit ids as\n`--input` args and either write an errot to `stderr` or return a\nsuccess code after downloading and adding missing state data related\nto these commit ids into the local .git folder.\n\n2. git-remote-blossom-push which must take multiple commit ids as\n`--input` args and either write an errot to `stderr` or upload\n downloading and uploading any missing state data to (a) blossom\n server(s) in a way that is retrievable by the fetch binary.\n\nthis is just an untested starting point.\n" ], [ "author", "DanConwayDev", "DanConwayDev@protonmail.com", "1731947987", "0" ], [ "committer", "DanConwayDev", "DanConwayDev@protonmail.com", "1731947987", "0" ] ], "content": "From 5ac09c580272d5116c2f57b4370e274b204f21bb Mon Sep 17 00:00:00 2001\nFrom: DanConwayDev \u003cDanConwayDev@protonmail.com\u003e\nDate: Mon, 18 Nov 2024 16:39:47 +0000\nSubject: [PATCH] feat(blossom): blossom as remote via external bin\n\nfollowing conversations with\nnostr:npub1elta7cneng3w8p9y4dw633qzdjr4kyvaparuyuttyrx6e8xp7xnq32cume\nthis minimum viable attempt at adapting git-remote-nostr so that his\napproach / work on git via blossom can be intergrated.\n\nit requires 2 binaries in PATH called:\n\n1. git-remote-blossom-fetch which must take multiple commit ids as\n`--input` args and either write an errot to `stderr` or return a\nsuccess code after downloading and adding missing state data related\nto these commit ids into the local .git folder.\n\n2. git-remote-blossom-push which must take multiple commit ids as\n`--input` args and either write an errot to `stderr` or upload\n downloading and uploading any missing state data to (a) blossom\n server(s) in a way that is retrievable by the fetch binary.\n\nthis is just an untested starting point.\n---\n src/bin/git_remote_nostr/fetch.rs | 30 ++++++++++++++++++++++++++++++\n src/bin/git_remote_nostr/list.rs | 24 +++++++++++++++++++++++-\n src/bin/git_remote_nostr/push.rs | 47 ++++++++++++++++++++++++++++++++++++++++++++---\n src/lib/repo_state.rs | 1 +\n 4 files changed, 98 insertions(+), 4 deletions(-)\n\ndiff --git a/src/bin/git_remote_nostr/fetch.rs b/src/bin/git_remote_nostr/fetch.rs\nindex a972a2f..df2158b 100644\n--- a/src/bin/git_remote_nostr/fetch.rs\n+++ b/src/bin/git_remote_nostr/fetch.rs\n@@ -2,6 +2,7 @@ use core::str;\n use std::{\n collections::HashMap,\n io::Stdin,\n+ process::Command,\n sync::{Arc, Mutex},\n time::Instant,\n };\n@@ -171,6 +172,10 @@ pub fn fetch_from_git_server(\n return Ok(());\n }\n \n+ if git_server_url == \"blossom\" {\n+ return fetch_from_blossom(oids, term);\n+ }\n+\n let server_url = git_server_url.parse::\u003cCloneUrl\u003e()?;\n \n let protocols_to_attempt = get_read_protocols_to_try(git_repo, \u0026server_url, decoded_nostr_url);\n@@ -228,6 +233,31 @@ pub fn fetch_from_git_server(\n }\n }\n \n+fn fetch_from_blossom(oids: \u0026[String], term: \u0026console::Term) -\u003e Result\u003c()\u003e {\n+ term.write_line(\"fetching over blossom...\")?;\n+ let args: Vec\u003cString\u003e = oids\n+ .iter()\n+ .flat_map(|value| vec![\"--input\".to_string(), value.clone()])\n+ .collect();\n+ let res = Command::new(\"git-remote-blossom-fetch\").args(args).output();\n+ match res {\n+ Ok(output) =\u003e {\n+ if output.status.success() {\n+ term.write_line(\"fetch: succeeded over blossom\")?;\n+ } else {\n+ let error = String::from_utf8_lossy(\u0026output.stderr).to_string();\n+ term.write_line(format!(\"fetch: failed over blossom: {}\", \u0026error).as_str())?;\n+ bail!(error);\n+ }\n+ }\n+ Err(error) =\u003e {\n+ term.write_line(format!(\"fetch: failed over blossom: {error}\").as_str())?;\n+ bail!(error);\n+ }\n+ }\n+ Ok(())\n+}\n+\n #[allow(clippy::cast_precision_loss)]\n #[allow(clippy::float_cmp)]\n #[allow(clippy::needless_pass_by_value)]\ndiff --git a/src/bin/git_remote_nostr/list.rs b/src/bin/git_remote_nostr/list.rs\nindex 92faa6b..b556897 100644\n--- a/src/bin/git_remote_nostr/list.rs\n+++ b/src/bin/git_remote_nostr/list.rs\n@@ -14,6 +14,7 @@ use ngit::{\n git_events::event_to_cover_letter,\n login::get_curent_user,\n repo_ref,\n+ repo_state::RepoState,\n };\n use nostr_sdk::hashes::sha1::Hash as Sha1Hash;\n use repo_ref::RepoRef;\n@@ -43,11 +44,20 @@ pub async fn run_list(\n \n let term = console::Term::stderr();\n \n- let remote_states = list_from_remotes(\u0026term, git_repo, \u0026repo_ref.git_server, decoded_nostr_url);\n+ let remote_states = list_from_remotes(\n+ \u0026term,\n+ git_repo,\n+ \u0026repo_ref.git_server,\n+ decoded_nostr_url,\n+ \u0026nostr_state,\n+ );\n \n let mut state = if let Some(nostr_state) = nostr_state {\n for (name, value) in \u0026nostr_state.state {\n for (url, remote_state) in \u0026remote_states {\n+ if url == \"blossom\" {\n+ continue;\n+ }\n let remote_name = get_short_git_server_name(git_repo, url);\n if let Some(remote_value) = remote_state.get(name) {\n if value.ne(remote_value) {\n@@ -179,10 +189,22 @@ pub fn list_from_remotes(\n git_repo: \u0026Repo,\n git_servers: \u0026Vec\u003cString\u003e,\n decoded_nostr_url: \u0026NostrUrlDecoded, // Add this parameter\n+ nostr_state: \u0026Option\u003cRepoState\u003e,\n ) -\u003e HashMap\u003cString, HashMap\u003cString, String\u003e\u003e {\n let mut remote_states = HashMap::new();\n let mut errors = HashMap::new();\n for url in git_servers {\n+ if url == \"blossom\" {\n+ remote_states.insert(\n+ \"blossom\".to_string(),\n+ if let Some(nostr_state) = nostr_state {\n+ nostr_state.state.clone()\n+ } else {\n+ HashMap::new()\n+ },\n+ );\n+ continue;\n+ }\n match list_from_remote(term, git_repo, url, decoded_nostr_url) {\n Err(error) =\u003e {\n errors.insert(url, error);\ndiff --git a/src/bin/git_remote_nostr/push.rs b/src/bin/git_remote_nostr/push.rs\nindex db86c04..2bc1cb1 100644\n--- a/src/bin/git_remote_nostr/push.rs\n+++ b/src/bin/git_remote_nostr/push.rs\n@@ -2,6 +2,7 @@ use core::str;\n use std::{\n collections::{HashMap, HashSet},\n io::Stdin,\n+ process::Command,\n sync::{Arc, Mutex},\n time::Instant,\n };\n@@ -72,13 +73,23 @@ pub async fn run_push(\n \n let term = console::Term::stderr();\n \n+ let nostr_state = get_state_from_cache(git_repo.get_path()?, repo_ref).await;\n+\n let list_outputs = match list_outputs {\n Some(outputs) =\u003e outputs,\n- _ =\u003e list_from_remotes(\u0026term, git_repo, \u0026repo_ref.git_server, decoded_nostr_url),\n+ _ =\u003e list_from_remotes(\n+ \u0026term,\n+ git_repo,\n+ \u0026repo_ref.git_server,\n+ decoded_nostr_url,\n+ \u0026if let Ok(nostr_state) = \u0026nostr_state {\n+ Some(nostr_state.clone())\n+ } else {\n+ None\n+ },\n+ ),\n };\n \n- let nostr_state = get_state_from_cache(git_repo.get_path()?, repo_ref).await;\n-\n let existing_state = {\n // if no state events - create from first git server listed\n if let Ok(nostr_state) = \u0026nostr_state {\n@@ -352,7 +363,12 @@ fn push_to_remote(\n remote_refspecs: \u0026[String],\n term: \u0026Term,\n ) -\u003e Result\u003c()\u003e {\n+ if git_server_url == \"blossom\" {\n+ return push_to_blossom(remote_refspecs, term);\n+ }\n+\n let server_url = git_server_url.parse::\u003cCloneUrl\u003e()?;\n+\n let protocols_to_attempt = get_write_protocols_to_try(git_repo, \u0026server_url, decoded_nostr_url);\n \n let mut failed_protocols = vec![];\n@@ -398,6 +414,31 @@ fn push_to_remote(\n }\n }\n \n+fn push_to_blossom(remote_refspecs: \u0026[String], term: \u0026console::Term) -\u003e Result\u003c()\u003e {\n+ term.write_line(\"push: to blossom...\")?;\n+ let args: Vec\u003cString\u003e = remote_refspecs\n+ .iter()\n+ .flat_map(|value| vec![\"--input\".to_string(), value.clone()])\n+ .collect();\n+ let res = Command::new(\"git-remote-blossom-push\").args(args).output();\n+ match res {\n+ Ok(output) =\u003e {\n+ if output.status.success() {\n+ term.write_line(\"push: succeeded over blossom\")?;\n+ } else {\n+ let error = String::from_utf8_lossy(\u0026output.stderr).to_string();\n+ term.write_line(format!(\"push: failed over blossom: {}\", \u0026error).as_str())?;\n+ bail!(error);\n+ }\n+ }\n+ Err(error) =\u003e {\n+ term.write_line(format!(\"push: failed over blossom: {error}\").as_str())?;\n+ bail!(error);\n+ }\n+ }\n+ Ok(())\n+}\n+\n fn push_to_remote_url(\n git_repo: \u0026Repo,\n git_server_url: \u0026str,\ndiff --git a/src/lib/repo_state.rs b/src/lib/repo_state.rs\nindex c3a7606..ccd317a 100644\n--- a/src/lib/repo_state.rs\n+++ b/src/lib/repo_state.rs\n@@ -3,6 +3,7 @@ use std::collections::HashMap;\n use anyhow::{Context, Result};\n use git2::Oid;\n \n+#[derive(Clone)]\n pub struct RepoState {\n pub identifier: String,\n pub state: HashMap\u003cString, String\u003e,\n--\nlibgit2 1.8.1\n\n", "sig": "635d98c2f0e090e540873c446ecad6c41a88daa2941f21ad6f4b8fd6aab28a1fe60341337c0595aa637838c28db89d06e300b3f1394977d60cd39d48328a58f0" }