Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

copy-tracking: add get_copy_records to Store #4102

Merged
merged 1 commit into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(),
);
}