upleb.uk

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

summaryrefslogtreecommitdiff
path: root/src/bin/git_remote_nostr
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2024-09-24 15:03:58 +0100
committerDanConwayDev <DanConwayDev@protonmail.com>2024-09-24 19:48:11 +0100
commitd01380f7b3efebc9c40a2e71c2ddd635fa936be4 (patch)
tree58af24e8981bfa4b0c8dc330ea8903dac3bbc479 /src/bin/git_remote_nostr
parent0acc9768c2aff4bf4495c89698f29b56dae2f4b4 (diff)
feat(login): login via nip46 QR code
or nostrconnect url string which is a much better UX flow for nip46
Diffstat (limited to 'src/bin/git_remote_nostr')
-rw-r--r--src/bin/git_remote_nostr/fetch.rs7
-rw-r--r--src/bin/git_remote_nostr/push.rs8
-rw-r--r--src/bin/git_remote_nostr/utils.rs14
3 files changed, 8 insertions, 21 deletions
diff --git a/src/bin/git_remote_nostr/fetch.rs b/src/bin/git_remote_nostr/fetch.rs
index 46e7ad3..ff55d6f 100644
--- a/src/bin/git_remote_nostr/fetch.rs
+++ b/src/bin/git_remote_nostr/fetch.rs
@@ -10,6 +10,7 @@ use anyhow::{anyhow, bail, Context, Result};
10use auth_git2::GitAuthenticator; 10use auth_git2::GitAuthenticator;
11use git2::{Progress, Repository}; 11use git2::{Progress, Repository};
12use ngit::{ 12use ngit::{
13 cli_interactor::count_lines_per_msg_vec,
13 git::{ 14 git::{
14 nostr_url::{CloneUrl, NostrUrlDecoded, ServerProtocol}, 15 nostr_url::{CloneUrl, NostrUrlDecoded, ServerProtocol},
15 utils::check_ssh_keys, 16 utils::check_ssh_keys,
@@ -23,9 +24,9 @@ use nostr::nips::nip19;
23use nostr_sdk::{Event, ToBech32}; 24use nostr_sdk::{Event, ToBech32};
24 25
25use crate::utils::{ 26use crate::utils::{
26 count_lines_per_msg_vec, fetch_or_list_error_is_not_authentication_failure, 27 fetch_or_list_error_is_not_authentication_failure, find_proposal_and_patches_by_branch_name,
27 find_proposal_and_patches_by_branch_name, get_oids_from_fetch_batch, get_open_proposals, 28 get_oids_from_fetch_batch, get_open_proposals, get_read_protocols_to_try, join_with_and,
28 get_read_protocols_to_try, join_with_and, set_protocol_preference, Direction, 29 set_protocol_preference, Direction,
29}; 30};
30 31
31pub async fn run_fetch( 32pub async fn run_fetch(
diff --git a/src/bin/git_remote_nostr/push.rs b/src/bin/git_remote_nostr/push.rs
index 3bda6ba..0f4e792 100644
--- a/src/bin/git_remote_nostr/push.rs
+++ b/src/bin/git_remote_nostr/push.rs
@@ -16,6 +16,7 @@ use git_events::{
16 generate_cover_letter_and_patch_events, generate_patch_event, get_commit_id_from_patch, 16 generate_cover_letter_and_patch_events, generate_patch_event, get_commit_id_from_patch,
17}; 17};
18use ngit::{ 18use ngit::{
19 cli_interactor::count_lines_per_msg_vec,
19 client::{self, get_event_from_cache_by_id}, 20 client::{self, get_event_from_cache_by_id},
20 git::{ 21 git::{
21 self, 22 self,
@@ -39,10 +40,9 @@ use crate::{
39 git::Repo, 40 git::Repo,
40 list::list_from_remotes, 41 list::list_from_remotes,
41 utils::{ 42 utils::{
42 count_lines_per_msg_vec, find_proposal_and_patches_by_branch_name, get_all_proposals, 43 find_proposal_and_patches_by_branch_name, get_all_proposals, get_remote_name_by_url,
43 get_remote_name_by_url, get_short_git_server_name, get_write_protocols_to_try, 44 get_short_git_server_name, get_write_protocols_to_try, join_with_and,
44 join_with_and, push_error_is_not_authentication_failure, read_line, 45 push_error_is_not_authentication_failure, read_line, set_protocol_preference, Direction,
45 set_protocol_preference, Direction,
46 }, 46 },
47}; 47};
48 48
diff --git a/src/bin/git_remote_nostr/utils.rs b/src/bin/git_remote_nostr/utils.rs
index 7b5c2d2..3ae1bab 100644
--- a/src/bin/git_remote_nostr/utils.rs
+++ b/src/bin/git_remote_nostr/utils.rs
@@ -384,20 +384,6 @@ pub fn error_might_be_authentication_related(error: &anyhow::Error) -> bool {
384 false 384 false
385} 385}
386 386
387fn count_lines_per_msg(width: u16, msg: &str, prefix_len: usize) -> usize {
388 if width == 0 {
389 return 1;
390 }
391 // ((msg_len+prefix) / width).ceil() implemented using Integer Arithmetic
392 ((msg.chars().count() + prefix_len) + (width - 1) as usize) / width as usize
393}
394
395pub fn count_lines_per_msg_vec(width: u16, msgs: &[String], prefix_len: usize) -> usize {
396 msgs.iter()
397 .map(|msg| count_lines_per_msg(width, msg, prefix_len))
398 .sum()
399}
400
401#[cfg(test)] 387#[cfg(test)]
402mod tests { 388mod tests {
403 use super::*; 389 use super::*;