From e1fd69cfa89642aa0e4d80dd0e045ba3b84b3cb8 Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Sat, 25 Sep 2021 00:17:54 -0700 Subject: [PATCH] evolution: don't crash when commit is no longer in view's set of heads If you rewrite a change twice, from A to A' to A'', then undo the operation that created A', you'll end up with a repo where A'' refers to commit (A') that's not reachable from any head in the view. We currently crash when that happens. This change fixes the crash. Undoing the A' operation now instead produces a state where A and A'' are divergent. That at least makes some sense. This may not seem important since I'm working on removing support for evolution (#32), but I wanted to get it fixed in order to help with the transition off of evolution. Specifically, I want to be able to start removing old heads more freely. This closes #28. --- lib/src/evolution.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/src/evolution.rs b/lib/src/evolution.rs index abebb7ec5..de8f01cd9 100644 --- a/lib/src/evolution.rs +++ b/lib/src/evolution.rs @@ -101,9 +101,11 @@ impl State { work.extend(state.pruned_commits.iter().cloned()); while !work.is_empty() { let commit_id = work.pop().unwrap(); - for child in state.children.get(&commit_id).unwrap() { - if state.orphan_commits.insert(child.clone()) { - work.push(child.clone()); + if let Some(children) = state.children.get(&commit_id) { + for child in children { + if state.orphan_commits.insert(child.clone()) { + work.push(child.clone()); + } } } }