From a625be66cfbced5f96cb0123a286937543e7273c Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Fri, 1 Aug 2025 09:39:36 +0100 Subject: refactor: move patch size evaluation fn to lib so we can use it in ngit as well as remote helper --- src/lib/git/mod.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/lib') 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 { commit: &Sha1Hash, series_count: &Option<(u64, u64)>, ) -> Result; + fn are_commits_too_big_for_patches(&self, commits: &[Sha1Hash]) -> bool; fn extract_commit_pgp_signature(&self, commit: &Sha1Hash) -> Result; fn checkout(&self, ref_name: &str) -> Result; fn create_branch_at_commit(&self, branch_name: &str, commit: &str) -> Result<()>; @@ -380,6 +381,19 @@ impl RepoActions for Repo { .to_owned()) } + fn are_commits_too_big_for_patches(&self, commits: &[Sha1Hash]) -> bool { + commits.iter().any(|commit| { + if let Ok(patch) = self.make_patch_from_commit(commit, &None) { + patch.len() + > ((65 // max recomended patch event size specified in nip34 in kb + // allownace for nostr event wrapper (id, pubkey, tags, sig) + - 1) * 1024) + } else { + true + } + }) + } + fn extract_commit_pgp_signature(&self, commit: &Sha1Hash) -> Result { let oid = Oid::from_bytes(commit.as_byte_array()).context(format!( "failed to convert commit_id format for {}", -- cgit v1.2.3