diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/bin/git_remote_nostr/fetch.rs | 17 | ||||
| -rw-r--r-- | src/bin/git_remote_nostr/push.rs | 13 | ||||
| -rw-r--r-- | src/bin/git_remote_nostr/utils.rs | 2 | ||||
| -rw-r--r-- | src/bin/ngit/sub_commands/init.rs | 53 | ||||
| -rw-r--r-- | src/lib/git_events.rs | 4 |
5 files changed, 47 insertions, 42 deletions
diff --git a/src/bin/git_remote_nostr/fetch.rs b/src/bin/git_remote_nostr/fetch.rs index 90387f3..458c6d8 100644 --- a/src/bin/git_remote_nostr/fetch.rs +++ b/src/bin/git_remote_nostr/fetch.rs | |||
| @@ -141,9 +141,11 @@ async fn fetch_proposals( | |||
| 141 | let current_user = get_curent_user(git_repo)?; | 141 | let current_user = get_curent_user(git_repo)?; |
| 142 | 142 | ||
| 143 | for refstr in proposal_refs.keys() { | 143 | for refstr in proposal_refs.keys() { |
| 144 | if let Some((_, (_, patches))) = | 144 | if let Some((_, (_, patches))) = find_proposal_and_patches_by_branch_name( |
| 145 | find_proposal_and_patches_by_branch_name(refstr, &open_proposals, ¤t_user) | 145 | refstr, |
| 146 | { | 146 | &open_proposals, |
| 147 | current_user.as_ref(), | ||
| 148 | ) { | ||
| 147 | if let Err(error) = make_commits_for_proposal(git_repo, repo_ref, patches) { | 149 | if let Err(error) = make_commits_for_proposal(git_repo, repo_ref, patches) { |
| 148 | term.write_line( | 150 | term.write_line( |
| 149 | format!("WARNING: failed to create branch for {refstr}, error: {error}",) | 151 | format!("WARNING: failed to create branch for {refstr}, error: {error}",) |
| @@ -234,7 +236,7 @@ pub fn fetch_from_git_server( | |||
| 234 | fn report_on_transfer_progress( | 236 | fn report_on_transfer_progress( |
| 235 | progress_stats: &Progress<'_>, | 237 | progress_stats: &Progress<'_>, |
| 236 | start_time: &Instant, | 238 | start_time: &Instant, |
| 237 | end_time: &Option<Instant>, | 239 | end_time: Option<&Instant>, |
| 238 | ) -> Vec<String> { | 240 | ) -> Vec<String> { |
| 239 | let mut report = vec![]; | 241 | let mut report = vec![]; |
| 240 | let total = progress_stats.total_objects() as f64; | 242 | let total = progress_stats.total_objects() as f64; |
| @@ -378,8 +380,11 @@ impl<'a> FetchReporter<'a> { | |||
| 378 | self.start_time = Some(Instant::now()); | 380 | self.start_time = Some(Instant::now()); |
| 379 | } | 381 | } |
| 380 | let existing_lines = self.just_count_transfer_progress(); | 382 | let existing_lines = self.just_count_transfer_progress(); |
| 381 | let updated = | 383 | let updated = report_on_transfer_progress( |
| 382 | report_on_transfer_progress(progress_stats, &self.start_time.unwrap(), &self.end_time); | 384 | progress_stats, |
| 385 | &self.start_time.unwrap(), | ||
| 386 | self.end_time.as_ref(), | ||
| 387 | ); | ||
| 383 | if self.transfer_progress_msgs.len() <= updated.len() { | 388 | if self.transfer_progress_msgs.len() <= updated.len() { |
| 384 | if self.end_time.is_none() && updated.first().is_some_and(|f| f.contains("100%")) { | 389 | if self.end_time.is_none() && updated.first().is_some_and(|f| f.contains("100%")) { |
| 385 | self.end_time = Some(Instant::now()); | 390 | self.end_time = Some(Instant::now()); |
diff --git a/src/bin/git_remote_nostr/push.rs b/src/bin/git_remote_nostr/push.rs index 48122e3..f2ac169 100644 --- a/src/bin/git_remote_nostr/push.rs +++ b/src/bin/git_remote_nostr/push.rs | |||
| @@ -299,7 +299,7 @@ async fn process_proposal_refspecs( | |||
| 299 | let tip_of_pushed_branch = git_repo.get_commit_or_tip_of_reference(from)?; | 299 | let tip_of_pushed_branch = git_repo.get_commit_or_tip_of_reference(from)?; |
| 300 | 300 | ||
| 301 | if let Some((_, (proposal, patches))) = | 301 | if let Some((_, (proposal, patches))) = |
| 302 | find_proposal_and_patches_by_branch_name(to, &all_proposals, ¤t_user) | 302 | find_proposal_and_patches_by_branch_name(to, &all_proposals, current_user.as_ref()) |
| 303 | { | 303 | { |
| 304 | if [repo_ref.maintainers.clone(), vec![proposal.pubkey]] | 304 | if [repo_ref.maintainers.clone(), vec![proposal.pubkey]] |
| 305 | .concat() | 305 | .concat() |
| @@ -576,7 +576,7 @@ fn report_on_transfer_progress( | |||
| 576 | total: usize, | 576 | total: usize, |
| 577 | bytes: usize, | 577 | bytes: usize, |
| 578 | start_time: &Instant, | 578 | start_time: &Instant, |
| 579 | end_time: &Option<Instant>, | 579 | end_time: Option<&Instant>, |
| 580 | ) -> Option<String> { | 580 | ) -> Option<String> { |
| 581 | if total == 0 { | 581 | if total == 0 { |
| 582 | return None; | 582 | return None; |
| @@ -688,7 +688,7 @@ impl<'a> PushReporter<'a> { | |||
| 688 | total, | 688 | total, |
| 689 | bytes, | 689 | bytes, |
| 690 | &self.start_time.unwrap(), | 690 | &self.start_time.unwrap(), |
| 691 | &self.end_time, | 691 | self.end_time.as_ref(), |
| 692 | ) { | 692 | ) { |
| 693 | let existing_lines = self.count_all_existing_lines(); | 693 | let existing_lines = self.count_all_existing_lines(); |
| 694 | if report.contains("100%") { | 694 | if report.contains("100%") { |
| @@ -1215,11 +1215,12 @@ async fn create_merge_events( | |||
| 1215 | signer, | 1215 | signer, |
| 1216 | repo_ref, | 1216 | repo_ref, |
| 1217 | &proposal, | 1217 | &proposal, |
| 1218 | &if let Some(revision_id) = revision_id { | 1218 | if let Some(revision_id) = revision_id { |
| 1219 | Some(get_event_from_cache_by_id(git_repo, revision_id).await?) | 1219 | Some(get_event_from_cache_by_id(git_repo, revision_id).await?) |
| 1220 | } else { | 1220 | } else { |
| 1221 | None | 1221 | None |
| 1222 | }, | 1222 | } |
| 1223 | .as_ref(), | ||
| 1223 | if let Some((commit, _)) = merged_patches | 1224 | if let Some((commit, _)) = merged_patches |
| 1224 | .iter() | 1225 | .iter() |
| 1225 | .find(|(_, m)| **m == MergedPRCommitType::MergeCommit) | 1226 | .find(|(_, m)| **m == MergedPRCommitType::MergeCommit) |
| @@ -1263,7 +1264,7 @@ async fn create_merge_status( | |||
| 1263 | signer: &Arc<dyn NostrSigner>, | 1264 | signer: &Arc<dyn NostrSigner>, |
| 1264 | repo_ref: &RepoRef, | 1265 | repo_ref: &RepoRef, |
| 1265 | proposal: &Event, | 1266 | proposal: &Event, |
| 1266 | revision: &Option<Event>, | 1267 | revision: Option<&Event>, |
| 1267 | merge_commits: Vec<Sha1Hash>, | 1268 | merge_commits: Vec<Sha1Hash>, |
| 1268 | merged_patches: Vec<EventId>, | 1269 | merged_patches: Vec<EventId>, |
| 1269 | applied: bool, | 1270 | applied: bool, |
diff --git a/src/bin/git_remote_nostr/utils.rs b/src/bin/git_remote_nostr/utils.rs index 5efb6e0..8e89652 100644 --- a/src/bin/git_remote_nostr/utils.rs +++ b/src/bin/git_remote_nostr/utils.rs | |||
| @@ -188,7 +188,7 @@ pub async fn get_all_proposals( | |||
| 188 | pub fn find_proposal_and_patches_by_branch_name<'a>( | 188 | pub fn find_proposal_and_patches_by_branch_name<'a>( |
| 189 | refstr: &'a str, | 189 | refstr: &'a str, |
| 190 | open_proposals: &'a HashMap<EventId, (Event, Vec<Event>)>, | 190 | open_proposals: &'a HashMap<EventId, (Event, Vec<Event>)>, |
| 191 | current_user: &Option<PublicKey>, | 191 | current_user: Option<&PublicKey>, |
| 192 | ) -> Option<(&'a EventId, &'a (Event, Vec<Event>))> { | 192 | ) -> Option<(&'a EventId, &'a (Event, Vec<Event>))> { |
| 193 | open_proposals.iter().find(|(_, (proposal, _))| { | 193 | open_proposals.iter().find(|(_, (proposal, _))| { |
| 194 | is_event_proposal_root_for_branch(proposal, refstr, current_user).unwrap_or(false) | 194 | is_event_proposal_root_for_branch(proposal, refstr, current_user).unwrap_or(false) |
diff --git a/src/bin/ngit/sub_commands/init.rs b/src/bin/ngit/sub_commands/init.rs index 1695e4c..0894f41 100644 --- a/src/bin/ngit/sub_commands/init.rs +++ b/src/bin/ngit/sub_commands/init.rs | |||
| @@ -364,34 +364,33 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 364 | args.web.clone() | 364 | args.web.clone() |
| 365 | }; | 365 | }; |
| 366 | 366 | ||
| 367 | let earliest_unique_commit = match &args.earliest_unique_commit { | 367 | let earliest_unique_commit = if let Some(t) = &args.earliest_unique_commit { |
| 368 | Some(t) => t.clone(), | 368 | t.clone() |
| 369 | None => { | 369 | } else { |
| 370 | let mut earliest_unique_commit = if let Some(repo_ref) = &repo_ref { | 370 | let mut earliest_unique_commit = if let Some(repo_ref) = &repo_ref { |
| 371 | repo_ref.root_commit.clone() | 371 | repo_ref.root_commit.clone() |
| 372 | } else { | 372 | } else { |
| 373 | root_commit.to_string() | 373 | root_commit.to_string() |
| 374 | }; | 374 | }; |
| 375 | println!( | 375 | println!( |
| 376 | "the earliest unique commit helps with discoverability. It defaults to the root commit. Only change this if your repo has completely forked off an has formed its own identity." | 376 | "the earliest unique commit helps with discoverability. It defaults to the root commit. Only change this if your repo has completely forked off an has formed its own identity." |
| 377 | ); | 377 | ); |
| 378 | loop { | 378 | loop { |
| 379 | earliest_unique_commit = Interactor::default().input( | 379 | earliest_unique_commit = Interactor::default().input( |
| 380 | PromptInputParms::default() | 380 | PromptInputParms::default() |
| 381 | .with_prompt("earliest unique commit (to help with discoverability)") | 381 | .with_prompt("earliest unique commit (to help with discoverability)") |
| 382 | .with_default(earliest_unique_commit.clone()), | 382 | .with_default(earliest_unique_commit.clone()), |
| 383 | )?; | 383 | )?; |
| 384 | if let Ok(exists) = git_repo.does_commit_exist(&earliest_unique_commit) { | 384 | if let Ok(exists) = git_repo.does_commit_exist(&earliest_unique_commit) { |
| 385 | if exists { | 385 | if exists { |
| 386 | break earliest_unique_commit; | 386 | break earliest_unique_commit; |
| 387 | } | ||
| 388 | println!("commit does not exist on current repository"); | ||
| 389 | } else { | ||
| 390 | println!("commit id not formatted correctly"); | ||
| 391 | } | ||
| 392 | if earliest_unique_commit.len().ne(&40) { | ||
| 393 | println!("commit id must be 40 characters long"); | ||
| 394 | } | 387 | } |
| 388 | println!("commit does not exist on current repository"); | ||
| 389 | } else { | ||
| 390 | println!("commit id not formatted correctly"); | ||
| 391 | } | ||
| 392 | if earliest_unique_commit.len().ne(&40) { | ||
| 393 | println!("commit id must be 40 characters long"); | ||
| 395 | } | 394 | } |
| 396 | } | 395 | } |
| 397 | }; | 396 | }; |
diff --git a/src/lib/git_events.rs b/src/lib/git_events.rs index 17fae8c..d8564ae 100644 --- a/src/lib/git_events.rs +++ b/src/lib/git_events.rs | |||
| @@ -619,11 +619,11 @@ fn get_event_parent_id(event: &nostr::Event) -> Result<String> { | |||
| 619 | pub fn is_event_proposal_root_for_branch( | 619 | pub fn is_event_proposal_root_for_branch( |
| 620 | e: &Event, | 620 | e: &Event, |
| 621 | branch_name_or_refstr: &str, | 621 | branch_name_or_refstr: &str, |
| 622 | logged_in_user: &Option<PublicKey>, | 622 | logged_in_user: Option<&PublicKey>, |
| 623 | ) -> Result<bool> { | 623 | ) -> Result<bool> { |
| 624 | let branch_name = branch_name_or_refstr.replace("refs/heads/", ""); | 624 | let branch_name = branch_name_or_refstr.replace("refs/heads/", ""); |
| 625 | Ok(event_to_cover_letter(e).is_ok_and(|cl| { | 625 | Ok(event_to_cover_letter(e).is_ok_and(|cl| { |
| 626 | (logged_in_user.is_some_and(|public_key| e.pubkey.eq(&public_key)) | 626 | (logged_in_user.is_some_and(|public_key| e.pubkey.eq(public_key)) |
| 627 | && (branch_name.eq(&format!("pr/{}", cl.branch_name)) | 627 | && (branch_name.eq(&format!("pr/{}", cl.branch_name)) |
| 628 | || cl.branch_name.eq(&branch_name))) | 628 | || cl.branch_name.eq(&branch_name))) |
| 629 | || cl.get_branch_name().is_ok_and(|s| s.eq(&branch_name)) | 629 | || cl.get_branch_name().is_ok_and(|s| s.eq(&branch_name)) |