From 811b65e1ae75b23b57b04c0692b5c148e8b97f9d Mon Sep 17 00:00:00 2001 From: Matt Kulukundis Date: Tue, 16 Jul 2024 12:49:10 -0400 Subject: [PATCH] copy-tracking: add `get_copy_records` to `Store` --- lib/src/store.rs | 14 ++++++++++++-- lib/tests/test_copy_tracking.rs | 20 ++++++++++---------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/lib/src/store.rs b/lib/src/store.rs index bdd985f5b8..323f371b0b 100644 --- a/lib/src/store.rs +++ b/lib/src/store.rs @@ -21,11 +21,12 @@ use std::io::Read; use std::sync::{Arc, RwLock}; use std::time::SystemTime; +use futures::stream::BoxStream; use pollster::FutureExt; use crate::backend::{ - self, Backend, BackendResult, ChangeId, CommitId, ConflictId, FileId, MergedTreeId, SigningFn, - SymlinkId, TreeId, + self, Backend, BackendResult, ChangeId, CommitId, ConflictId, CopyRecord, FileId, MergedTreeId, + SigningFn, SymlinkId, TreeId, }; use crate::commit::Commit; use crate::index::Index; @@ -82,6 +83,15 @@ impl Store { self.use_tree_conflict_format } + pub fn get_copy_records( + &self, + paths: &[RepoPathBuf], + roots: &[CommitId], + heads: &[CommitId], + ) -> BackendResult>> { + self.backend.get_copy_records(paths, roots, heads) + } + pub fn commit_id_length(&self) -> usize { self.backend.commit_id_length() } diff --git a/lib/tests/test_copy_tracking.rs b/lib/tests/test_copy_tracking.rs index 770deff3a1..0be6c185f3 100644 --- a/lib/tests/test_copy_tracking.rs +++ b/lib/tests/test_copy_tracking.rs @@ -15,22 +15,22 @@ use std::collections::HashMap; use futures::executor::block_on_stream; -use jj_lib::backend::{Backend, CommitId, CopySource, CopySources}; +use jj_lib::backend::{CommitId, CopySource, CopySources}; use jj_lib::commit::Commit; -use jj_lib::git_backend::GitBackend; use jj_lib::repo::Repo; use jj_lib::repo_path::{RepoPath, RepoPathBuf}; use jj_lib::settings::UserSettings; +use jj_lib::store::Store; use jj_lib::transaction::Transaction; use testutils::{create_tree, TestRepo, TestRepoBackend}; fn get_copy_records( - backend: &GitBackend, + store: &Store, paths: &[RepoPathBuf], a: &Commit, b: &Commit, ) -> HashMap> { - let stream = backend + let stream = store .get_copy_records(paths, &[a.id().clone()], &[b.id().clone()]) .unwrap(); let mut res: HashMap> = HashMap::new(); @@ -96,25 +96,25 @@ fn test_git_detection() { &[(&paths[2], "content")], ); - let backend: &GitBackend = repo.store().backend_impl().downcast_ref().unwrap(); + let store = repo.store(); assert_eq!( - get_copy_records(backend, paths, &commit_a, &commit_b), + get_copy_records(store, paths, &commit_a, &commit_b), HashMap::from([("file1".to_string(), vec!["file0".to_string()])]) ); assert_eq!( - get_copy_records(backend, paths, &commit_b, &commit_c), + get_copy_records(store, paths, &commit_b, &commit_c), HashMap::from([("file2".to_string(), vec!["file1".to_string()])]) ); assert_eq!( - get_copy_records(backend, paths, &commit_a, &commit_c), + get_copy_records(store, paths, &commit_a, &commit_c), HashMap::from([("file2".to_string(), vec!["file0".to_string()])]) ); assert_eq!( - get_copy_records(backend, &[], &commit_a, &commit_c), + get_copy_records(store, &[], &commit_a, &commit_c), HashMap::default(), ); assert_eq!( - get_copy_records(backend, paths, &commit_c, &commit_c), + get_copy_records(store, paths, &commit_c, &commit_c), HashMap::default(), ); }