diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2024-12-16 09:00:46 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2024-12-16 09:46:30 +0000 |
| commit | 4ee83e2fe5335a8afd78439c35f029c4a472e797 (patch) | |
| tree | bdb111b191e7a68cb74ce29b4bb2757b4b7be91f /src/bin/git_remote_nostr | |
| parent | 5fe839e2bf8ceb2931c1984efb2d956980431203 (diff) | |
chore: bump nix flake rust nightly `fmt` overlay
update the rust nightly `fmt` overlay which needs to be pinned
to a specific version (this case by date)
update formatting in main files via `cargo fmt`
Diffstat (limited to 'src/bin/git_remote_nostr')
| -rw-r--r-- | src/bin/git_remote_nostr/fetch.rs | 10 | ||||
| -rw-r--r-- | src/bin/git_remote_nostr/list.rs | 6 | ||||
| -rw-r--r-- | src/bin/git_remote_nostr/main.rs | 6 | ||||
| -rw-r--r-- | src/bin/git_remote_nostr/push.rs | 62 | ||||
| -rw-r--r-- | src/bin/git_remote_nostr/utils.rs | 17 |
5 files changed, 44 insertions, 57 deletions
diff --git a/src/bin/git_remote_nostr/fetch.rs b/src/bin/git_remote_nostr/fetch.rs index 458c6d8..7012955 100644 --- a/src/bin/git_remote_nostr/fetch.rs +++ b/src/bin/git_remote_nostr/fetch.rs | |||
| @@ -6,15 +6,15 @@ use std::{ | |||
| 6 | time::Instant, | 6 | time::Instant, |
| 7 | }; | 7 | }; |
| 8 | 8 | ||
| 9 | use anyhow::{anyhow, bail, Context, Result}; | 9 | use anyhow::{Context, Result, anyhow, bail}; |
| 10 | use auth_git2::GitAuthenticator; | 10 | use auth_git2::GitAuthenticator; |
| 11 | use git2::{Progress, Repository}; | 11 | use git2::{Progress, Repository}; |
| 12 | use ngit::{ | 12 | use ngit::{ |
| 13 | cli_interactor::count_lines_per_msg_vec, | 13 | cli_interactor::count_lines_per_msg_vec, |
| 14 | git::{ | 14 | git::{ |
| 15 | Repo, RepoActions, | ||
| 15 | nostr_url::{CloneUrl, NostrUrlDecoded, ServerProtocol}, | 16 | nostr_url::{CloneUrl, NostrUrlDecoded, ServerProtocol}, |
| 16 | utils::check_ssh_keys, | 17 | utils::check_ssh_keys, |
| 17 | Repo, RepoActions, | ||
| 18 | }, | 18 | }, |
| 19 | git_events::tag_value, | 19 | git_events::tag_value, |
| 20 | login::get_curent_user, | 20 | login::get_curent_user, |
| @@ -24,9 +24,9 @@ use nostr::nips::nip19; | |||
| 24 | use nostr_sdk::{Event, ToBech32}; | 24 | use nostr_sdk::{Event, ToBech32}; |
| 25 | 25 | ||
| 26 | use crate::utils::{ | 26 | use crate::utils::{ |
| 27 | fetch_or_list_error_is_not_authentication_failure, find_proposal_and_patches_by_branch_name, | 27 | Direction, fetch_or_list_error_is_not_authentication_failure, |
| 28 | get_oids_from_fetch_batch, get_open_proposals, get_read_protocols_to_try, join_with_and, | 28 | find_proposal_and_patches_by_branch_name, get_oids_from_fetch_batch, get_open_proposals, |
| 29 | set_protocol_preference, Direction, | 29 | get_read_protocols_to_try, join_with_and, set_protocol_preference, |
| 30 | }; | 30 | }; |
| 31 | 31 | ||
| 32 | pub async fn run_fetch( | 32 | pub async fn run_fetch( |
diff --git a/src/bin/git_remote_nostr/list.rs b/src/bin/git_remote_nostr/list.rs index 9171544..bba15aa 100644 --- a/src/bin/git_remote_nostr/list.rs +++ b/src/bin/git_remote_nostr/list.rs | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | use core::str; | 1 | use core::str; |
| 2 | use std::collections::HashMap; | 2 | use std::collections::HashMap; |
| 3 | 3 | ||
| 4 | use anyhow::{anyhow, Context, Result}; | 4 | use anyhow::{Context, Result, anyhow}; |
| 5 | use auth_git2::GitAuthenticator; | 5 | use auth_git2::GitAuthenticator; |
| 6 | use client::get_state_from_cache; | 6 | use client::get_state_from_cache; |
| 7 | use git::RepoActions; | 7 | use git::RepoActions; |
| @@ -22,9 +22,9 @@ use crate::{ | |||
| 22 | fetch::{fetch_from_git_server, make_commits_for_proposal}, | 22 | fetch::{fetch_from_git_server, make_commits_for_proposal}, |
| 23 | git::Repo, | 23 | git::Repo, |
| 24 | utils::{ | 24 | utils::{ |
| 25 | fetch_or_list_error_is_not_authentication_failure, get_open_proposals, | 25 | Direction, fetch_or_list_error_is_not_authentication_failure, get_open_proposals, |
| 26 | get_read_protocols_to_try, get_short_git_server_name, join_with_and, | 26 | get_read_protocols_to_try, get_short_git_server_name, join_with_and, |
| 27 | set_protocol_preference, Direction, | 27 | set_protocol_preference, |
| 28 | }, | 28 | }, |
| 29 | }; | 29 | }; |
| 30 | 30 | ||
diff --git a/src/bin/git_remote_nostr/main.rs b/src/bin/git_remote_nostr/main.rs index 1a21341..e6f7af3 100644 --- a/src/bin/git_remote_nostr/main.rs +++ b/src/bin/git_remote_nostr/main.rs | |||
| @@ -11,9 +11,9 @@ use std::{ | |||
| 11 | path::{Path, PathBuf}, | 11 | path::{Path, PathBuf}, |
| 12 | }; | 12 | }; |
| 13 | 13 | ||
| 14 | use anyhow::{bail, Context, Result}; | 14 | use anyhow::{Context, Result, bail}; |
| 15 | use client::{consolidate_fetch_reports, get_repo_ref_from_cache, Connect}; | 15 | use client::{Connect, consolidate_fetch_reports, get_repo_ref_from_cache}; |
| 16 | use git::{nostr_url::NostrUrlDecoded, RepoActions}; | 16 | use git::{RepoActions, nostr_url::NostrUrlDecoded}; |
| 17 | use ngit::{client, git, login::existing::load_existing_login}; | 17 | use ngit::{client, git, login::existing::load_existing_login}; |
| 18 | use nostr::nips::nip01::Coordinate; | 18 | use nostr::nips::nip01::Coordinate; |
| 19 | use utils::read_line; | 19 | use utils::read_line; |
diff --git a/src/bin/git_remote_nostr/push.rs b/src/bin/git_remote_nostr/push.rs index f2ac169..e8e1587 100644 --- a/src/bin/git_remote_nostr/push.rs +++ b/src/bin/git_remote_nostr/push.rs | |||
| @@ -6,17 +6,17 @@ use std::{ | |||
| 6 | time::Instant, | 6 | time::Instant, |
| 7 | }; | 7 | }; |
| 8 | 8 | ||
| 9 | use anyhow::{anyhow, bail, Context, Result}; | 9 | use anyhow::{Context, Result, anyhow, bail}; |
| 10 | use auth_git2::GitAuthenticator; | 10 | use auth_git2::GitAuthenticator; |
| 11 | use client::{ | 11 | use client::{ |
| 12 | get_events_from_local_cache, get_state_from_cache, send_events, sign_event, STATE_KIND, | 12 | STATE_KIND, get_events_from_local_cache, get_state_from_cache, send_events, sign_event, |
| 13 | }; | 13 | }; |
| 14 | use console::Term; | 14 | use console::Term; |
| 15 | use git::{sha1_to_oid, RepoActions}; | 15 | use git::{RepoActions, sha1_to_oid}; |
| 16 | use git2::{Oid, Repository}; | ||
| 17 | use git_events::{ | 16 | use git_events::{ |
| 18 | generate_cover_letter_and_patch_events, generate_patch_event, get_commit_id_from_patch, | 17 | generate_cover_letter_and_patch_events, generate_patch_event, get_commit_id_from_patch, |
| 19 | }; | 18 | }; |
| 19 | use git2::{Oid, Repository}; | ||
| 20 | use ngit::{ | 20 | use ngit::{ |
| 21 | cli_interactor::count_lines_per_msg_vec, | 21 | cli_interactor::count_lines_per_msg_vec, |
| 22 | client::{self, get_event_from_cache_by_id}, | 22 | client::{self, get_event_from_cache_by_id}, |
| @@ -32,8 +32,8 @@ use ngit::{ | |||
| 32 | }; | 32 | }; |
| 33 | use nostr::nips::nip10::Marker; | 33 | use nostr::nips::nip10::Marker; |
| 34 | use nostr_sdk::{ | 34 | use nostr_sdk::{ |
| 35 | hashes::sha1::Hash as Sha1Hash, Event, EventBuilder, EventId, Kind, NostrSigner, PublicKey, | 35 | Event, EventBuilder, EventId, Kind, NostrSigner, PublicKey, RelayUrl, Tag, |
| 36 | RelayUrl, Tag, | 36 | hashes::sha1::Hash as Sha1Hash, |
| 37 | }; | 37 | }; |
| 38 | use repo_ref::RepoRef; | 38 | use repo_ref::RepoRef; |
| 39 | use repo_state::RepoState; | 39 | use repo_state::RepoState; |
| @@ -43,9 +43,10 @@ use crate::{ | |||
| 43 | git::Repo, | 43 | git::Repo, |
| 44 | list::list_from_remotes, | 44 | list::list_from_remotes, |
| 45 | utils::{ | 45 | utils::{ |
| 46 | find_proposal_and_patches_by_branch_name, get_all_proposals, get_remote_name_by_url, | 46 | Direction, find_proposal_and_patches_by_branch_name, get_all_proposals, |
| 47 | get_short_git_server_name, get_write_protocols_to_try, join_with_and, | 47 | get_remote_name_by_url, get_short_git_server_name, get_write_protocols_to_try, |
| 48 | push_error_is_not_authentication_failure, read_line, set_protocol_preference, Direction, | 48 | join_with_and, push_error_is_not_authentication_failure, read_line, |
| 49 | set_protocol_preference, | ||
| 49 | }, | 50 | }, |
| 50 | }; | 51 | }; |
| 51 | 52 | ||
| @@ -1023,13 +1024,10 @@ async fn get_merged_status_events( | |||
| 1023 | let (ahead, _) = | 1024 | let (ahead, _) = |
| 1024 | git_repo.get_commits_ahead_behind(&tip_of_remote_branch, &tip_of_pushed_branch)?; | 1025 | git_repo.get_commits_ahead_behind(&tip_of_remote_branch, &tip_of_pushed_branch)?; |
| 1025 | 1026 | ||
| 1026 | let commit_events = get_events_from_local_cache( | 1027 | let commit_events = get_events_from_local_cache(git_repo.get_path()?, vec![ |
| 1027 | git_repo.get_path()?, | 1028 | nostr::Filter::default().kind(nostr::Kind::GitPatch), |
| 1028 | vec![ | 1029 | // TODO: limit by repo_ref |
| 1029 | nostr::Filter::default().kind(nostr::Kind::GitPatch), | 1030 | ]) |
| 1030 | // TODO: limit by repo_ref | ||
| 1031 | ], | ||
| 1032 | ) | ||
| 1033 | .await?; | 1031 | .await?; |
| 1034 | 1032 | ||
| 1035 | let merged_proposals_info = | 1033 | let merged_proposals_info = |
| @@ -1106,12 +1104,9 @@ async fn get_merged_proposals_info( | |||
| 1106 | proposals.entry(proposal_id).or_default(); | 1104 | proposals.entry(proposal_id).or_default(); |
| 1107 | // ignore revisions without all the merged commits | 1105 | // ignore revisions without all the merged commits |
| 1108 | if entry_revision_id == &revision_id { | 1106 | if entry_revision_id == &revision_id { |
| 1109 | merged_patches.insert( | 1107 | merged_patches.insert(*commit_hash, MergedPRCommitType::PatchCommit { |
| 1110 | *commit_hash, | 1108 | event_id: patch_event.id, |
| 1111 | MergedPRCommitType::PatchCommit { | 1109 | }); |
| 1112 | event_id: patch_event.id, | ||
| 1113 | }, | ||
| 1114 | ); | ||
| 1115 | } | 1110 | } |
| 1116 | } | 1111 | } |
| 1117 | } | 1112 | } |
| @@ -1136,12 +1131,9 @@ async fn get_merged_proposals_info( | |||
| 1136 | proposals.entry(proposal_id).or_default(); | 1131 | proposals.entry(proposal_id).or_default(); |
| 1137 | // ignore revisions without all the applied commits | 1132 | // ignore revisions without all the applied commits |
| 1138 | if entry_revision_id == &revision_id { | 1133 | if entry_revision_id == &revision_id { |
| 1139 | merged_patches.insert( | 1134 | merged_patches.insert(*commit_hash, MergedPRCommitType::PatchApplied { |
| 1140 | *commit_hash, | 1135 | event_id: patch_event.id, |
| 1141 | MergedPRCommitType::PatchApplied { | 1136 | }); |
| 1142 | event_id: patch_event.id, | ||
| 1143 | }, | ||
| 1144 | ); | ||
| 1145 | } | 1137 | } |
| 1146 | } | 1138 | } |
| 1147 | } | 1139 | } |
| @@ -1379,10 +1371,9 @@ async fn get_proposal_and_revision_root_from_patch( | |||
| 1379 | .clone(), | 1371 | .clone(), |
| 1380 | )?; | 1372 | )?; |
| 1381 | 1373 | ||
| 1382 | get_events_from_local_cache( | 1374 | get_events_from_local_cache(git_repo.get_path()?, vec![ |
| 1383 | git_repo.get_path()?, | 1375 | nostr::Filter::default().id(proposal_or_revision_id), |
| 1384 | vec![nostr::Filter::default().id(proposal_or_revision_id)], | 1376 | ]) |
| 1385 | ) | ||
| 1386 | .await? | 1377 | .await? |
| 1387 | .first() | 1378 | .first() |
| 1388 | .unwrap() | 1379 | .unwrap() |
| @@ -1538,10 +1529,9 @@ impl BuildRepoState for RepoState { | |||
| 1538 | ) -> Result<RepoState> { | 1529 | ) -> Result<RepoState> { |
| 1539 | let mut tags = vec![Tag::identifier(identifier.clone())]; | 1530 | let mut tags = vec![Tag::identifier(identifier.clone())]; |
| 1540 | for (name, value) in &state { | 1531 | for (name, value) in &state { |
| 1541 | tags.push(Tag::custom( | 1532 | tags.push(Tag::custom(nostr_sdk::TagKind::Custom(name.into()), vec![ |
| 1542 | nostr_sdk::TagKind::Custom(name.into()), | 1533 | value.clone(), |
| 1543 | vec![value.clone()], | 1534 | ])); |
| 1544 | )); | ||
| 1545 | } | 1535 | } |
| 1546 | let event = sign_event(EventBuilder::new(STATE_KIND, "").tags(tags), signer).await?; | 1536 | let event = sign_event(EventBuilder::new(STATE_KIND, "").tags(tags), signer).await?; |
| 1547 | Ok(RepoState { | 1537 | Ok(RepoState { |
diff --git a/src/bin/git_remote_nostr/utils.rs b/src/bin/git_remote_nostr/utils.rs index 8e89652..15ebb10 100644 --- a/src/bin/git_remote_nostr/utils.rs +++ b/src/bin/git_remote_nostr/utils.rs | |||
| @@ -6,7 +6,7 @@ use std::{ | |||
| 6 | str::FromStr, | 6 | str::FromStr, |
| 7 | }; | 7 | }; |
| 8 | 8 | ||
| 9 | use anyhow::{bail, Context, Result}; | 9 | use anyhow::{Context, Result, bail}; |
| 10 | use git2::Repository; | 10 | use git2::Repository; |
| 11 | use ngit::{ | 11 | use ngit::{ |
| 12 | client::{ | 12 | client::{ |
| @@ -14,8 +14,8 @@ use ngit::{ | |||
| 14 | get_proposals_and_revisions_from_cache, | 14 | get_proposals_and_revisions_from_cache, |
| 15 | }, | 15 | }, |
| 16 | git::{ | 16 | git::{ |
| 17 | nostr_url::{CloneUrl, NostrUrlDecoded, ServerProtocol}, | ||
| 18 | Repo, RepoActions, | 17 | Repo, RepoActions, |
| 18 | nostr_url::{CloneUrl, NostrUrlDecoded, ServerProtocol}, | ||
| 19 | }, | 19 | }, |
| 20 | git_events::{ | 20 | git_events::{ |
| 21 | event_is_revision_root, get_most_recent_patch_with_ancestors, | 21 | event_is_revision_root, get_most_recent_patch_with_ancestors, |
| @@ -108,14 +108,11 @@ pub async fn get_open_proposals( | |||
| 108 | .collect(); | 108 | .collect(); |
| 109 | 109 | ||
| 110 | let statuses: Vec<nostr::Event> = { | 110 | let statuses: Vec<nostr::Event> = { |
| 111 | let mut statuses = get_events_from_local_cache( | 111 | let mut statuses = get_events_from_local_cache(git_repo_path, vec![ |
| 112 | git_repo_path, | 112 | nostr::Filter::default() |
| 113 | vec![ | 113 | .kinds(status_kinds().clone()) |
| 114 | nostr::Filter::default() | 114 | .events(proposals.iter().map(|e| e.id)), |
| 115 | .kinds(status_kinds().clone()) | 115 | ]) |
| 116 | .events(proposals.iter().map(|e| e.id)), | ||
| 117 | ], | ||
| 118 | ) | ||
| 119 | .await?; | 116 | .await?; |
| 120 | statuses.sort_by_key(|e| e.created_at); | 117 | statuses.sort_by_key(|e| e.created_at); |
| 121 | statuses.reverse(); | 118 | statuses.reverse(); |