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:
parent
41ebdea415
commit
1c55c02106
4 changed files with 32 additions and 29 deletions
|
@ -20,6 +20,7 @@ use std::io::Write;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::sync::{Arc, Mutex, MutexGuard};
|
use std::sync::{Arc, Mutex, MutexGuard};
|
||||||
|
|
||||||
|
use itertools::Itertools;
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
use crate::backend::{Backend, BackendError, CommitId};
|
use crate::backend::{Backend, BackendError, CommitId};
|
||||||
|
@ -34,6 +35,7 @@ use crate::local_backend::LocalBackend;
|
||||||
use crate::op_heads_store::OpHeadsStore;
|
use crate::op_heads_store::OpHeadsStore;
|
||||||
use crate::op_store::{BranchTarget, OpStore, OperationId, RefTarget};
|
use crate::op_store::{BranchTarget, OpStore, OperationId, RefTarget};
|
||||||
use crate::operation::Operation;
|
use crate::operation::Operation;
|
||||||
|
use crate::revset::RevsetExpression;
|
||||||
use crate::rewrite::DescendantRebaser;
|
use crate::rewrite::DescendantRebaser;
|
||||||
use crate::settings::{RepoSettings, UserSettings};
|
use crate::settings::{RepoSettings, UserSettings};
|
||||||
use crate::simple_op_store::SimpleOpStore;
|
use crate::simple_op_store::SimpleOpStore;
|
||||||
|
@ -799,6 +801,33 @@ impl MutableRepo {
|
||||||
self.invalidate_evolution();
|
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> {
|
pub fn get_branch(&self, name: &str) -> Option<&BranchTarget> {
|
||||||
self.view.get_branch(name)
|
self.view.get_branch(name)
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,7 +72,8 @@ impl Transaction {
|
||||||
/// That means that a repo can be loaded at the operation, but the
|
/// That means that a repo can be loaded at the operation, but the
|
||||||
/// operation will not be seen when loading the repo at head.
|
/// operation will not be seen when loading the repo at head.
|
||||||
pub fn write(mut self) -> UnpublishedOperation {
|
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 base_repo = mut_repo.base_repo().clone();
|
||||||
let (mut_index, view, maybe_mut_evolution) = mut_repo.consume();
|
let (mut_index, view, maybe_mut_evolution) = mut_repo.consume();
|
||||||
let maybe_evolution =
|
let maybe_evolution =
|
||||||
|
|
|
@ -188,6 +188,6 @@ fn test_isolation(use_git: bool) {
|
||||||
let repo = repo.reload();
|
let repo = repo.reload();
|
||||||
assert_heads(
|
assert_heads(
|
||||||
repo.as_repo_ref(),
|
repo.as_repo_ref(),
|
||||||
vec![&wc_id, initial.id(), rewrite1.id(), rewrite2.id()],
|
vec![&wc_id, rewrite1.id(), rewrite2.id()],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -453,38 +453,11 @@ impl RepoCommandHelper {
|
||||||
if self.auto_update_branches {
|
if self.auto_update_branches {
|
||||||
update_branches_after_rewrite(mut_repo);
|
update_branches_after_rewrite(mut_repo);
|
||||||
}
|
}
|
||||||
remove_hidden_heads(mut_repo);
|
|
||||||
self.repo = tx.commit();
|
self.repo = tx.commit();
|
||||||
update_working_copy(ui, &self.repo, &self.repo.working_copy_locked())
|
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> {
|
fn rev_arg<'a, 'b>() -> Arg<'a, 'b> {
|
||||||
Arg::with_name("revision")
|
Arg::with_name("revision")
|
||||||
.long("revision")
|
.long("revision")
|
||||||
|
|
Loading…
Reference in a new issue