diff options
Diffstat (limited to 'src/bin/git_remote_nostr')
| -rw-r--r-- | src/bin/git_remote_nostr/fetch.rs | 7 | ||||
| -rw-r--r-- | src/bin/git_remote_nostr/push.rs | 8 | ||||
| -rw-r--r-- | src/bin/git_remote_nostr/utils.rs | 14 |
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}; | |||
| 10 | use auth_git2::GitAuthenticator; | 10 | use auth_git2::GitAuthenticator; |
| 11 | use git2::{Progress, Repository}; | 11 | use git2::{Progress, Repository}; |
| 12 | use ngit::{ | 12 | use 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; | |||
| 23 | use nostr_sdk::{Event, ToBech32}; | 24 | use nostr_sdk::{Event, ToBech32}; |
| 24 | 25 | ||
| 25 | use crate::utils::{ | 26 | use 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 | ||
| 31 | pub async fn run_fetch( | 32 | 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::{ | |||
| 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 | }; |
| 18 | use ngit::{ | 18 | use 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 | ||
| 387 | fn 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 | |||
| 395 | pub 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)] |
| 402 | mod tests { | 388 | mod tests { |
| 403 | use super::*; | 389 | use super::*; |