Enumerate the stored bindings still missing a local create-only ref and publish up to `max` of them in deterministic (id-hex) order. Each publication reuses [`Repository::publish_binding`] — the journaled CAS path with its immutable receipt — so an interrupted run replays idempotently: already-created refs are observed identical and skipped. A ref that exists with a *different* binding is a creat
(
repo: &Repository,
working_copy: WorkingCopyId,
git: &GitRepository,
max: usize,
)
| 168 | /// A ref that exists with a *different* binding is a create-only violation |
| 169 | /// and aborts the run without overwriting it. |
| 170 | pub fn run_local_publish_queue( |
| 171 | repo: &Repository, |
| 172 | working_copy: WorkingCopyId, |
| 173 | git: &GitRepository, |
| 174 | max: usize, |
| 175 | ) -> CliResult<QueueOutcome> { |
| 176 | let mut outcome = QueueOutcome::default(); |
| 177 | let mut ids: Vec<atomic_repository::git_binding::BindingId> = |
| 178 | repo.binding_ids().map_err(CliError::Repository)?; |
| 179 | ids.sort_by_key(|id| id.to_hex()); |
| 180 | for id in ids { |
| 181 | if outcome.published >= max { |
| 182 | break; |
| 183 | } |
| 184 | let Some(binding) = repo.load_binding(&id).map_err(CliError::Repository)? else { |
| 185 | outcome.unresolvable += 1; |
| 186 | outcome.refs.push(Repository::binding_ref_name(&id)); |
| 187 | continue; |
| 188 | }; |
| 189 | let ref_name = Repository::binding_ref_name(&id); |
| 190 | outcome.refs.push(ref_name.clone()); |
| 191 | // Create-only invariant: an existing ref may only already hold THIS |
| 192 | // binding, and only when its full carrier validates — the exact |
| 193 | // immutable parentless commit, an allowlisted tree, and valid public |
| 194 | // payloads. A ref carrying any other binding, a hostile carrier, or |
| 195 | // undecodable bytes would leak every reachable object on transfer: |
| 196 | // refused, never overwritten, never transferred. |
| 197 | match repo.verify_published_binding_carrier(git, &id) { |
| 198 | Ok(Some(verified)) => { |
| 199 | if verified.binding.encode() != binding.encode() { |
| 200 | return Err(CliError::GitError { |
| 201 | message: format!( |
| 202 | "binding ref '{ref_name}' publishes binding {} with bytes differing \ |
| 203 | from the stored binding; refusing to treat it as present or to \ |
| 204 | transfer it", |
| 205 | id.to_hex() |
| 206 | ), |
| 207 | }); |
| 208 | } |
| 209 | outcome.already_present += 1; |
| 210 | continue; |
| 211 | } |
| 212 | Ok(None) => {} |
| 213 | Err(error) => { |
| 214 | return Err(CliError::GitError { |
| 215 | message: format!( |
| 216 | "binding ref '{ref_name}' exists but is not a verifiable carrier of \ |
| 217 | stored binding {} (create-only violation, refusing to transfer or \ |
| 218 | overwrite): {error}", |
| 219 | id.to_hex() |
| 220 | ), |
| 221 | }); |
| 222 | } |
| 223 | } |
| 224 | match repo |
| 225 | .publish_binding(working_copy, git, &binding, None) |
| 226 | .map_err(CliError::Repository)? |
| 227 | { |
no test coverage detected