Skip to content

Commit b623453

Browse files
committed
Auto commit after git-prolly init and commit
to make sure prollytree metadata are kept
1 parent 7402841 commit b623453

3 files changed

Lines changed: 208 additions & 29 deletions

File tree

src/git/operations.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,14 +397,24 @@ mod tests {
397397
#[test]
398398
fn test_git_operations_creation() {
399399
let temp_dir = TempDir::new().unwrap();
400-
let store = VersionedKvStore::<32>::init(temp_dir.path()).unwrap();
400+
// Initialize git repository (regular, not bare)
401+
gix::init(temp_dir.path()).unwrap();
402+
// Create subdirectory for dataset
403+
let dataset_dir = temp_dir.path().join("dataset");
404+
std::fs::create_dir_all(&dataset_dir).unwrap();
405+
let store = VersionedKvStore::<32>::init(&dataset_dir).unwrap();
401406
let _ops = GitOperations::new(store);
402407
}
403408

404409
#[test]
405410
fn test_parse_commit_id() {
406411
let temp_dir = TempDir::new().unwrap();
407-
let store = VersionedKvStore::<32>::init(temp_dir.path()).unwrap();
412+
// Initialize git repository (regular, not bare)
413+
gix::init(temp_dir.path()).unwrap();
414+
// Create subdirectory for dataset
415+
let dataset_dir = temp_dir.path().join("dataset");
416+
std::fs::create_dir_all(&dataset_dir).unwrap();
417+
let store = VersionedKvStore::<32>::init(&dataset_dir).unwrap();
408418
let ops = GitOperations::new(store);
409419

410420
// Test HEAD parsing

src/git/storage.rs

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ pub struct GitNodeStorage<const N: usize> {
3333
configs: Mutex<HashMap<String, Vec<u8>>>,
3434
// Maps ProllyTree hashes to Git object IDs
3535
hash_to_object_id: Mutex<HashMap<ValueDigest<N>, gix::ObjectId>>,
36+
// Directory where this dataset's config and mapping files are stored
37+
dataset_dir: std::path::PathBuf,
3638
}
3739

3840
impl<const N: usize> Clone for GitNodeStorage<N> {
@@ -42,6 +44,7 @@ impl<const N: usize> Clone for GitNodeStorage<N> {
4244
cache: Mutex::new(LruCache::new(NonZeroUsize::new(1000).unwrap())),
4345
configs: Mutex::new(HashMap::new()),
4446
hash_to_object_id: Mutex::new(HashMap::new()),
47+
dataset_dir: self.dataset_dir.clone(),
4548
};
4649

4750
// Load the hash mappings for the cloned instance
@@ -53,14 +56,15 @@ impl<const N: usize> Clone for GitNodeStorage<N> {
5356

5457
impl<const N: usize> GitNodeStorage<N> {
5558
/// Create a new GitNodeStorage instance
56-
pub fn new(repository: gix::Repository) -> Result<Self, GitKvError> {
59+
pub fn new(repository: gix::Repository, dataset_dir: std::path::PathBuf) -> Result<Self, GitKvError> {
5760
let cache_size = NonZeroUsize::new(1000).unwrap(); // Default cache size
5861

5962
let storage = GitNodeStorage {
6063
_repository: Arc::new(Mutex::new(repository)),
6164
cache: Mutex::new(LruCache::new(cache_size)),
6265
configs: Mutex::new(HashMap::new()),
6366
hash_to_object_id: Mutex::new(HashMap::new()),
67+
dataset_dir,
6468
};
6569

6670
// Load existing hash mappings
@@ -72,6 +76,7 @@ impl<const N: usize> GitNodeStorage<N> {
7276
/// Create GitNodeStorage with custom cache size
7377
pub fn with_cache_size(
7478
repository: gix::Repository,
79+
dataset_dir: std::path::PathBuf,
7580
cache_size: usize,
7681
) -> Result<Self, GitKvError> {
7782
let cache_size = NonZeroUsize::new(cache_size).unwrap_or(NonZeroUsize::new(1000).unwrap());
@@ -81,6 +86,7 @@ impl<const N: usize> GitNodeStorage<N> {
8186
cache: Mutex::new(LruCache::new(cache_size)),
8287
configs: Mutex::new(HashMap::new()),
8388
hash_to_object_id: Mutex::new(HashMap::new()),
89+
dataset_dir,
8490
};
8591

8692
// Load existing hash mappings
@@ -176,9 +182,8 @@ impl<const N: usize> NodeStorage<N> for GitNodeStorage<N> {
176182
let mut configs = self.configs.lock().unwrap();
177183
configs.insert(key.to_string(), config.to_vec());
178184

179-
// Also persist to filesystem for durability
180-
let repo = self._repository.lock().unwrap();
181-
let config_path = repo.path().join(format!("prolly_config_{key}"));
185+
// Also persist to filesystem for durability in the dataset directory
186+
let config_path = self.dataset_dir.join(format!("prolly_config_{key}"));
182187
let _ = std::fs::write(config_path, config);
183188
}
184189

@@ -189,11 +194,9 @@ impl<const N: usize> NodeStorage<N> for GitNodeStorage<N> {
189194
}
190195

191196
// If not in memory, try to load from filesystem
192-
let repo = self._repository.lock().unwrap();
193-
let config_path = repo.path().join(format!("prolly_config_{key}"));
197+
let config_path = self.dataset_dir.join(format!("prolly_config_{key}"));
194198
if let Ok(config) = std::fs::read(config_path) {
195199
// Cache in memory for future use
196-
drop(repo);
197200
self.configs
198201
.lock()
199202
.unwrap()
@@ -208,8 +211,7 @@ impl<const N: usize> NodeStorage<N> for GitNodeStorage<N> {
208211
impl<const N: usize> GitNodeStorage<N> {
209212
/// Save hash mapping to filesystem
210213
fn save_hash_mapping(&self, hash: &ValueDigest<N>, object_id: &gix::ObjectId) {
211-
let repo = self._repository.lock().unwrap();
212-
let mapping_path = repo.path().join("prolly_hash_mappings");
214+
let mapping_path = self.dataset_dir.join("prolly_hash_mappings");
213215

214216
// Read existing mappings
215217
let mut mappings = if mapping_path.exists() {
@@ -230,8 +232,7 @@ impl<const N: usize> GitNodeStorage<N> {
230232

231233
/// Load hash mappings from filesystem
232234
fn load_hash_mappings(&self) {
233-
let repo = self._repository.lock().unwrap();
234-
let mapping_path = repo.path().join("prolly_hash_mappings");
235+
let mapping_path = self.dataset_dir.join("prolly_hash_mappings");
235236

236237
if let Ok(mappings) = std::fs::read_to_string(mapping_path) {
237238
let mut hash_map = self.hash_to_object_id.lock().unwrap();
@@ -300,8 +301,8 @@ mod tests {
300301

301302
#[test]
302303
fn test_git_node_storage_basic_operations() {
303-
let (_temp_dir, repo) = create_test_repo();
304-
let mut storage = GitNodeStorage::<32>::new(repo).unwrap();
304+
let (temp_dir, repo) = create_test_repo();
305+
let mut storage = GitNodeStorage::<32>::new(repo, temp_dir.path().to_path_buf()).unwrap();
305306

306307
let node = create_test_node();
307308
let hash = node.get_hash();
@@ -324,8 +325,10 @@ mod tests {
324325

325326
#[test]
326327
fn test_cache_functionality() {
327-
let (_temp_dir, repo) = create_test_repo();
328-
let mut storage = GitNodeStorage::<32>::with_cache_size(repo, 2).unwrap();
328+
let (temp_dir, repo) = create_test_repo();
329+
let dataset_dir = temp_dir.path().join("dataset");
330+
std::fs::create_dir_all(&dataset_dir).unwrap();
331+
let mut storage = GitNodeStorage::<32>::with_cache_size(repo, dataset_dir, 2).unwrap();
329332

330333
let node1 = create_test_node();
331334
let hash1 = node1.get_hash();

0 commit comments

Comments
 (0)