diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2025-06-19 09:30:16 +0100 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2025-06-19 09:30:16 +0100 |
| commit | 9386cc2e409cc4117ae1792411179a9cd986b3f3 (patch) | |
| tree | 79d7c002f24eae80bf9d274e081ea1f7435e27e7 /src/bin/git_remote_nostr | |
| parent | 20f2680394e0b62864b1b192338b3cd7ecdad4ec (diff) | |
refactor: move build state function
in preparation for enforcing the inclusion of HEAD
Diffstat (limited to 'src/bin/git_remote_nostr')
| -rw-r--r-- | src/bin/git_remote_nostr/push.rs | 37 |
1 files changed, 1 insertions, 36 deletions
diff --git a/src/bin/git_remote_nostr/push.rs b/src/bin/git_remote_nostr/push.rs index 56bf177..434dae9 100644 --- a/src/bin/git_remote_nostr/push.rs +++ b/src/bin/git_remote_nostr/push.rs | |||
| @@ -8,9 +8,7 @@ use std::{ | |||
| 8 | 8 | ||
| 9 | use anyhow::{Context, Result, anyhow, bail}; | 9 | use anyhow::{Context, Result, anyhow, bail}; |
| 10 | use auth_git2::GitAuthenticator; | 10 | use auth_git2::GitAuthenticator; |
| 11 | use client::{ | 11 | use client::{get_events_from_local_cache, get_state_from_cache, send_events, sign_event}; |
| 12 | STATE_KIND, get_events_from_local_cache, get_state_from_cache, send_events, sign_event, | ||
| 13 | }; | ||
| 14 | use console::Term; | 12 | use console::Term; |
| 15 | use git::{RepoActions, sha1_to_oid}; | 13 | use git::{RepoActions, sha1_to_oid}; |
| 16 | use git_events::{ | 14 | use git_events::{ |
| @@ -1549,39 +1547,6 @@ fn get_refspecs_from_push_batch(stdin: &Stdin, initial_refspec: &str) -> Result< | |||
| 1549 | Ok(refspecs) | 1547 | Ok(refspecs) |
| 1550 | } | 1548 | } |
| 1551 | 1549 | ||
| 1552 | trait BuildRepoState { | ||
| 1553 | async fn build( | ||
| 1554 | identifier: String, | ||
| 1555 | state: HashMap<String, String>, | ||
| 1556 | signer: &Arc<dyn NostrSigner>, | ||
| 1557 | ) -> Result<RepoState>; | ||
| 1558 | } | ||
| 1559 | impl BuildRepoState for RepoState { | ||
| 1560 | async fn build( | ||
| 1561 | identifier: String, | ||
| 1562 | state: HashMap<String, String>, | ||
| 1563 | signer: &Arc<dyn NostrSigner>, | ||
| 1564 | ) -> Result<RepoState> { | ||
| 1565 | let mut tags = vec![Tag::identifier(identifier.clone())]; | ||
| 1566 | for (name, value) in &state { | ||
| 1567 | tags.push(Tag::custom(nostr_sdk::TagKind::Custom(name.into()), vec![ | ||
| 1568 | value.clone(), | ||
| 1569 | ])); | ||
| 1570 | } | ||
| 1571 | let event = sign_event( | ||
| 1572 | EventBuilder::new(STATE_KIND, "").tags(tags), | ||
| 1573 | signer, | ||
| 1574 | "git state".to_string(), | ||
| 1575 | ) | ||
| 1576 | .await?; | ||
| 1577 | Ok(RepoState { | ||
| 1578 | identifier, | ||
| 1579 | state, | ||
| 1580 | event, | ||
| 1581 | }) | ||
| 1582 | } | ||
| 1583 | } | ||
| 1584 | |||
| 1585 | #[cfg(test)] | 1550 | #[cfg(test)] |
| 1586 | mod tests { | 1551 | mod tests { |
| 1587 | use super::*; | 1552 | use super::*; |