diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2025-08-01 09:39:36 +0100 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2025-08-01 09:39:36 +0100 |
| commit | a625be66cfbced5f96cb0123a286937543e7273c (patch) | |
| tree | 3fddbe2381cff0004602b6ab80af935540595796 /src/bin | |
| parent | a7cabb96df30cd5d26f63affdb023b0706a387d1 (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/bin')
| -rw-r--r-- | src/bin/git_remote_nostr/push.rs | 17 |
1 files changed, 2 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 | ||
| 444 | fn 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)] |
| 458 | async fn generate_patches_or_pr_event_or_pr_updates( | 445 | async 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(); |