diff --git a/rust/hg-core/src/dirstate_tree/dirstate_map.rs b/rust/hg-core/src/dirstate_tree/dirstate_map.rs --- a/rust/hg-core/src/dirstate_tree/dirstate_map.rs +++ b/rust/hg-core/src/dirstate_tree/dirstate_map.rs @@ -1337,7 +1337,9 @@ )? .and_then(|node| { if let Some(source) = &node.copy_source { - *count -= 1; + *count = count + .checked_sub(1) + .expect("nodes_with_copy_source_count should be >= 0"); DirstateMap::count_dropped_path(unreachable_bytes, source); } node.copy_source.take().map(Cow::into_owned)