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

Function detect_deepened_history

atomic-cli/src/commands/git/parallel.rs:2006–2058  ·  view source on GitHub ↗

Refuse to reinterpret prior sequencing after a shallow repository is deepened (CB-9A §7). For every collected commit that is not yet indexed in Atomic, refuse when it has an already-indexed *descendant* inside the collected closure: importing it now would fabricate a second, differently-derived history below changes the view already contains. Returns the count of deepened commits so callers can d

(
    git: &GitRepository,
    ordered_oids: &[Oid],
    indexed_shas: &HashSet<String>,
)

Source from the content-addressed store, hash-verified

2004/// commits so callers can diagnose; the walk order is the deterministic
2005/// shim order.
2006pub(crate) fn detect_deepened_history(
2007 git: &GitRepository,
2008 ordered_oids: &[Oid],
2009 indexed_shas: &HashSet<String>,
2010) -> CliResult<usize> {
2011 let collected: HashSet<Oid> = ordered_oids.iter().copied().collect();
2012 let mut children_of: HashMap<Oid, Vec<Oid>> = HashMap::with_capacity(ordered_oids.len());
2013 for oid in ordered_oids {
2014 let commit = git.find_commit(*oid).map_err(|error| {
2015 git_error(format!(
2016 "cannot read commit {oid} for deepening check: {error}"
2017 ))
2018 })?;
2019 for parent in commit.parent_ids() {
2020 if collected.contains(&parent) {
2021 children_of.entry(parent).or_default().push(*oid);
2022 }
2023 }
2024 }
2025
2026 // Newest → oldest: a commit is "below an indexed descendant" when it is
2027 // itself indexed or any child is.
2028 let mut below_indexed: HashSet<Oid> = HashSet::new();
2029 for oid in ordered_oids.iter().rev() {
2030 let indexed = indexed_shas.contains(&oid.to_string());
2031 let child_below = children_of
2032 .get(oid)
2033 .map(|children| children.iter().any(|child| below_indexed.contains(child)))
2034 .unwrap_or(false);
2035 if indexed || child_below {
2036 below_indexed.insert(*oid);
2037 }
2038 }
2039
2040 let mut deepened = Vec::new();
2041 for oid in ordered_oids {
2042 let sha = oid.to_string();
2043 if !indexed_shas.contains(&sha) && below_indexed.contains(oid) {
2044 deepened.push(sha);
2045 }
2046 }
2047 if deepened.is_empty() {
2048 return Ok(0);
2049 }
2050 Err(git_error(format!(
2051 "Git history deepened below already-imported commits: {} unindexed commit(s) (oldest \
2052 {}) sit below indexed descendants; deepening must never silently reinterpret prior \
2053 shim sequencing. Import the deepened history into a fresh view or explicitly \
2054 rebuild the affected view.",
2055 deepened.len(),
2056 deepened.last().cloned().unwrap_or_default()
2057 )))
2058}
2059
2060fn validate_import_tree_capabilities(
2061 git: &GitRepository,

Calls 9

git_errorFunction · 0.70
getMethod · 0.65
collectMethod · 0.45
iterMethod · 0.45
lenMethod · 0.45
containsMethod · 0.45
pushMethod · 0.45
insertMethod · 0.45
is_emptyMethod · 0.45