upleb.uk

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

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2026-01-05 13:10:14 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2026-01-05 13:10:14 +0000
commit8cb45487d7125a14d15c15dfc14b0804eb22ffd6 (patch)
treef0b67d9bd75dee7251347f402925770ba85575a0
parent623cae575f8c9ce33f2d7fdc2526db495f846acb (diff)
purgatory: state git data sync use single command to fetch oids
-rw-r--r--src/purgatory/mod.rs114
1 files changed, 53 insertions, 61 deletions
diff --git a/src/purgatory/mod.rs b/src/purgatory/mod.rs
index f0a9ac5..8634aff 100644
--- a/src/purgatory/mod.rs
+++ b/src/purgatory/mod.rs
@@ -581,72 +581,64 @@ async fn fetch_missing_oids_from_server(
581 let oids = missing_oids.to_vec(); 581 let oids = missing_oids.to_vec();
582 582
583 tokio::task::spawn_blocking(move || { 583 tokio::task::spawn_blocking(move || {
584 let mut fetched_count = 0; 584 // Filter to only OIDs that don't already exist
585 585 let missing: Vec<&String> = oids.iter().filter(|oid| !oid_exists(&repo_path, oid)).collect();
586 // Try to fetch each missing OID individually
587 // This uses git's ability to fetch specific commits
588 for oid in &oids {
589 // Skip if already exists
590 if oid_exists(&repo_path, oid) {
591 continue;
592 }
593 586
594 // git fetch <remote> <sha1> 587 if missing.is_empty() {
595 let output = Command::new("git") 588 return Ok(0);
596 .args(["fetch", "--depth=1", &server_url, oid])
597 .current_dir(&repo_path)
598 .output();
599
600 match output {
601 Ok(result) if result.status.success() => {
602 fetched_count += 1;
603 tracing::debug!(
604 oid = %oid,
605 server = %server_url,
606 "Successfully fetched OID"
607 );
608 }
609 Ok(result) => {
610 let stderr = String::from_utf8_lossy(&result.stderr);
611 tracing::debug!(
612 oid = %oid,
613 server = %server_url,
614 stderr = %stderr,
615 "git fetch failed for OID"
616 );
617 }
618 Err(e) => {
619 tracing::debug!(
620 oid = %oid,
621 server = %server_url,
622 error = %e,
623 "git fetch command error"
624 );
625 }
626 }
627 } 589 }
628 590
629 // If individual fetches didn't work, try a broader fetch 591 // git fetch <remote> <sha1> <sha2> ... - fetch all OIDs in one command
630 if fetched_count == 0 { 592 let mut args = vec!["fetch", "--depth=1", &server_url];
631 // Try fetching all refs - this might get us the commits we need 593 args.extend(missing.iter().map(|s| s.as_str()));
632 let output = Command::new("git") 594
633 .args(["fetch", "--all", "--tags", &server_url]) 595 tracing::debug!(
634 .current_dir(&repo_path) 596 oids = ?missing,
635 .output(); 597 server = %server_url,
636 598 "Fetching OIDs"
637 if let Ok(result) = output { 599 );
638 if result.status.success() { 600
639 // Count how many OIDs we now have 601 let output = Command::new("git")
640 for oid in &oids { 602 .args(&args)
641 if oid_exists(&repo_path, oid) { 603 .current_dir(&repo_path)
642 fetched_count += 1; 604 .output();
643 } 605
644 } 606 match output {
645 } 607 Ok(result) if result.status.success() => {
608 // Count how many OIDs we now have
609 let fetched_count = missing
610 .iter()
611 .filter(|oid| oid_exists(&repo_path, oid))
612 .count();
613
614 tracing::debug!(
615 fetched_count = fetched_count,
616 server = %server_url,
617 "Successfully fetched OIDs"
618 );
619
620 Ok(fetched_count)
621 }
622 Ok(result) => {
623 let stderr = String::from_utf8_lossy(&result.stderr);
624 tracing::debug!(
625 oids = ?missing,
626 server = %server_url,
627 stderr = %stderr,
628 "git fetch failed for OIDs"
629 );
630 Ok(0)
631 }
632 Err(e) => {
633 tracing::debug!(
634 oids = ?missing,
635 server = %server_url,
636 error = %e,
637 "git fetch command error"
638 );
639 Ok(0)
646 } 640 }
647 } 641 }
648
649 Ok(fetched_count)
650 }) 642 })
651 .await? 643 .await?
652} 644}