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/lib/git/mod.rs | |
| 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/lib/git/mod.rs')
| -rw-r--r-- | src/lib/git/mod.rs | 14 |
1 files changed, 14 insertions, 0 deletions
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 {}", |