diff --git a/lib/src/op_heads_store.rs b/lib/src/op_heads_store.rs index 4efb98b3d..6c6c788df 100644 --- a/lib/src/op_heads_store.rs +++ b/lib/src/op_heads_store.rs @@ -22,7 +22,7 @@ use crate::lock::FileLock; use crate::op_store::{OpStore, OperationId, OperationMetadata}; use crate::operation::Operation; use crate::repo::RepoLoader; -use crate::store::{CommitId, Timestamp}; +use crate::store::Timestamp; use crate::transaction::UnpublishedOperation; use crate::{dag_walk, op_store}; @@ -43,10 +43,8 @@ impl OpHeadsStore { pub fn init( dir: PathBuf, op_store: &Arc, - checkout: CommitId, - ) -> (Self, OperationId, op_store::View) { - let mut root_view = op_store::View::new(checkout.clone()); - root_view.head_ids.insert(checkout); + root_view: &op_store::View, + ) -> (Self, OperationId) { let root_view_id = op_store.write_view(&root_view).unwrap(); let operation_metadata = OperationMetadata::new("initialize repo".to_string(), Timestamp::now()); @@ -59,7 +57,7 @@ impl OpHeadsStore { let op_heads_store = OpHeadsStore { dir }; op_heads_store.add_op_head(&init_operation_id); - (op_heads_store, init_operation_id, root_view) + (op_heads_store, init_operation_id) } pub fn load(dir: PathBuf) -> OpHeadsStore { diff --git a/lib/src/repo.rs b/lib/src/repo.rs index 800b8e22a..ea16162d2 100644 --- a/lib/src/repo.rs +++ b/lib/src/repo.rs @@ -215,8 +215,12 @@ impl ReadonlyRepo { let op_heads_dir = repo_path.join("op_heads"); std::fs::create_dir(&op_heads_dir).unwrap(); - let (op_heads_store, init_op_id, root_view) = - OpHeadsStore::init(op_heads_dir, &op_store, checkout_commit.id().clone()); + let mut root_view = op_store::View::new(checkout_commit.id().clone()); + root_view.head_ids.insert(checkout_commit.id().clone()); + root_view + .public_head_ids + .insert(store.root_commit_id().clone()); + let (op_heads_store, init_op_id) = OpHeadsStore::init(op_heads_dir, &op_store, &root_view); let op_heads_store = Arc::new(op_heads_store); fs::create_dir(repo_path.join("index")).unwrap(); diff --git a/lib/tests/test_revset.rs b/lib/tests/test_revset.rs index ab466d350..a6b4ddee3 100644 --- a/lib/tests/test_revset.rs +++ b/lib/tests/test_revset.rs @@ -528,14 +528,14 @@ fn test_evaluate_expression_public_heads(use_git: bool) { let mut tx = repo.start_transaction("test"); let mut_repo = tx.mut_repo(); + let root_commit = repo.store().root_commit(); let commit1 = testutils::create_random_commit(&settings, &repo).write_to_repo(mut_repo); let commit2 = testutils::create_random_commit(&settings, &repo).write_to_repo(mut_repo); // Can get public heads with root commit as only public head assert_eq!( resolve_commit_ids(mut_repo.as_repo_ref(), "public_heads()"), - // TODO: This should include the root commit - vec![] + vec![root_commit.id().clone()] ); // Can get public heads with a single public head mut_repo.add_public_head(&commit1); diff --git a/lib/tests/test_view.rs b/lib/tests/test_view.rs index 2ff3780a1..ce6b538d0 100644 --- a/lib/tests/test_view.rs +++ b/lib/tests/test_view.rs @@ -24,6 +24,10 @@ fn test_heads_empty(use_git: bool) { let wc = repo.working_copy_locked(); assert_eq!(*repo.view().heads(), hashset! {wc.current_commit_id()}); + assert_eq!( + *repo.view().public_heads(), + hashset! {repo.store().root_commit_id().clone()} + ); } #[test_case(false ; "local store")]