upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src/git
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2026-01-07 12:58:01 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2026-01-07 12:58:01 +0000
commit37c9d3e0d195b0789f9e6407b81973cf50222b76 (patch)
treed4d14e833a2fc78bfb7418cfe0ac5d4d80366493 /src/git
parentd78d3a86ba81a5b59cde527a448f5c9d131db8d6 (diff)
purgatory: improve process_newly_available_git_data state event sync
Diffstat (limited to 'src/git')
-rw-r--r--src/git/sync.rs38
1 files changed, 13 insertions, 25 deletions
diff --git a/src/git/sync.rs b/src/git/sync.rs
index e57a0cc..cf6e93d 100644
--- a/src/git/sync.rs
+++ b/src/git/sync.rs
@@ -43,7 +43,7 @@ use crate::git::authorization::{
43use crate::git::{self, oid_exists}; 43use crate::git::{self, oid_exists};
44use crate::nostr::builder::SharedDatabase; 44use crate::nostr::builder::SharedDatabase;
45use crate::nostr::events::RepositoryState; 45use crate::nostr::events::RepositoryState;
46use crate::purgatory::{can_satisfy_state, Purgatory}; 46use crate::purgatory::{can_apply_state, Purgatory};
47 47
48/// Result of processing newly available git data. 48/// Result of processing newly available git data.
49/// 49///
@@ -837,15 +837,9 @@ pub async fn process_newly_available_git_data(
837 "Processing newly available git data" 837 "Processing newly available git data"
838 ); 838 );
839 839
840 // Get current refs from the repository for state matching
841 let current_refs: HashMap<String, String> = git::list_refs(source_repo_path)
842 .unwrap_or_default()
843 .into_iter()
844 .collect();
845
846 // Process state events from purgatory 840 // Process state events from purgatory
847 let state_result = 841 let state_result =
848 process_purgatory_state_events(&identifier, source_repo_path, &current_refs, database, local_relay, purgatory, git_data_path).await; 842 process_purgatory_state_events(&identifier, source_repo_path, database, local_relay, purgatory, git_data_path).await;
849 result.merge(state_result); 843 result.merge(state_result);
850 844
851 // Process PR events from purgatory 845 // Process PR events from purgatory
@@ -866,11 +860,15 @@ pub async fn process_newly_available_git_data(
866 Ok(result) 860 Ok(result)
867} 861}
868 862
869/// Process state events from purgatory that can now be satisfied. 863/// Process state events from purgatory that can now be applied.
864///
865/// This checks if we have all the git OIDs needed to apply each state event.
866/// Unlike push authorization (which uses `can_satisfy_state` to check if a push
867/// would transform refs correctly), this uses `can_apply_state` to simply check
868/// if the required git data is available.
870async fn process_purgatory_state_events( 869async fn process_purgatory_state_events(
871 identifier: &str, 870 identifier: &str,
872 source_repo_path: &Path, 871 source_repo_path: &Path,
873 current_refs: &HashMap<String, String>,
874 database: &SharedDatabase, 872 database: &SharedDatabase,
875 local_relay: Option<&nostr_relay_builder::LocalRelay>, 873 local_relay: Option<&nostr_relay_builder::LocalRelay>,
876 purgatory: &Purgatory, 874 purgatory: &Purgatory,
@@ -887,27 +885,17 @@ async fn process_purgatory_state_events(
887 debug!( 885 debug!(
888 identifier = %identifier, 886 identifier = %identifier,
889 purgatory_states_count = purgatory_states.len(), 887 purgatory_states_count = purgatory_states.len(),
890 "Checking purgatory state events for satisfaction" 888 "Checking purgatory state events for available git data"
891 ); 889 );
892 890
893 // Build ref updates from current refs (treating all as "creations" for matching purposes) 891 // Check which state events can be applied (have all required OIDs)
894 let ref_updates: Vec<crate::purgatory::RefUpdate> = current_refs
895 .iter()
896 .map(|(ref_name, commit)| crate::purgatory::RefUpdate {
897 old_oid: "0000000000000000000000000000000000000000".to_string(),
898 new_oid: commit.clone(),
899 ref_name: ref_name.clone(),
900 })
901 .collect();
902
903 // Check which state events can be satisfied
904 for entry in &purgatory_states { 892 for entry in &purgatory_states {
905 // Check if this state event can be satisfied with current refs 893 // Check if we have all the git data needed to apply this state event
906 if !can_satisfy_state(&entry.event, &ref_updates, current_refs) { 894 if !can_apply_state(&entry.event, source_repo_path) {
907 debug!( 895 debug!(
908 identifier = %identifier, 896 identifier = %identifier,
909 event_id = %entry.event.id, 897 event_id = %entry.event.id,
910 "State event cannot be satisfied with current refs" 898 "State event cannot be applied - missing git OIDs"
911 ); 899 );
912 continue; 900 continue;
913 } 901 }