mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-18 02:04:19 +00:00
simple_op_heads_store: rename storage directory
`SimpleOpHeadsStore` currently stores its files in `.jj/repo/op_heads/simple_op_heads/`. The `.jj/repo/op_heads/type` file indicates the type of op-heads backend. If that contains "simple_op_head_store", we use the `SimpleOpHeadsStore` backend. There's no need for the `simple_op_heads` directory to also indicate the type of backend in its name. I kept just the `heads` in the name to make it less redundant with the parent directory (which is `op_heads)`. We could alternatively call the directory `values` or similar.
This commit is contained in:
parent
0d1ec835c1
commit
37ba17589d
2 changed files with 66 additions and 21 deletions
|
@ -51,7 +51,7 @@ impl SimpleOpHeadsStore {
|
||||||
let init_operation_id = op_store.write_operation(&init_operation).unwrap();
|
let init_operation_id = op_store.write_operation(&init_operation).unwrap();
|
||||||
let init_operation = Operation::new(op_store.clone(), init_operation_id, init_operation);
|
let init_operation = Operation::new(op_store.clone(), init_operation_id, init_operation);
|
||||||
|
|
||||||
let op_heads_dir = dir.join("simple_op_heads");
|
let op_heads_dir = dir.join("heads");
|
||||||
fs::create_dir(&op_heads_dir).unwrap();
|
fs::create_dir(&op_heads_dir).unwrap();
|
||||||
let op_heads_store = Self { dir: op_heads_dir };
|
let op_heads_store = Self { dir: op_heads_dir };
|
||||||
op_heads_store.add_op_head(init_operation.id());
|
op_heads_store.add_op_head(init_operation.id());
|
||||||
|
@ -59,21 +59,25 @@ impl SimpleOpHeadsStore {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn load(dir: &Path) -> Self {
|
pub fn load(dir: &Path) -> Self {
|
||||||
let op_heads_dir = dir.join("simple_op_heads");
|
let op_heads_dir = dir.join("heads");
|
||||||
|
// TODO: Delete this migration code at 0.9+ or so
|
||||||
// TODO: Delete this migration code at 0.8+ or so
|
|
||||||
if !op_heads_dir.exists() {
|
if !op_heads_dir.exists() {
|
||||||
let old_store = Self {
|
// For some months during 0.7 development, the name was "simple_op_heads"
|
||||||
dir: dir.to_path_buf(),
|
if dir.join("simple_op_heads").exists() {
|
||||||
};
|
fs::rename(dir.join("simple_op_heads"), &op_heads_dir).unwrap();
|
||||||
fs::create_dir(&op_heads_dir).unwrap();
|
} else {
|
||||||
let new_store = Self { dir: op_heads_dir };
|
let old_store = Self {
|
||||||
|
dir: dir.to_path_buf(),
|
||||||
|
};
|
||||||
|
fs::create_dir(&op_heads_dir).unwrap();
|
||||||
|
let new_store = Self { dir: op_heads_dir };
|
||||||
|
|
||||||
for id in old_store.get_op_heads() {
|
for id in old_store.get_op_heads() {
|
||||||
old_store.remove_op_head(&id);
|
old_store.remove_op_head(&id);
|
||||||
new_store.add_op_head(&id);
|
new_store.add_op_head(&id);
|
||||||
|
}
|
||||||
|
return new_store;
|
||||||
}
|
}
|
||||||
return new_store;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Self { dir: op_heads_dir }
|
Self { dir: op_heads_dir }
|
||||||
|
@ -152,7 +156,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_simple_op_heads_store_migration() {
|
fn test_simple_op_heads_store_migration_into_subdir() {
|
||||||
let test_dir = testutils::new_temp_dir();
|
let test_dir = testutils::new_temp_dir();
|
||||||
let store_path = test_dir.path().join("op_heads");
|
let store_path = test_dir.path().join("op_heads");
|
||||||
fs::create_dir(&store_path).unwrap();
|
fs::create_dir(&store_path).unwrap();
|
||||||
|
@ -174,19 +178,60 @@ mod tests {
|
||||||
|
|
||||||
let new_store = SimpleOpHeadsStore::load(&store_path);
|
let new_store = SimpleOpHeadsStore::load(&store_path);
|
||||||
assert_eq!(&ops, &new_store.get_op_heads().into_iter().collect());
|
assert_eq!(&ops, &new_store.get_op_heads().into_iter().collect());
|
||||||
assert_eq!(vec!["simple_op_heads"], read_dir(&store_path));
|
assert_eq!(vec!["heads"], read_dir(&store_path));
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
vec!["012345", "abcdef"],
|
vec!["012345", "abcdef"],
|
||||||
read_dir(&store_path.join("simple_op_heads"))
|
read_dir(&store_path.join("heads"))
|
||||||
);
|
);
|
||||||
|
|
||||||
// Migration is idempotent
|
// Migration is idempotent
|
||||||
let new_store = SimpleOpHeadsStore::load(&store_path);
|
let new_store = SimpleOpHeadsStore::load(&store_path);
|
||||||
assert_eq!(&ops, &new_store.get_op_heads().into_iter().collect());
|
assert_eq!(&ops, &new_store.get_op_heads().into_iter().collect());
|
||||||
assert_eq!(vec!["simple_op_heads"], read_dir(&store_path));
|
assert_eq!(vec!["heads"], read_dir(&store_path));
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
vec!["012345", "abcdef"],
|
vec!["012345", "abcdef"],
|
||||||
read_dir(&store_path.join("simple_op_heads"))
|
read_dir(&store_path.join("heads"))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_simple_op_heads_store_migration_change_dirname() {
|
||||||
|
let test_dir = testutils::new_temp_dir();
|
||||||
|
let store_path = test_dir.path().join("op_heads");
|
||||||
|
fs::create_dir(&store_path).unwrap();
|
||||||
|
let old_heads_path = store_path.join("simple_op_heads");
|
||||||
|
fs::create_dir(&old_heads_path).unwrap();
|
||||||
|
|
||||||
|
let op1 = OperationId::from_hex("012345");
|
||||||
|
let op2 = OperationId::from_hex("abcdef");
|
||||||
|
let mut ops = HashSet::new();
|
||||||
|
ops.insert(op1.clone());
|
||||||
|
ops.insert(op2.clone());
|
||||||
|
|
||||||
|
let old_store = SimpleOpHeadsStore {
|
||||||
|
dir: old_heads_path,
|
||||||
|
};
|
||||||
|
old_store.add_op_head(&op1);
|
||||||
|
old_store.add_op_head(&op2);
|
||||||
|
|
||||||
|
assert_eq!(vec!["simple_op_heads"], read_dir(&store_path));
|
||||||
|
drop(old_store);
|
||||||
|
|
||||||
|
let new_store = SimpleOpHeadsStore::load(&store_path);
|
||||||
|
assert_eq!(&ops, &new_store.get_op_heads().into_iter().collect());
|
||||||
|
assert_eq!(vec!["heads"], read_dir(&store_path));
|
||||||
|
assert_eq!(
|
||||||
|
vec!["012345", "abcdef"],
|
||||||
|
read_dir(&store_path.join("heads"))
|
||||||
|
);
|
||||||
|
|
||||||
|
// Migration is idempotent
|
||||||
|
let new_store = SimpleOpHeadsStore::load(&store_path);
|
||||||
|
assert_eq!(&ops, &new_store.get_op_heads().into_iter().collect());
|
||||||
|
assert_eq!(vec!["heads"], read_dir(&store_path));
|
||||||
|
assert_eq!(
|
||||||
|
vec!["012345", "abcdef"],
|
||||||
|
read_dir(&store_path.join("heads"))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ fn test_unpublished_operation(use_git: bool) {
|
||||||
let test_repo = TestRepo::init(use_git);
|
let test_repo = TestRepo::init(use_git);
|
||||||
let repo = &test_repo.repo;
|
let repo = &test_repo.repo;
|
||||||
|
|
||||||
let op_heads_dir = repo.repo_path().join("op_heads").join("simple_op_heads");
|
let op_heads_dir = repo.repo_path().join("op_heads").join("heads");
|
||||||
let op_id0 = repo.op_id().clone();
|
let op_id0 = repo.op_id().clone();
|
||||||
assert_eq!(list_dir(&op_heads_dir), vec![repo.op_id().hex()]);
|
assert_eq!(list_dir(&op_heads_dir), vec![repo.op_id().hex()]);
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ fn test_consecutive_operations(use_git: bool) {
|
||||||
let test_repo = TestRepo::init(use_git);
|
let test_repo = TestRepo::init(use_git);
|
||||||
let repo = &test_repo.repo;
|
let repo = &test_repo.repo;
|
||||||
|
|
||||||
let op_heads_dir = repo.repo_path().join("op_heads").join("simple_op_heads");
|
let op_heads_dir = repo.repo_path().join("op_heads").join("heads");
|
||||||
let op_id0 = repo.op_id().clone();
|
let op_id0 = repo.op_id().clone();
|
||||||
assert_eq!(list_dir(&op_heads_dir), vec![repo.op_id().hex()]);
|
assert_eq!(list_dir(&op_heads_dir), vec![repo.op_id().hex()]);
|
||||||
|
|
||||||
|
@ -90,7 +90,7 @@ fn test_concurrent_operations(use_git: bool) {
|
||||||
let test_repo = TestRepo::init(use_git);
|
let test_repo = TestRepo::init(use_git);
|
||||||
let repo = &test_repo.repo;
|
let repo = &test_repo.repo;
|
||||||
|
|
||||||
let op_heads_dir = repo.repo_path().join("op_heads").join("simple_op_heads");
|
let op_heads_dir = repo.repo_path().join("op_heads").join("heads");
|
||||||
let op_id0 = repo.op_id().clone();
|
let op_id0 = repo.op_id().clone();
|
||||||
assert_eq!(list_dir(&op_heads_dir), vec![repo.op_id().hex()]);
|
assert_eq!(list_dir(&op_heads_dir), vec![repo.op_id().hex()]);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue