Skip to content

Commit

Permalink
copy-tracking: add get_copy_records to Store
Browse files Browse the repository at this point in the history
  • Loading branch information
fowles committed Jul 16, 2024
1 parent df02108 commit 811b65e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
14 changes: 12 additions & 2 deletions lib/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
}
Expand Down
20 changes: 10 additions & 10 deletions lib/tests/test_copy_tracking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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(),
);
}

0 comments on commit 811b65e

Please sign in to comment.