forked from mirrors/jj
copy-tracking: add get_copy_records
to Store
This commit is contained in:
parent
c7eac90200
commit
3043b83a8f
2 changed files with 22 additions and 12 deletions
|
@ -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<BoxStream<BackendResult<CopyRecord>>> {
|
||||
self.backend.get_copy_records(paths, roots, heads)
|
||||
}
|
||||
|
||||
pub fn commit_id_length(&self) -> usize {
|
||||
self.backend.commit_id_length()
|
||||
}
|
||||
|
|
|
@ -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<String, Vec<String>> {
|
||||
let stream = backend
|
||||
let stream = store
|
||||
.get_copy_records(paths, &[a.id().clone()], &[b.id().clone()])
|
||||
.unwrap();
|
||||
let mut res: HashMap<String, Vec<String>> = 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(),
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue