From d01380f7b3efebc9c40a2e71c2ddd635fa936be4 Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Tue, 24 Sep 2024 15:03:58 +0100 Subject: feat(login): login via nip46 QR code or nostrconnect url string which is a much better UX flow for nip46 --- src/bin/git_remote_nostr/fetch.rs | 7 ++++--- src/bin/git_remote_nostr/push.rs | 8 ++++---- src/bin/git_remote_nostr/utils.rs | 14 -------------- 3 files changed, 8 insertions(+), 21 deletions(-) (limited to 'src/bin') 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}; use auth_git2::GitAuthenticator; use git2::{Progress, Repository}; use ngit::{ + cli_interactor::count_lines_per_msg_vec, git::{ nostr_url::{CloneUrl, NostrUrlDecoded, ServerProtocol}, utils::check_ssh_keys, @@ -23,9 +24,9 @@ use nostr::nips::nip19; use nostr_sdk::{Event, ToBech32}; use crate::utils::{ - count_lines_per_msg_vec, fetch_or_list_error_is_not_authentication_failure, - find_proposal_and_patches_by_branch_name, get_oids_from_fetch_batch, get_open_proposals, - get_read_protocols_to_try, join_with_and, set_protocol_preference, Direction, + fetch_or_list_error_is_not_authentication_failure, find_proposal_and_patches_by_branch_name, + get_oids_from_fetch_batch, get_open_proposals, get_read_protocols_to_try, join_with_and, + set_protocol_preference, Direction, }; pub 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::{ generate_cover_letter_and_patch_events, generate_patch_event, get_commit_id_from_patch, }; use ngit::{ + cli_interactor::count_lines_per_msg_vec, client::{self, get_event_from_cache_by_id}, git::{ self, @@ -39,10 +40,9 @@ use crate::{ git::Repo, list::list_from_remotes, utils::{ - count_lines_per_msg_vec, find_proposal_and_patches_by_branch_name, get_all_proposals, - get_remote_name_by_url, get_short_git_server_name, get_write_protocols_to_try, - join_with_and, push_error_is_not_authentication_failure, read_line, - set_protocol_preference, Direction, + find_proposal_and_patches_by_branch_name, get_all_proposals, get_remote_name_by_url, + get_short_git_server_name, get_write_protocols_to_try, join_with_and, + push_error_is_not_authentication_failure, read_line, set_protocol_preference, Direction, }, }; 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 { false } -fn count_lines_per_msg(width: u16, msg: &str, prefix_len: usize) -> usize { - if width == 0 { - return 1; - } - // ((msg_len+prefix) / width).ceil() implemented using Integer Arithmetic - ((msg.chars().count() + prefix_len) + (width - 1) as usize) / width as usize -} - -pub fn count_lines_per_msg_vec(width: u16, msgs: &[String], prefix_len: usize) -> usize { - msgs.iter() - .map(|msg| count_lines_per_msg(width, msg, prefix_len)) - .sum() -} - #[cfg(test)] mod tests { use super::*; -- cgit v1.2.3