Repo-write half of [`reconcile_after_fetch`]: apply a fetched identity document to the local repository. Skip entirely when nothing was fetched.
(
repo: &Repository,
document: &serde_json::Value,
)
| 116 | /// Repo-write half of [`reconcile_after_fetch`]: apply a fetched identity |
| 117 | /// document to the local repository. Skip entirely when nothing was fetched. |
| 118 | pub fn apply_fetched_identity( |
| 119 | repo: &Repository, |
| 120 | document: &serde_json::Value, |
| 121 | ) -> Result<ReconcileReport, RepositoryError> { |
| 122 | let mut report = ReconcileReport::default(); |
| 123 | let record = match record_from_document(document) { |
| 124 | Ok(record) => record, |
| 125 | Err(error) => { |
| 126 | tracing::info!("project-identity adoption skipped: {error}"); |
| 127 | return Ok(report); |
| 128 | } |
| 129 | }; |
| 130 | match repo.adopt_remote_project_identity(&record)? { |
| 131 | atomic_repository::IdentityAdoption::Adopted => { |
| 132 | report.adopted = Some( |
| 133 | record |
| 134 | .project_id() |
| 135 | .map_err(|e| RepositoryError::InvalidOperation { |
| 136 | message: e.to_string(), |
| 137 | })? |
| 138 | .to_base32(), |
| 139 | ); |
| 140 | } |
| 141 | atomic_repository::IdentityAdoption::ReplacedUpgrade => { |
| 142 | report.adopted = Some( |
| 143 | record |
| 144 | .project_id() |
| 145 | .map_err(|e| RepositoryError::InvalidOperation { |
| 146 | message: e.to_string(), |
| 147 | })? |
| 148 | .to_base32(), |
| 149 | ); |
| 150 | report.replaced_upgrade = true; |
| 151 | // The adopted id re-keys every project-qualified IRI: rebuild the |
| 152 | // derived graph before anything reads it. |
| 153 | repo.rebuild_kg(false)?; |
| 154 | } |
| 155 | atomic_repository::IdentityAdoption::AlreadyCurrent => {} |
| 156 | atomic_repository::IdentityAdoption::Diverged => { |
| 157 | let remote_id = record |
| 158 | .project_id() |
| 159 | .map_err(|e| RepositoryError::InvalidOperation { |
| 160 | message: e.to_string(), |
| 161 | })?; |
| 162 | let local_id = repo |
| 163 | .project_id() |
| 164 | .map_err(|e| RepositoryError::InvalidOperation { |
| 165 | message: e.to_string(), |
| 166 | })?; |
| 167 | report.diverged = Some((remote_id.to_base32(), local_id.to_base32())); |
| 168 | } |
| 169 | } |
| 170 | Ok(report) |
| 171 | } |
| 172 | |
| 173 | /// The outcome of a pre-push bind attempt. |
| 174 | #[derive(Debug, Clone, PartialEq, Eq)] |
no test coverage detected