mirror of
https://github.com/martinvonz/jj.git
synced 2024-11-13 06:06:56 +03:00
transaction: remove index() and view() helpers
This commit is contained in:
parent
5ed14185a0
commit
16d97ef8c0
@ -12,6 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use std::collections::HashSet;
|
||||
use std::fmt::{Debug, Formatter};
|
||||
use std::fs;
|
||||
use std::fs::File;
|
||||
@ -611,6 +612,10 @@ impl<'r> MutableRepo<'r> {
|
||||
open_commit
|
||||
}
|
||||
|
||||
pub fn heads(&self) -> &HashSet<CommitId> {
|
||||
self.view.heads()
|
||||
}
|
||||
|
||||
fn enforce_view_invariants(&mut self) {
|
||||
let view = self.view.store_view_mut();
|
||||
// TODO: This is surely terribly slow on large repos, at least in its current
|
||||
|
@ -16,7 +16,6 @@ use std::sync::Arc;
|
||||
|
||||
use crate::commit::Commit;
|
||||
use crate::evolution::MutableEvolution;
|
||||
use crate::index::MutableIndex;
|
||||
use crate::op_heads_store::OpHeadsStore;
|
||||
use crate::op_store::{OperationId, OperationMetadata};
|
||||
use crate::operation::Operation;
|
||||
@ -24,7 +23,6 @@ use crate::repo::{MutableRepo, ReadonlyRepo, RepoRef};
|
||||
use crate::settings::UserSettings;
|
||||
use crate::store::{CommitId, Timestamp};
|
||||
use crate::store_wrapper::StoreWrapper;
|
||||
use crate::view::MutableView;
|
||||
use crate::{op_store, store};
|
||||
|
||||
pub struct Transaction<'r> {
|
||||
@ -66,14 +64,6 @@ impl<'r> Transaction<'r> {
|
||||
Arc::get_mut(self.repo.as_mut().unwrap()).unwrap()
|
||||
}
|
||||
|
||||
pub fn index(&self) -> &MutableIndex {
|
||||
self.repo.as_ref().unwrap().index()
|
||||
}
|
||||
|
||||
pub fn view(&self) -> &MutableView {
|
||||
self.repo.as_ref().unwrap().view()
|
||||
}
|
||||
|
||||
pub fn evolution(&self) -> &MutableEvolution {
|
||||
self.repo.as_ref().unwrap().evolution()
|
||||
}
|
||||
|
@ -67,9 +67,10 @@ fn test_import_refs() {
|
||||
|
||||
let git_repo = repo.store().git_repo().unwrap();
|
||||
let mut tx = repo.start_transaction("test");
|
||||
let mut_repo = tx.mut_repo();
|
||||
let heads_before: HashSet<_> = repo.view().heads().clone();
|
||||
jujube_lib::git::import_refs(tx.mut_repo(), &git_repo).unwrap_or_default();
|
||||
let view = tx.view();
|
||||
jujube_lib::git::import_refs(mut_repo, &git_repo).unwrap_or_default();
|
||||
let view = mut_repo.view();
|
||||
let expected_heads: HashSet<_> = heads_before
|
||||
.union(&hashset!(
|
||||
commit_id(&commit3),
|
||||
@ -127,9 +128,10 @@ fn test_import_refs_reimport() {
|
||||
|
||||
Arc::get_mut(&mut repo).unwrap().reload();
|
||||
let mut tx = repo.start_transaction("test");
|
||||
jujube_lib::git::import_refs(tx.mut_repo(), &git_repo).unwrap_or_default();
|
||||
let mut_repo = tx.mut_repo();
|
||||
jujube_lib::git::import_refs(mut_repo, &git_repo).unwrap_or_default();
|
||||
|
||||
let view = tx.view();
|
||||
let view = mut_repo.view();
|
||||
// TODO: commit3 and commit4 should probably be removed
|
||||
let expected_heads: HashSet<_> = heads_before
|
||||
.union(&hashset!(
|
||||
@ -280,9 +282,10 @@ fn test_import_refs_empty_git_repo() {
|
||||
let repo = ReadonlyRepo::init_external_git(&settings, jj_repo_dir, git_repo_dir);
|
||||
let heads_before = repo.view().heads().clone();
|
||||
let mut tx = repo.start_transaction("test");
|
||||
jujube_lib::git::import_refs(tx.mut_repo(), &git_repo).unwrap_or_default();
|
||||
assert_eq!(*tx.view().heads(), heads_before);
|
||||
assert_eq!(tx.view().git_refs().len(), 0);
|
||||
let mut_repo = tx.mut_repo();
|
||||
jujube_lib::git::import_refs(mut_repo, &git_repo).unwrap_or_default();
|
||||
assert_eq!(*mut_repo.view().heads(), heads_before);
|
||||
assert_eq!(mut_repo.view().git_refs().len(), 0);
|
||||
tx.discard();
|
||||
}
|
||||
|
||||
@ -325,8 +328,9 @@ fn test_fetch_success() {
|
||||
|
||||
// The new commit is visible after git::fetch().
|
||||
let mut tx = jj_repo.start_transaction("test");
|
||||
git::fetch(tx.mut_repo(), &clone_git_repo, "origin").unwrap();
|
||||
assert!(tx.view().heads().contains(&commit_id(&new_git_commit)));
|
||||
let mut_repo = tx.mut_repo();
|
||||
git::fetch(mut_repo, &clone_git_repo, "origin").unwrap();
|
||||
assert!(mut_repo.heads().contains(&commit_id(&new_git_commit)));
|
||||
|
||||
tx.discard();
|
||||
}
|
||||
|
@ -410,8 +410,9 @@ fn test_index_commits_incremental_already_indexed(use_git: bool) {
|
||||
assert!(repo.index().has_id(commit_a.id()));
|
||||
assert_eq!(repo.index().num_commits(), 2 + 1);
|
||||
let mut tx = repo.start_transaction("test");
|
||||
tx.add_head(&commit_a);
|
||||
assert_eq!(tx.index().num_commits(), 2 + 1);
|
||||
let mut_repo = tx.mut_repo();
|
||||
mut_repo.add_head(&commit_a);
|
||||
assert_eq!(mut_repo.index().num_commits(), 2 + 1);
|
||||
tx.discard();
|
||||
}
|
||||
|
||||
|
@ -315,11 +315,12 @@ fn test_add_head_success(use_git: bool) {
|
||||
assert_eq!(index_stats.num_commits, 2);
|
||||
assert_eq!(index_stats.max_generation_number, 1);
|
||||
let mut tx = repo.start_transaction("test");
|
||||
assert!(!tx.view().heads().contains(new_commit.id()));
|
||||
assert!(!tx.index().has_id(new_commit.id()));
|
||||
tx.mut_repo().add_head(&new_commit);
|
||||
assert!(tx.view().heads().contains(new_commit.id()));
|
||||
assert!(tx.index().has_id(new_commit.id()));
|
||||
let mut_repo = tx.mut_repo();
|
||||
assert!(!mut_repo.view().heads().contains(new_commit.id()));
|
||||
assert!(!mut_repo.index().has_id(new_commit.id()));
|
||||
mut_repo.add_head(&new_commit);
|
||||
assert!(mut_repo.view().heads().contains(new_commit.id()));
|
||||
assert!(mut_repo.index().has_id(new_commit.id()));
|
||||
tx.commit();
|
||||
Arc::get_mut(&mut repo).unwrap().reload();
|
||||
assert!(repo.view().heads().contains(new_commit.id()));
|
||||
@ -354,9 +355,10 @@ fn test_add_head_ancestor(use_git: bool) {
|
||||
assert_eq!(index_stats.num_commits, 5);
|
||||
assert_eq!(index_stats.max_generation_number, 3);
|
||||
let mut tx = repo.start_transaction("test");
|
||||
tx.mut_repo().add_head(&commit1);
|
||||
assert!(!tx.view().heads().contains(commit1.id()));
|
||||
let index_stats = tx.index().stats();
|
||||
let mut_repo = tx.mut_repo();
|
||||
mut_repo.add_head(&commit1);
|
||||
assert!(!mut_repo.view().heads().contains(commit1.id()));
|
||||
let index_stats = mut_repo.index().stats();
|
||||
assert_eq!(index_stats.num_heads, 2);
|
||||
assert_eq!(index_stats.num_commits, 5);
|
||||
assert_eq!(index_stats.max_generation_number, 3);
|
||||
@ -393,15 +395,16 @@ fn test_add_head_not_immediate_child(use_git: bool) {
|
||||
assert_eq!(index_stats.num_commits, 3);
|
||||
assert_eq!(index_stats.max_generation_number, 1);
|
||||
let mut tx = repo.start_transaction("test");
|
||||
tx.mut_repo().add_head(&child);
|
||||
assert!(tx.view().heads().contains(initial.id()));
|
||||
assert!(!tx.view().heads().contains(rewritten.id()));
|
||||
assert!(tx.view().heads().contains(child.id()));
|
||||
assert!(tx.index().has_id(initial.id()));
|
||||
assert!(tx.index().has_id(rewritten.id()));
|
||||
assert!(tx.index().has_id(child.id()));
|
||||
assert!(tx.evolution().is_obsolete(initial.id()));
|
||||
let index_stats = tx.index().stats();
|
||||
let mut_repo = tx.mut_repo();
|
||||
mut_repo.add_head(&child);
|
||||
assert!(mut_repo.view().heads().contains(initial.id()));
|
||||
assert!(!mut_repo.view().heads().contains(rewritten.id()));
|
||||
assert!(mut_repo.view().heads().contains(child.id()));
|
||||
assert!(mut_repo.index().has_id(initial.id()));
|
||||
assert!(mut_repo.index().has_id(rewritten.id()));
|
||||
assert!(mut_repo.index().has_id(child.id()));
|
||||
assert!(mut_repo.evolution().is_obsolete(initial.id()));
|
||||
let index_stats = mut_repo.index().stats();
|
||||
assert_eq!(index_stats.num_heads, 3);
|
||||
assert_eq!(index_stats.num_commits, 5);
|
||||
assert_eq!(index_stats.max_generation_number, 2);
|
||||
@ -433,15 +436,16 @@ fn test_remove_head(use_git: bool) {
|
||||
Arc::get_mut(&mut repo).unwrap().reload();
|
||||
|
||||
let mut tx = repo.start_transaction("test");
|
||||
assert!(tx.view().heads().contains(commit3.id()));
|
||||
tx.mut_repo().remove_head(&commit3);
|
||||
let heads = tx.view().heads().clone();
|
||||
let mut_repo = tx.mut_repo();
|
||||
assert!(mut_repo.view().heads().contains(commit3.id()));
|
||||
mut_repo.remove_head(&commit3);
|
||||
let heads = mut_repo.view().heads().clone();
|
||||
assert!(!heads.contains(commit3.id()));
|
||||
assert!(!heads.contains(commit2.id()));
|
||||
assert!(!heads.contains(commit1.id()));
|
||||
assert!(tx.index().has_id(commit1.id()));
|
||||
assert!(tx.index().has_id(commit2.id()));
|
||||
assert!(tx.index().has_id(commit3.id()));
|
||||
assert!(mut_repo.index().has_id(commit1.id()));
|
||||
assert!(mut_repo.index().has_id(commit2.id()));
|
||||
assert!(mut_repo.index().has_id(commit3.id()));
|
||||
tx.commit();
|
||||
|
||||
Arc::get_mut(&mut repo).unwrap().reload();
|
||||
@ -476,10 +480,11 @@ fn test_remove_head_ancestor_git_ref(use_git: bool) {
|
||||
Arc::get_mut(&mut repo).unwrap().reload();
|
||||
|
||||
let mut tx = repo.start_transaction("test");
|
||||
let heads = tx.view().heads().clone();
|
||||
let mut_repo = tx.mut_repo();
|
||||
let heads = mut_repo.view().heads().clone();
|
||||
assert!(heads.contains(commit3.id()));
|
||||
tx.mut_repo().remove_head(&commit3);
|
||||
let heads = tx.view().heads().clone();
|
||||
mut_repo.remove_head(&commit3);
|
||||
let heads = mut_repo.view().heads().clone();
|
||||
assert!(!heads.contains(commit3.id()));
|
||||
assert!(!heads.contains(commit2.id()));
|
||||
assert!(heads.contains(commit1.id()));
|
||||
@ -506,9 +511,10 @@ fn test_add_public_head(use_git: bool) {
|
||||
Arc::get_mut(&mut repo).unwrap().reload();
|
||||
|
||||
let mut tx = repo.start_transaction("test");
|
||||
assert!(!tx.view().public_heads().contains(commit1.id()));
|
||||
tx.mut_repo().add_public_head(&commit1);
|
||||
assert!(tx.view().public_heads().contains(commit1.id()));
|
||||
let mut_repo = tx.mut_repo();
|
||||
assert!(!mut_repo.view().public_heads().contains(commit1.id()));
|
||||
mut_repo.add_public_head(&commit1);
|
||||
assert!(mut_repo.view().public_heads().contains(commit1.id()));
|
||||
tx.commit();
|
||||
Arc::get_mut(&mut repo).unwrap().reload();
|
||||
assert!(repo.view().public_heads().contains(commit1.id()));
|
||||
@ -532,9 +538,10 @@ fn test_add_public_head_ancestor(use_git: bool) {
|
||||
Arc::get_mut(&mut repo).unwrap().reload();
|
||||
|
||||
let mut tx = repo.start_transaction("test");
|
||||
assert!(!tx.view().public_heads().contains(commit1.id()));
|
||||
tx.mut_repo().add_public_head(&commit1);
|
||||
assert!(!tx.view().public_heads().contains(commit1.id()));
|
||||
let mut_repo = tx.mut_repo();
|
||||
assert!(!mut_repo.view().public_heads().contains(commit1.id()));
|
||||
mut_repo.add_public_head(&commit1);
|
||||
assert!(!mut_repo.view().public_heads().contains(commit1.id()));
|
||||
tx.commit();
|
||||
Arc::get_mut(&mut repo).unwrap().reload();
|
||||
assert!(!repo.view().public_heads().contains(commit1.id()));
|
||||
@ -555,9 +562,10 @@ fn test_remove_public_head(use_git: bool) {
|
||||
Arc::get_mut(&mut repo).unwrap().reload();
|
||||
|
||||
let mut tx = repo.start_transaction("test");
|
||||
assert!(tx.view().public_heads().contains(commit1.id()));
|
||||
tx.mut_repo().remove_public_head(&commit1);
|
||||
assert!(!tx.view().public_heads().contains(commit1.id()));
|
||||
let mut_repo = tx.mut_repo();
|
||||
assert!(mut_repo.view().public_heads().contains(commit1.id()));
|
||||
mut_repo.remove_public_head(&commit1);
|
||||
assert!(!mut_repo.view().public_heads().contains(commit1.id()));
|
||||
tx.commit();
|
||||
Arc::get_mut(&mut repo).unwrap().reload();
|
||||
assert!(!repo.view().public_heads().contains(commit1.id()));
|
||||
|
@ -45,7 +45,7 @@ fn test_heads_fork(use_git: bool) {
|
||||
|
||||
let wc = repo.working_copy_locked();
|
||||
assert_eq!(
|
||||
*tx.view().heads(),
|
||||
*tx.mut_repo().view().heads(),
|
||||
hashset! {
|
||||
wc.current_commit_id(),
|
||||
child1.id().clone(),
|
||||
@ -77,7 +77,7 @@ fn test_heads_merge(use_git: bool) {
|
||||
|
||||
let wc = repo.working_copy_locked();
|
||||
assert_eq!(
|
||||
*tx.view().heads(),
|
||||
*tx.mut_repo().view().heads(),
|
||||
hashset! {wc.current_commit_id(), merge.id().clone()}
|
||||
);
|
||||
tx.discard();
|
||||
|
@ -1344,7 +1344,7 @@ fn cmd_new(
|
||||
);
|
||||
let mut tx = repo.start_transaction("new empty commit");
|
||||
let new_commit = commit_builder.write_to_transaction(&mut tx);
|
||||
if tx.view().checkout() == parent.id() {
|
||||
if tx.mut_repo().view().checkout() == parent.id() {
|
||||
tx.check_out(ui.settings(), &new_commit);
|
||||
}
|
||||
tx.commit();
|
||||
|
Loading…
Reference in New Issue
Block a user