view: make root commit public

This commit is contained in:
Martin von Zweigbergk 2021-04-18 22:52:31 -07:00
parent b52cfc156c
commit 64fcf90c68
4 changed files with 16 additions and 10 deletions

View file

@ -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<dyn OpStore>,
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 {

View file

@ -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();

View file

@ -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);

View file

@ -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")]