mononoke: migrate cross_repo_sync to Movers instead of the impl Fns

Summary: Let's have all concerned parties use the same type under the same name.

Reviewed By: farnz

Differential Revision: D17481135

fbshipit-source-id: d0a99cce19fa0941d351f5754ed4517aea6a6105
This commit is contained in:
Kostia Balytskyi 2019-09-23 11:06:59 -07:00 committed by Facebook Github Bot
parent e55eeca6d7
commit daf9b3d79a
2 changed files with 30 additions and 23 deletions

View File

@ -22,6 +22,7 @@ use metaconfig_types::PushrebaseParams;
use mononoke_types::{
BonsaiChangeset, BonsaiChangesetMut, ChangesetId, FileChange, MPath, RepositoryId,
};
use movers::Mover;
use pushrebase::{do_pushrebase_bonsai, OntoBookmarkParams, PushrebaseError};
use synced_commit_mapping::{SyncedCommitMapping, SyncedCommitMappingEntry};
@ -54,7 +55,7 @@ async fn rewrite_commit<M: SyncedCommitMapping>(
source_repo_id: RepositoryId,
target_repo_id: RepositoryId,
mapping: &M,
rewrite_path: impl Fn(&MPath) -> Result<Option<MPath>, Error> + Send + Sync,
rewrite_path: Mover,
) -> Result<Option<(BonsaiChangesetMut, Vec<ChangesetId>)>, Error> {
let mut changesets: Vec<ChangesetId> = Vec::new();
// Empty commits should always sync as-is; there is no path rewriting involved here.
@ -67,7 +68,7 @@ async fn rewrite_commit<M: SyncedCommitMapping>(
// Just rewrite copy_from information, when we have it
fn rewrite_copy_from(
copy_from: &(MPath, ChangesetId),
rewrite_path: impl Fn(&MPath) -> Result<Option<MPath>, Error> + Send + Sync,
rewrite_path: Mover,
) -> Result<Option<(MPath, ChangesetId)>, Error> {
let (path, cs) = copy_from;
let new_path = rewrite_path(&path)?;
@ -77,7 +78,7 @@ async fn rewrite_commit<M: SyncedCommitMapping>(
// Extract any copy_from information, and use rewrite_copy_from on it
fn rewrite_file_change(
change: FileChange,
rewrite_path: impl Fn(&MPath) -> Result<Option<MPath>, Error> + Send + Sync,
rewrite_path: Mover,
) -> Result<(FileChange, Option<(MPath, ChangesetId)>), Error> {
let new_copy_from = change
.copy_from()
@ -90,16 +91,16 @@ async fn rewrite_commit<M: SyncedCommitMapping>(
fn do_rewrite(
path: MPath,
change: Option<FileChange>,
rewrite_path: impl Fn(&MPath) -> Result<Option<MPath>, Error> + Send + Sync,
rewrite_path: Mover,
) -> Result<Option<(MPath, Option<(FileChange, Option<(MPath, ChangesetId)>)>)>, Error>
{
let new_path = rewrite_path(&path)?;
let change = change
.map(|change| rewrite_file_change(change, &rewrite_path))
.map(|change| rewrite_file_change(change, rewrite_path.clone()))
.transpose()?;
Ok(new_path.map(|new_path| (new_path, change)))
}
do_rewrite(path, change, &rewrite_path).transpose()
do_rewrite(path, change, rewrite_path.clone()).transpose()
});
for rewritten_change in path_rewritten_changes {
@ -194,7 +195,7 @@ pub async fn sync_commit<M: SyncedCommitMapping + Clone + 'static>(
repos: CommitSyncRepos,
bookmark: BookmarkName,
mapping: M,
rewrite_paths: impl Fn(&MPath) -> Result<Option<MPath>, Error> + Send + Sync + 'static,
rewrite_paths: Mover,
) -> Result<Option<ChangesetId>, Error> {
let hash = cs.get_changeset_id();
let (source_repo, target_repo, source_is_large) = match repos {
@ -334,7 +335,7 @@ pub fn sync_commit_compat<M: SyncedCommitMapping + Clone + 'static>(
repos: CommitSyncRepos,
bookmark: BookmarkName,
mapping: M,
rewrite_paths: impl Fn(&MPath) -> Result<Option<MPath>, Error> + Send + Sync + 'static,
rewrite_paths: Mover,
) -> impl Future<Item = Option<ChangesetId>, Error = Error> {
sync_commit(ctx, cs, repos, bookmark, mapping, rewrite_paths)
.boxed()

View File

@ -14,6 +14,7 @@ use fbinit::FacebookInit;
use futures::Future;
use maplit::btreemap;
use std::str::FromStr;
use std::sync::Arc;
use blobrepo::{save_bonsai_changesets, BlobRepo};
use blobrepo_factory;
@ -27,6 +28,7 @@ use mononoke_types::{
BlobstoreValue, BonsaiChangesetMut, ChangesetId, DateTime, FileChange, FileContents, FileType,
MPath, RepositoryId,
};
use movers::Mover;
use synced_commit_mapping::{SqlConstructors, SqlSyncedCommitMapping, SyncedCommitMapping};
use cross_repo_sync::{sync_commit_compat, CommitSyncRepos};
@ -123,7 +125,7 @@ fn sync_to_master(
repos: CommitSyncRepos,
source_bcs_id: ChangesetId,
mapping: impl SyncedCommitMapping + Clone + 'static,
rewrite_paths: impl Fn(&MPath) -> Result<Option<MPath>, Error> + Send + Sync + 'static,
rewrite_paths: Mover,
) -> Result<Option<ChangesetId>, Error> {
let bookmark_name = BookmarkName::new("master").unwrap();
let source = get_source_repo(&repos);
@ -212,7 +214,7 @@ fn sync_parentage(fb: FacebookInit) {
let mapping = SqlSyncedCommitMapping::with_sqlite_in_memory().unwrap();
let linear_path_in_megarepo = MPath::new("linear").unwrap();
let linear_remap = move |path: &MPath| Ok(Some(linear_path_in_megarepo.join(path)));
let linear_remap = Arc::new(move |path: &MPath| Ok(Some(linear_path_in_megarepo.join(path))));
create_initial_commit(ctx.clone(), &megarepo);
@ -289,7 +291,7 @@ fn sync_removes_commit(fb: FacebookInit) {
};
let mapping = SqlSyncedCommitMapping::with_sqlite_in_memory().unwrap();
let linear_remap = move |_path: &MPath| Ok(None);
let linear_remap = Arc::new(move |_path: &MPath| Ok(None));
// Create a commit with one file called "master" in the blobrepo, and set the bookmark
create_initial_commit(ctx.clone(), &megarepo);
@ -383,10 +385,11 @@ fn sync_causes_conflict(fb: FacebookInit) {
let mapping = SqlSyncedCommitMapping::with_sqlite_in_memory().unwrap();
let linear_path_in_megarepo = MPath::new("linear").unwrap();
let linear_remap = move |path: &MPath| Ok(Some(linear_path_in_megarepo.join(path)));
let linear_remap = Arc::new(move |path: &MPath| Ok(Some(linear_path_in_megarepo.join(path))));
let master_file_path_in_megarepo = MPath::new("master_file").unwrap();
let master_file_remap = move |path: &MPath| Ok(Some(master_file_path_in_megarepo.join(path)));
let master_file_remap =
Arc::new(move |path: &MPath| Ok(Some(master_file_path_in_megarepo.join(path))));
create_initial_commit(ctx.clone(), &megarepo);
@ -458,10 +461,10 @@ fn sync_empty_commit(fb: FacebookInit) {
let mapping = SqlSyncedCommitMapping::with_sqlite_in_memory().unwrap();
let linear_path_in_megarepo = MPath::new("linear").unwrap();
let linear_remap = move |path: &MPath| Ok(Some(linear_path_in_megarepo.join(path)));
let linear_remap = Arc::new(move |path: &MPath| Ok(Some(linear_path_in_megarepo.join(path))));
let linear_path_in_megarepo = MPath::new("linear").unwrap();
let megarepo_remap =
move |path: &MPath| Ok(path.remove_prefix_component(&linear_path_in_megarepo));
Arc::new(move |path: &MPath| Ok(path.remove_prefix_component(&linear_path_in_megarepo)));
create_initial_commit(ctx.clone(), &megarepo);
@ -581,10 +584,10 @@ fn sync_copyinfo(fb: FacebookInit) {
let mapping = SqlSyncedCommitMapping::with_sqlite_in_memory().unwrap();
let linear_path_in_megarepo = MPath::new("linear").unwrap();
let linear_remap = move |path: &MPath| Ok(Some(linear_path_in_megarepo.join(path)));
let linear_remap = Arc::new(move |path: &MPath| Ok(Some(linear_path_in_megarepo.join(path))));
let linear_path_in_megarepo = MPath::new("linear").unwrap();
let megarepo_remap =
move |path: &MPath| Ok(path.remove_prefix_component(&linear_path_in_megarepo));
Arc::new(move |path: &MPath| Ok(path.remove_prefix_component(&linear_path_in_megarepo)));
create_initial_commit(ctx.clone(), &megarepo);
@ -672,13 +675,16 @@ fn sync_remap_failure(fb: FacebookInit) {
let mapping = SqlSyncedCommitMapping::with_sqlite_in_memory().unwrap();
let linear_path_in_megarepo = MPath::new("linear").unwrap();
let linear_remap = move |path: &MPath| Ok(Some(linear_path_in_megarepo.join(path)));
let linear_remap = Arc::new(move |path: &MPath| Ok(Some(linear_path_in_megarepo.join(path))));
let linear_path_in_megarepo = MPath::new("linear").unwrap();
let fail_remap = move |_path: &MPath| Err(err_msg("This always fails"));
let copyfrom_fail_remap = move |path: &MPath| match path.basename().to_bytes().as_ref() {
b"1" => Err(err_msg("This only fails if the file is named '1'")),
_ => Ok(path.remove_prefix_component(&linear_path_in_megarepo)),
};
let fail_remap = Arc::new(move |_path: &MPath| Err(err_msg("This always fails")));
let copyfrom_fail_remap =
Arc::new(
move |path: &MPath| match path.basename().to_bytes().as_ref() {
b"1" => Err(err_msg("This only fails if the file is named '1'")),
_ => Ok(path.remove_prefix_component(&linear_path_in_megarepo)),
},
);
create_initial_commit(ctx.clone(), &megarepo);