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

Method get_incremental_markers

atomic-cli/src/commands/git/import.rs:488–592  ·  view source on GitHub ↗

Get the set of already imported Git SHAs from existing changes, plus the Merkle states already present in the import target view. The states let the importer skip commits created by `atomic git push`: such a commit trailers the view state it represents, and if that state is already known the commit adds nothing. `repair_index` controls the best-effort Git SHA index repair. Real imports pass `tru

(
        &self,
        repo: &Repository,
        view_name: &str,
        repair_index: bool,
    )

Source from the content-addressed store, hash-verified

486 /// imports pass `true`; the `--dry-run` forecast passes `false` so it can
487 /// compute markers against a read-only handle without writing anything.
488 fn get_incremental_markers(
489 &self,
490 repo: &Repository,
491 view_name: &str,
492 repair_index: bool,
493 ) -> CliResult<(HashSet<String>, HashSet<atomic_core::types::Merkle>)> {
494 let started = std::time::Instant::now();
495 // CB-6C: the GIT_SHA_INDEX is a checked cache, never authority. Every
496 // row is validated against hash-authoritative change bytes before it
497 // may act as an import marker; stale rows are repaired and invalid
498 // rows are dropped, so a corrupt cache produces exactly the same
499 // skip decisions as a cold cache (the legacy backfill below).
500 let (indexed, dropped) = repo
501 .checked_git_sha_marker_hashes()
502 .map_err(|error| CliError::Internal(error.into()))?;
503 for sha in dropped.iter().take(3) {
504 log::warn!(
505 "Dropped unverifiable GIT_SHA_INDEX row for {} (same treatment as a cold cache)",
506 &sha[..8.min(sha.len())]
507 );
508 }
509 let mut states = HashSet::new();
510 let mut index_repairs = Vec::new();
511
512 // Query the target's effective root-to-leaf states without opening every
513 // historical change file. Imported SHAs come from GIT_SHA_INDEX, making
514 // the normal one-commit incremental path a single B-tree scan. Only
515 // repositories with no index rows take the legacy backfill path.
516 let entries = repo
517 .effective_history(Some(view_name))
518 .map_err(|error| CliError::Internal(error.into()))?;
519 let needs_legacy_backfill = indexed.is_empty() && !entries.is_empty();
520 // The index is repository-wide, but a marker only skips a commit for
521 // THIS view when the commit's change is a member of this view. A
522 // commit interpreted under another branch's view (a feature branch
523 // that `main` later fast-forwards onto) is not imported here yet;
524 // the writer references its existing change into the target view
525 // instead of re-synthesizing it.
526 let view_members: HashSet<atomic_core::types::Hash> =
527 entries.iter().map(|entry| entry.hash).collect();
528 let mut shas: HashSet<String> = indexed
529 .into_iter()
530 .filter(|(_, hash)| view_members.contains(hash))
531 .map(|(sha, _)| sha)
532 .collect();
533 for entry in entries {
534 states.insert(entry.state);
535 if !needs_legacy_backfill {
536 continue;
537 }
538 let change = repo
539 .load_change(&entry.hash)
540 .map_err(|error| CliError::Internal(error.into()))?;
541 if let Some(ref unhashed) = change.unhashed {
542 if let Some(git) = unhashed.get("git") {
543 if let Some(sha) = git.get("sha").and_then(|v| v.as_str()) {
544 if shas.insert(sha.to_string()) {
545 index_repairs.push((sha.to_string(), entry.hash));

Callers 1

run_importMethod · 0.80

Calls 15

trace_git_importFunction · 0.85
effective_historyMethod · 0.80
list_tags_for_viewMethod · 0.80
as_refMethod · 0.80
index_git_shasMethod · 0.80
getMethod · 0.65
iterMethod · 0.45
is_emptyMethod · 0.45
collectMethod · 0.45
into_iterMethod · 0.45
containsMethod · 0.45

Tested by

no test coverage detected