MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / insert_changes

Method insert_changes

libatomic/src/daemon/services.rs:2258–2666  ·  view source on GitHub ↗
(
        &self,
        request: Request<InsertChangesRequest>,
    )

Source from the content-addressed store, hash-verified

2256 }
2257
2258 async fn insert_changes(
2259 &self,
2260 request: Request<InsertChangesRequest>,
2261 ) -> Result<Response<InsertChangesResponse>, Status> {
2262 let request = request.into_inner();
2263 let handle = self
2264 .state
2265 .resolve(request.repository.as_ref().unwrap_or(&default_ref()))?;
2266 self.state.log_rpc("InsertChanges", Some(&handle));
2267 let gate_handle = handle.clone();
2268 let _gate = gate_handle.exclusive().await;
2269 let result =
2270 tokio::task::spawn_blocking(move || -> Result<InsertChangesResponse, Status> {
2271 // A stale insertion must not reconcile or capture the working
2272 // copy before its refusal. The second check below still fences
2273 // the mutation after workspace entry; dry runs remain reads.
2274 if !request.dry_run.unwrap_or(false) {
2275 if let Some(expected) = &request.expected_snapshot {
2276 let repo = handle.repository_readonly()?;
2277 let working_copy =
2278 repo.require_working_copy_id().map_err(repository_error)?;
2279 let target = match &request.target_view {
2280 Some(target) => target.clone(),
2281 None => repo
2282 .desired_view_name(working_copy)
2283 .map_err(repository_error)?,
2284 };
2285 check_view_fence(&repo, &target, expected)?;
2286 }
2287 }
2288 let (repo, workspace) =
2289 handle.workspace_repository(if request.dry_run.unwrap_or(false) {
2290 atomic_repository::WorkspaceTxnMode::Observe
2291 } else {
2292 atomic_repository::WorkspaceTxnMode::Reconcile
2293 })?;
2294 let working_copy = workspace.working_copy();
2295 // The target defaults to the repository's current view (the
2296 // wire's target_view is a display hint that must agree).
2297 let target = request
2298 .target_view
2299 .clone()
2300 .unwrap_or_else(|| workspace.view().name.clone());
2301 // The fence: the target view must be at the state the
2302 // caller last saw — two concurrent inserters (two
2303 // expeditions merging into the same view) can't both
2304 // land on a stale read silently. Dry runs read only and
2305 // don't fence.
2306 if !request.dry_run.unwrap_or(false) {
2307 if let Some(expected) = &request.expected_snapshot {
2308 check_view_fence(&repo, &target, expected)?;
2309 }
2310 }
2311 let dry_run = request.dry_run.unwrap_or(false);
2312 let apply_dependencies = request.apply_dependencies.unwrap_or(true);
2313 // Insert may refresh the current working copy below. Refuse
2314 // before publishing any membership, rather than overwriting
2315 // edits (including untracked files) during materialization.

Calls 15

default_refFunction · 0.85
check_view_fenceFunction · 0.85
domain_statusFunction · 0.85
wire_hashFunction · 0.85
single_insertFunction · 0.85
resolve_change_referenceFunction · 0.85
change_infoFunction · 0.85
bare_change_infoFunction · 0.85
as_refMethod · 0.80
log_rpcMethod · 0.80
exclusiveMethod · 0.80