From ea7a6b9ce16608bbe8c1245f575e19595132247d Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Wed, 23 Dec 2020 17:21:26 -0800 Subject: [PATCH] evolution: keep track of non-obsolete commits per change id I'm about to make the evolution state updated incrementally. To be able to tell if a new commit is divergent, we'll need to keep track of already existing, non-obsolete commits in the change, even if they're not divergent before the new commit is added. --- lib/src/evolution.rs | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/lib/src/evolution.rs b/lib/src/evolution.rs index c7ca2f3c8..6fd314ab5 100644 --- a/lib/src/evolution.rs +++ b/lib/src/evolution.rs @@ -37,7 +37,9 @@ struct State { obsolete_commits: HashSet, pruned_commits: HashSet, orphan_commits: HashSet, - divergent_changes: HashMap>, + /// If there's more than one element in the value, then the change is + /// divergent. + non_obsoletes_by_changeid: HashMap>, } impl State { @@ -83,15 +85,15 @@ impl State { } } } - // Find divergent commits + // Find non-obsolete commits by change id (potentially divergent commits) for (change_id, commit_ids) in change_to_commits { - let divergent: HashSet = commit_ids + let non_obsoletes: HashSet = commit_ids .difference(&state.obsolete_commits) .cloned() .collect(); - if divergent.len() > 1 { - state.divergent_changes.insert(change_id, divergent); - } + state + .non_obsoletes_by_changeid + .insert(change_id, non_obsoletes); } // Find orphans by walking to the children of obsolete commits let mut work: Vec = state.obsolete_commits.iter().cloned().collect(); @@ -133,7 +135,9 @@ impl State { } fn is_divergent(&self, change_id: &ChangeId) -> bool { - self.divergent_changes.contains_key(change_id) + self.non_obsoletes_by_changeid + .get(change_id) + .map_or(false, |non_obsoletes| non_obsoletes.len() > 1) } pub fn new_parent(&self, store: &StoreWrapper, old_parent_id: &CommitId) -> HashSet { @@ -357,8 +361,9 @@ pub fn evolve( .as_repo_mut() .evolution_mut() .state - .divergent_changes + .non_obsoletes_by_changeid .values() + .filter(|non_obsoletes| non_obsoletes.len() > 1) .cloned() .collect(); for commit_ids in divergent_changes {