ok/jj
1
0
Fork 0
forked from mirrors/jj

Transaction: remove hidden heads on commit

I recently made the CLI remove hidden heads when a transaction is
committed (38474a9). Let's move that to `Transaction::commit()`, so
the library crate becomes more similar to how the CLI behaves and more
similar to our evolution-less future (#32).
This commit is contained in:
Martin von Zweigbergk 2021-10-02 22:39:49 -07:00
parent 41ebdea415
commit 1c55c02106
4 changed files with 32 additions and 29 deletions

View file

@ -20,6 +20,7 @@ use std::io::Write;
use std::path::{Path, PathBuf};
use std::sync::{Arc, Mutex, MutexGuard};
use itertools::Itertools;
use thiserror::Error;
use crate::backend::{Backend, BackendError, CommitId};
@ -34,6 +35,7 @@ use crate::local_backend::LocalBackend;
use crate::op_heads_store::OpHeadsStore;
use crate::op_store::{BranchTarget, OpStore, OperationId, RefTarget};
use crate::operation::Operation;
use crate::revset::RevsetExpression;
use crate::rewrite::DescendantRebaser;
use crate::settings::{RepoSettings, UserSettings};
use crate::simple_op_store::SimpleOpStore;
@ -799,6 +801,33 @@ impl MutableRepo {
self.invalidate_evolution();
}
pub fn remove_hidden_heads(&mut self) {
let mut view = self.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(self.as_repo_ref())
.unwrap()
.iter()
{
view.head_ids.insert(index_entry.commit_id());
}
for index_entry in public_heads_expression
.evaluate(self.as_repo_ref())
.unwrap()
.iter()
{
view.public_head_ids.insert(index_entry.commit_id());
}
self.set_view(view)
}
pub fn get_branch(&self, name: &str) -> Option<&BranchTarget> {
self.view.get_branch(name)
}

View file

@ -72,7 +72,8 @@ impl Transaction {
/// That means that a repo can be loaded at the operation, but the
/// operation will not be seen when loading the repo at head.
pub fn write(mut self) -> UnpublishedOperation {
let mut_repo = self.repo.take().unwrap();
let mut mut_repo = self.repo.take().unwrap();
mut_repo.remove_hidden_heads();
let base_repo = mut_repo.base_repo().clone();
let (mut_index, view, maybe_mut_evolution) = mut_repo.consume();
let maybe_evolution =

View file

@ -188,6 +188,6 @@ fn test_isolation(use_git: bool) {
let repo = repo.reload();
assert_heads(
repo.as_repo_ref(),
vec![&wc_id, initial.id(), rewrite1.id(), rewrite2.id()],
vec![&wc_id, rewrite1.id(), rewrite2.id()],
);
}

View file

@ -453,38 +453,11 @@ 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")