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:
authorDanConwayDev <DanConwayDev@protonmail.com>2025-08-01 09:39:36 +0100
committerDanConwayDev <DanConwayDev@protonmail.com>2025-08-01 09:39:36 +0100
commita625be66cfbced5f96cb0123a286937543e7273c (patch)
tree3fddbe2381cff0004602b6ab80af935540595796 /src
parenta7cabb96df30cd5d26f63affdb023b0706a387d1 (diff)
refactor: move patch size evaluation fn to lib
so we can use it in ngit as well as remote helper
Diffstat (limited to 'src')
-rw-r--r--src/bin/git_remote_nostr/push.rs17
-rw-r--r--src/lib/git/mod.rs14
2 files changed, 16 insertions, 15 deletions
diff --git a/src/bin/git_remote_nostr/push.rs b/src/bin/git_remote_nostr/push.rs
index 9ba7c30..38b6fc4 100644
--- a/src/bin/git_remote_nostr/push.rs
+++ b/src/bin/git_remote_nostr/push.rs
@@ -357,7 +357,7 @@ async fn process_proposal_refspecs(
357 ); 357 );
358 } 358 }
359 if proposal.kind.eq(&KIND_PULL_REQUEST) 359 if proposal.kind.eq(&KIND_PULL_REQUEST)
360 || are_commits_too_big_for_patches(git_repo, &ahead) 360 || git_repo.are_commits_too_big_for_patches(&ahead)
361 { 361 {
362 for event in generate_patches_or_pr_event_or_pr_updates( 362 for event in generate_patches_or_pr_event_or_pr_updates(
363 git_repo, 363 git_repo,
@@ -441,19 +441,6 @@ async fn process_proposal_refspecs(
441 Ok((events, rejected_proposal_refspecs)) 441 Ok((events, rejected_proposal_refspecs))
442} 442}
443 443
444fn are_commits_too_big_for_patches(git_repo: &Repo, commits: &[Sha1Hash]) -> bool {
445 commits.iter().any(|commit| {
446 if let Ok(patch) = git_repo.make_patch_from_commit(commit, &None) {
447 patch.len()
448 > ((65 // max recomended patch event size specified in nip34 in kb
449 // allownace for nostr event wrapper (id, pubkey, tags, sig)
450 - 1) * 1024)
451 } else {
452 true
453 }
454 })
455}
456
457#[allow(clippy::too_many_lines)] 444#[allow(clippy::too_many_lines)]
458async fn generate_patches_or_pr_event_or_pr_updates( 445async fn generate_patches_or_pr_event_or_pr_updates(
459 git_repo: &Repo, 446 git_repo: &Repo,
@@ -466,7 +453,7 @@ async fn generate_patches_or_pr_event_or_pr_updates(
466) -> Result<Vec<Event>> { 453) -> Result<Vec<Event>> {
467 let mut events: Vec<Event> = vec![]; 454 let mut events: Vec<Event> = vec![];
468 let use_pr = root_proposal.is_some_and(|proposal| proposal.kind.eq(&KIND_PULL_REQUEST)) 455 let use_pr = root_proposal.is_some_and(|proposal| proposal.kind.eq(&KIND_PULL_REQUEST))
469 || are_commits_too_big_for_patches(git_repo, ahead); 456 || git_repo.are_commits_too_big_for_patches(ahead);
470 457
471 if use_pr { 458 if use_pr {
472 let repo_grasps = repo_ref.grasp_servers(); 459 let repo_grasps = repo_ref.grasp_servers();
diff --git a/src/lib/git/mod.rs b/src/lib/git/mod.rs
index b275b49..3d5297f 100644
--- a/src/lib/git/mod.rs
+++ b/src/lib/git/mod.rs
@@ -75,6 +75,7 @@ pub trait RepoActions {
75 commit: &Sha1Hash, 75 commit: &Sha1Hash,
76 series_count: &Option<(u64, u64)>, 76 series_count: &Option<(u64, u64)>,
77 ) -> Result<String>; 77 ) -> Result<String>;
78 fn are_commits_too_big_for_patches(&self, commits: &[Sha1Hash]) -> bool;
78 fn extract_commit_pgp_signature(&self, commit: &Sha1Hash) -> Result<String>; 79 fn extract_commit_pgp_signature(&self, commit: &Sha1Hash) -> Result<String>;
79 fn checkout(&self, ref_name: &str) -> Result<Sha1Hash>; 80 fn checkout(&self, ref_name: &str) -> Result<Sha1Hash>;
80 fn create_branch_at_commit(&self, branch_name: &str, commit: &str) -> Result<()>; 81 fn create_branch_at_commit(&self, branch_name: &str, commit: &str) -> Result<()>;
@@ -380,6 +381,19 @@ impl RepoActions for Repo {
380 .to_owned()) 381 .to_owned())
381 } 382 }
382 383
384 fn are_commits_too_big_for_patches(&self, commits: &[Sha1Hash]) -> bool {
385 commits.iter().any(|commit| {
386 if let Ok(patch) = self.make_patch_from_commit(commit, &None) {
387 patch.len()
388 > ((65 // max recomended patch event size specified in nip34 in kb
389 // allownace for nostr event wrapper (id, pubkey, tags, sig)
390 - 1) * 1024)
391 } else {
392 true
393 }
394 })
395 }
396
383 fn extract_commit_pgp_signature(&self, commit: &Sha1Hash) -> Result<String> { 397 fn extract_commit_pgp_signature(&self, commit: &Sha1Hash) -> Result<String> {
384 let oid = Oid::from_bytes(commit.as_byte_array()).context(format!( 398 let oid = Oid::from_bytes(commit.as_byte_array()).context(format!(
385 "failed to convert commit_id format for {}", 399 "failed to convert commit_id format for {}",