From 81379757859e538b3c3f6c9bc366be89b7aeffa6 Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Wed, 27 Dec 2023 15:54:01 -0800 Subject: [PATCH] op heads: drop support for old location/format We move `.jj/repo/op_heads/*` into `.jj/repo/op_heads/heads/*` almost a year ago, in commits 90a66ec2621f and 37ba17589dc3. We said we would drop support for it in 0.9+. I think we said that before we started doing monthly releases, but I we're still past the goal of 6 months (which is what I think we were aiming for). --- lib/src/simple_op_heads_store.rs | 122 ------------------------------- 1 file changed, 122 deletions(-) diff --git a/lib/src/simple_op_heads_store.rs b/lib/src/simple_op_heads_store.rs index 1874b2159..3f538694d 100644 --- a/lib/src/simple_op_heads_store.rs +++ b/lib/src/simple_op_heads_store.rs @@ -49,26 +49,6 @@ impl SimpleOpHeadsStore { pub fn load(dir: &Path) -> Self { let op_heads_dir = dir.join("heads"); - // TODO: Delete this migration code at 0.9+ or so - if !op_heads_dir.exists() { - // For some months during 0.7 development, the name was "simple_op_heads" - if dir.join("simple_op_heads").exists() { - fs::rename(dir.join("simple_op_heads"), &op_heads_dir).unwrap(); - } else { - 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() { - old_store.remove_op_head(&id); - new_store.add_op_head(&id); - } - return new_store; - } - } - Self { dir: op_heads_dir } } } @@ -123,105 +103,3 @@ impl OpHeadsStore for SimpleOpHeadsStore { }) } } - -#[cfg(test)] -mod tests { - use std::collections::HashSet; - use std::fs; - use std::path::Path; - - use itertools::Itertools; - - use crate::backend::ObjectId; - use crate::op_heads_store::OpHeadsStore; - use crate::op_store::OperationId; - use crate::simple_op_heads_store::SimpleOpHeadsStore; - - fn read_dir(dir: &Path) -> Vec { - fs::read_dir(dir) - .unwrap() - .map(|entry| entry.unwrap().file_name().to_str().unwrap().to_string()) - .sorted() - .collect() - } - - #[test] - fn test_simple_op_heads_store_migration_into_subdir() { - let test_dir = testutils::new_temp_dir(); - let store_path = test_dir.path().join("op_heads"); - fs::create_dir(&store_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: store_path.clone(), - }; - old_store.add_op_head(&op1); - old_store.add_op_head(&op2); - - assert_eq!(vec!["012345", "abcdef"], 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")) - ); - } - - #[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")) - ); - } -}