From 38474a9fb91dbad20a3f5875a62dd075b4524de0 Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Sat, 25 Sep 2021 10:11:58 -0700 Subject: [PATCH] cli: remove non-visible heads after every operation This makes it so that almost every command will remove non-visible heads. That shouldn't have much visible effect, except that the `all_heads()` revset will become the same as `non_obsolete_heads()`. It will help us remove support for evolution by cleaning up existing repos. Existing repos (like mine) will lose the unwanted heads (~8.5k heads in my case), so they don't clutter the repo once evolution is gone. This is part of issue #32. --- src/commands.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/commands.rs b/src/commands.rs index 08b999a9b..7325beb4a 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -471,11 +471,38 @@ impl RepoCommandHelper { if self.auto_update_branches { update_branches_after_rewrite(mut_repo); } + remove_hidden_heads(mut_repo); self.repo = tx.commit(); update_working_copy(ui, &self.repo, &self.repo.working_copy_locked()) } } +fn remove_hidden_heads(mut_repo: &mut MutableRepo) { + let mut view = mut_repo.view().store_view().clone(); + let heads_expression = + RevsetExpression::commits(view.head_ids.iter().cloned().collect_vec()).non_obsolete_heads(); + let public_heads_expression = + RevsetExpression::commits(view.public_head_ids.iter().cloned().collect_vec()) + .non_obsolete_heads(); + view.head_ids.clear(); + view.public_head_ids.clear(); + for index_entry in heads_expression + .evaluate(mut_repo.as_repo_ref()) + .unwrap() + .iter() + { + view.head_ids.insert(index_entry.commit_id()); + } + for index_entry in public_heads_expression + .evaluate(mut_repo.as_repo_ref()) + .unwrap() + .iter() + { + view.public_head_ids.insert(index_entry.commit_id()); + } + mut_repo.set_view(view) +} + fn rev_arg<'a, 'b>() -> Arg<'a, 'b> { Arg::with_name("revision") .long("revision")