mirror of
https://github.com/martinvonz/jj.git
synced 2024-12-27 06:27:43 +00:00
tests: call num_commits() on specific implementation
This removes the last calls to `Index::num_commits()`.
This commit is contained in:
parent
efc9cc9885
commit
0a7de2540f
1 changed files with 22 additions and 15 deletions
|
@ -17,7 +17,7 @@ use std::sync::Arc;
|
|||
use jujutsu_lib::backend::CommitId;
|
||||
use jujutsu_lib::commit::Commit;
|
||||
use jujutsu_lib::commit_builder::CommitBuilder;
|
||||
use jujutsu_lib::default_index_store::ReadonlyIndexImpl;
|
||||
use jujutsu_lib::default_index_store::{MutableIndexImpl, ReadonlyIndexImpl};
|
||||
use jujutsu_lib::index::Index;
|
||||
use jujutsu_lib::repo::{MutableRepo, ReadonlyRepo, Repo};
|
||||
use jujutsu_lib::settings::UserSettings;
|
||||
|
@ -45,7 +45,7 @@ fn test_index_commits_empty_repo(use_git: bool) {
|
|||
let test_repo = TestRepo::init(use_git);
|
||||
let repo = &test_repo.repo;
|
||||
|
||||
let index = repo.index();
|
||||
let index = as_readonly_impl(repo);
|
||||
// There should be just the root commit
|
||||
assert_eq!(index.num_commits(), 1);
|
||||
|
||||
|
@ -87,7 +87,7 @@ fn test_index_commits_standard_cases(use_git: bool) {
|
|||
let commit_h = graph_builder.commit_with_parents(&[&commit_e]);
|
||||
let repo = tx.commit();
|
||||
|
||||
let index = as_index_impl(&repo);
|
||||
let index = as_readonly_impl(&repo);
|
||||
// There should be the root commit, plus 8 more
|
||||
assert_eq!(index.num_commits(), 1 + 8);
|
||||
|
||||
|
@ -147,7 +147,7 @@ fn test_index_commits_criss_cross(use_git: bool) {
|
|||
}
|
||||
let repo = tx.commit();
|
||||
|
||||
let index = as_index_impl(&repo);
|
||||
let index = as_readonly_impl(&repo);
|
||||
// There should the root commit, plus 2 for each generation
|
||||
assert_eq!(index.num_commits(), 1 + 2 * (num_generations as u32));
|
||||
|
||||
|
@ -293,7 +293,7 @@ fn test_index_commits_previous_operations(use_git: bool) {
|
|||
std::fs::create_dir(&index_operations_dir).unwrap();
|
||||
|
||||
let repo = load_repo_at_head(&settings, repo.repo_path());
|
||||
let index = as_index_impl(&repo);
|
||||
let index = as_readonly_impl(&repo);
|
||||
// There should be the root commit, plus 3 more
|
||||
assert_eq!(index.num_commits(), 1 + 3);
|
||||
|
||||
|
@ -330,7 +330,7 @@ fn test_index_commits_incremental(use_git: bool) {
|
|||
.unwrap();
|
||||
let repo = tx.commit();
|
||||
|
||||
let index = repo.index();
|
||||
let index = as_readonly_impl(&repo);
|
||||
// There should be the root commit, plus 1 more
|
||||
assert_eq!(index.num_commits(), 1 + 1);
|
||||
|
||||
|
@ -344,7 +344,7 @@ fn test_index_commits_incremental(use_git: bool) {
|
|||
tx.commit();
|
||||
|
||||
let repo = load_repo_at_head(&settings, repo.repo_path());
|
||||
let index = as_index_impl(&repo);
|
||||
let index = as_readonly_impl(&repo);
|
||||
// There should be the root commit, plus 3 more
|
||||
assert_eq!(index.num_commits(), 1 + 3);
|
||||
|
||||
|
@ -382,14 +382,14 @@ fn test_index_commits_incremental_empty_transaction(use_git: bool) {
|
|||
.unwrap();
|
||||
let repo = tx.commit();
|
||||
|
||||
let index = repo.index();
|
||||
let index = as_readonly_impl(&repo);
|
||||
// There should be the root commit, plus 1 more
|
||||
assert_eq!(index.num_commits(), 1 + 1);
|
||||
|
||||
repo.start_transaction(&settings, "test").commit();
|
||||
|
||||
let repo = load_repo_at_head(&settings, repo.repo_path());
|
||||
let index = as_index_impl(&repo);
|
||||
let index = as_readonly_impl(&repo);
|
||||
// There should be the root commit, plus 1 more
|
||||
assert_eq!(index.num_commits(), 1 + 1);
|
||||
|
||||
|
@ -426,11 +426,11 @@ fn test_index_commits_incremental_already_indexed(use_git: bool) {
|
|||
let repo = tx.commit();
|
||||
|
||||
assert!(repo.index().has_id(commit_a.id()));
|
||||
assert_eq!(repo.index().num_commits(), 1 + 1);
|
||||
assert_eq!(as_readonly_impl(&repo).num_commits(), 1 + 1);
|
||||
let mut tx = repo.start_transaction(&settings, "test");
|
||||
let mut_repo = tx.mut_repo();
|
||||
mut_repo.add_head(&commit_a);
|
||||
assert_eq!(mut_repo.index().num_commits(), 1 + 1);
|
||||
assert_eq!(as_mutable_impl(mut_repo).num_commits(), 1 + 1);
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
|
@ -446,7 +446,7 @@ fn create_n_commits(
|
|||
tx.commit()
|
||||
}
|
||||
|
||||
fn as_index_impl(repo: &Arc<ReadonlyRepo>) -> &ReadonlyIndexImpl {
|
||||
fn as_readonly_impl(repo: &Arc<ReadonlyRepo>) -> &ReadonlyIndexImpl {
|
||||
repo.readonly_index()
|
||||
.as_index()
|
||||
.as_any()
|
||||
|
@ -454,8 +454,15 @@ fn as_index_impl(repo: &Arc<ReadonlyRepo>) -> &ReadonlyIndexImpl {
|
|||
.unwrap()
|
||||
}
|
||||
|
||||
fn as_mutable_impl(repo: &MutableRepo) -> &MutableIndexImpl {
|
||||
repo.index()
|
||||
.as_any()
|
||||
.downcast_ref::<MutableIndexImpl>()
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
fn commits_by_level(repo: &Arc<ReadonlyRepo>) -> Vec<u32> {
|
||||
as_index_impl(repo)
|
||||
as_readonly_impl(repo)
|
||||
.stats()
|
||||
.levels
|
||||
.iter()
|
||||
|
@ -536,7 +543,7 @@ fn test_index_store_type(use_git: bool) {
|
|||
let test_repo = TestRepo::init(use_git);
|
||||
let repo = &test_repo.repo;
|
||||
|
||||
assert_eq!(repo.index().num_commits(), 1);
|
||||
assert_eq!(as_readonly_impl(repo).num_commits(), 1);
|
||||
let index_store_type_path = repo.repo_path().join("index").join("type");
|
||||
assert_eq!(
|
||||
std::fs::read_to_string(&index_store_type_path).unwrap(),
|
||||
|
@ -550,5 +557,5 @@ fn test_index_store_type(use_git: bool) {
|
|||
std::fs::read_to_string(&index_store_type_path).unwrap(),
|
||||
"default"
|
||||
);
|
||||
assert_eq!(repo.index().num_commits(), 1);
|
||||
assert_eq!(as_readonly_impl(&repo).num_commits(), 1);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue