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

Method remove_batch

atomic-repository/src/repository/tracking.rs:340–395  ·  view source on GitHub ↗

Remove multiple files from tracking in a single write transaction. This is much faster than calling `remove()` in a loop because it avoids a separate write transaction (and fsync) for each file. # Arguments `working_copy` - Identity of the physical working copy being updated `paths` - Paths to remove (relative to repository root) # Returns Number of files actually removed.

(
        &self,
        working_copy: WorkingCopyId,
        paths: &[&str],
    )

Source from the content-addressed store, hash-verified

338 ///
339 /// Number of files actually removed.
340 pub fn remove_batch(
341 &self,
342 working_copy: WorkingCopyId,
343 paths: &[&str],
344 ) -> Result<usize, RepositoryError> {
345 use crate::tracking::{TreeProjectionOperation, TreeProjectionPlan};
346 self.validate_working_copy(working_copy)?;
347 if paths.is_empty() {
348 return Ok(0);
349 }
350
351 let mut txn = self
352 .pristine
353 .write_txn()
354 .map_err(|e| RepositoryError::Database(e.to_string()))?;
355
356 // Performance: one tree projection for the whole batch (see
357 // add_batch — per-path planning rescans the full TREE table).
358 let mut operations: Vec<TreeProjectionOperation> = Vec::with_capacity(paths.len());
359 let mut planned: std::collections::HashSet<String> = std::collections::HashSet::new();
360 let mut count = 0usize;
361 for path in paths {
362 let normalized = normalize_path(Path::new(path));
363 if planned.contains(&normalized) {
364 continue;
365 }
366 planned.insert(normalized.clone());
367 if let Some(inode) = crate::tracking::get_inode(&txn, &normalized)
368 .map_err(|e| RepositoryError::Database(e.to_string()))?
369 {
370 // Recorded bindings belong to their change (see `remove`); plan
371 // only the staged ones so the batch never orphans a live claim.
372 if tracked_path_state(&txn, inode)
373 .map_err(|e| RepositoryError::Database(e.to_string()))?
374 == TrackedPathState::Recorded
375 {
376 continue;
377 }
378 operations.push(TreeProjectionOperation::Delete {
379 inode,
380 retire: true,
381 });
382 count += 1;
383 }
384 }
385
386 TreeProjectionPlan::plan(&txn, operations)
387 .map_err(|e| RepositoryError::Database(e.to_string()))?
388 .apply(&mut txn)
389 .map_err(|e| RepositoryError::Database(e.to_string()))?;
390
391 txn.commit()
392 .map_err(|e| RepositoryError::Database(e.to_string()))?;
393
394 Ok(count)
395 }
396
397 /// Add an empty directory to tracking explicitly.

Calls 14

get_inodeFunction · 0.85
tracked_path_stateFunction · 0.85
planFunction · 0.85
validate_working_copyMethod · 0.80
write_txnMethod · 0.80
normalize_pathFunction · 0.50
is_emptyMethod · 0.45
lenMethod · 0.45
containsMethod · 0.45
insertMethod · 0.45
cloneMethod · 0.45
pushMethod · 0.45