diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2024-07-31 17:14:25 +0100 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2024-07-31 17:14:25 +0100 |
| commit | 1180f0b3c3157b6fd8eb7bf08a255a114e961e5f (patch) | |
| tree | 8bb6bd9a0382e1395b4ef3b124e98461cf9c8683 /src/repo_state.rs | |
| parent | 3acdeabfc3ab55d3e92d76d92d8ab6ad0383dd09 (diff) | |
fix(remote): updating `push` state event
ensure refs are included in state event
use `HashMap` to improve `RepoState` struct
Diffstat (limited to 'src/repo_state.rs')
| -rw-r--r-- | src/repo_state.rs | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/repo_state.rs b/src/repo_state.rs index 0c1aa30..a5cebab 100644 --- a/src/repo_state.rs +++ b/src/repo_state.rs | |||
| @@ -1,9 +1,11 @@ | |||
| 1 | use std::collections::HashMap; | ||
| 2 | |||
| 1 | use anyhow::{Context, Result}; | 3 | use anyhow::{Context, Result}; |
| 2 | use git2::Oid; | 4 | use git2::Oid; |
| 3 | 5 | ||
| 4 | pub struct RepoState { | 6 | pub struct RepoState { |
| 5 | pub identifier: String, | 7 | pub identifier: String, |
| 6 | pub state: Vec<(String, String)>, | 8 | pub state: HashMap<String, String>, |
| 7 | pub event: nostr::Event, | 9 | pub event: nostr::Event, |
| 8 | } | 10 | } |
| 9 | 11 | ||
| @@ -11,7 +13,7 @@ impl RepoState { | |||
| 11 | pub fn try_from(mut state_events: Vec<nostr::Event>) -> Result<Self> { | 13 | pub fn try_from(mut state_events: Vec<nostr::Event>) -> Result<Self> { |
| 12 | state_events.sort_by_key(|e| e.created_at); | 14 | state_events.sort_by_key(|e| e.created_at); |
| 13 | let event = state_events.first().context("no state events")?; | 15 | let event = state_events.first().context("no state events")?; |
| 14 | let mut state = vec![]; | 16 | let mut state = HashMap::new(); |
| 15 | for tag in &event.tags { | 17 | for tag in &event.tags { |
| 16 | if let Some(name) = tag.as_vec().first() { | 18 | if let Some(name) = tag.as_vec().first() { |
| 17 | if ["refs/heads/", "refs/tags", "HEAD"] | 19 | if ["refs/heads/", "refs/tags", "HEAD"] |
| @@ -19,8 +21,8 @@ impl RepoState { | |||
| 19 | .any(|s| name.starts_with(*s)) | 21 | .any(|s| name.starts_with(*s)) |
| 20 | { | 22 | { |
| 21 | if let Some(value) = tag.as_vec().get(1) { | 23 | if let Some(value) = tag.as_vec().get(1) { |
| 22 | if Oid::from_str(value).is_ok() { | 24 | if Oid::from_str(value).is_ok() || value.contains("ref: refs/") { |
| 23 | state.push((name.to_owned(), value.to_owned())); | 25 | state.insert(name.to_owned(), value.to_owned()); |
| 24 | } | 26 | } |
| 25 | } | 27 | } |
| 26 | } | 28 | } |