push-redirector: borrow more instead of cloning

Summary: Same as the previous diff, but for push-redirector.

Reviewed By: StanislavGlebik

Differential Revision: D24538027

fbshipit-source-id: 392aee1b9cf0e684486c274c2b54fc2fb719bb3a
This commit is contained in:
Kostia Balytskyi 2020-10-27 11:43:24 -07:00 committed by Facebook GitHub Bot
parent cab3d4f181
commit 26e9741d32
2 changed files with 47 additions and 50 deletions

View File

@ -1653,7 +1653,7 @@ impl HgCommands for RepoClient {
None, None,
); );
push_redirector push_redirector
.run_redirected_post_resolve_action(ctx, action) .run_redirected_post_resolve_action(&ctx, action)
.await .await
} }
None => { None => {

View File

@ -153,7 +153,7 @@ impl PushRedirector {
/// - convert the `UnbundleResponse` struct to be a small-repo one /// - convert the `UnbundleResponse` struct to be a small-repo one
pub async fn run_redirected_post_resolve_action( pub async fn run_redirected_post_resolve_action(
&self, &self,
ctx: CoreContext, ctx: &CoreContext,
action: PostResolveAction, action: PostResolveAction,
) -> Result<UnbundleResponse, BundleResolverError> { ) -> Result<UnbundleResponse, BundleResolverError> {
let large_repo = self.repo.blobrepo().clone(); let large_repo = self.repo.blobrepo().clone();
@ -164,7 +164,7 @@ impl PushRedirector {
let push_params = self.repo.push_params().clone(); let push_params = self.repo.push_params().clone();
let large_repo_action = self let large_repo_action = self
.convert_post_resolve_action(ctx.clone(), action) .convert_post_resolve_action(&ctx, action)
.await .await
.map_err(BundleResolverError::from)?; .map_err(BundleResolverError::from)?;
let large_repo_response = run_post_resolve_action( let large_repo_response = run_post_resolve_action(
@ -182,18 +182,19 @@ impl PushRedirector {
CrossRepoPushSource::PushRedirected, CrossRepoPushSource::PushRedirected,
) )
.await?; .await?;
self.convert_unbundle_response(ctx.clone(), large_repo_response) self.convert_unbundle_response(&ctx, large_repo_response)
.await .await
.map_err(BundleResolverError::from) .map_err(BundleResolverError::from)
} }
fn make_hook_rejection_remapper( fn make_hook_rejection_remapper(
&self, &self,
ctx: CoreContext, ctx: &CoreContext,
large_to_small: HashMap<ChangesetId, ChangesetId>, large_to_small: HashMap<ChangesetId, ChangesetId>,
) -> Arc<dyn HookRejectionRemapper> { ) -> Arc<dyn HookRejectionRemapper> {
Arc::new({ Arc::new({
let large_to_small_commit_syncer = self.large_to_small_commit_syncer.clone(); let large_to_small_commit_syncer = self.large_to_small_commit_syncer.clone();
cloned!(ctx);
move | move |
HookRejection { HookRejection {
hook_name, hook_name,
@ -246,7 +247,7 @@ impl PushRedirector {
/// to be suitable for processing in the large repo /// to be suitable for processing in the large repo
async fn convert_post_resolve_action( async fn convert_post_resolve_action(
&self, &self,
ctx: CoreContext, ctx: &CoreContext,
orig: PostResolveAction, orig: PostResolveAction,
) -> Result<PostResolveAction, Error> { ) -> Result<PostResolveAction, Error> {
use PostResolveAction::*; use PostResolveAction::*;
@ -275,7 +276,7 @@ impl PushRedirector {
/// the large repo /// the large repo
async fn convert_post_resolve_push_action( async fn convert_post_resolve_push_action(
&self, &self,
ctx: CoreContext, ctx: &CoreContext,
orig: PostResolvePush, orig: PostResolvePush,
) -> Result<PostResolvePush, Error> { ) -> Result<PostResolvePush, Error> {
// Note: the `maybe_raw_bundle2_id` field here contains a bundle, which // Note: the `maybe_raw_bundle2_id` field here contains a bundle, which
@ -297,11 +298,11 @@ impl PushRedirector {
} = orig; } = orig;
let uploaded_bonsais = self let uploaded_bonsais = self
.sync_uploaded_changesets(ctx.clone(), uploaded_bonsais, None) .sync_uploaded_changesets(ctx, uploaded_bonsais, None)
.await?; .await?;
let bookmark_pushes = try_join_all(bookmark_pushes.into_iter().map(|bookmark_push| { let bookmark_pushes = try_join_all(bookmark_pushes.into_iter().map(|bookmark_push| {
self.convert_plain_bookmark_push_small_to_large(ctx.clone(), bookmark_push) self.convert_plain_bookmark_push_small_to_large(ctx, bookmark_push)
})) }))
.await?; .await?;
@ -330,7 +331,7 @@ impl PushRedirector {
/// the large repo /// the large repo
async fn convert_post_resolve_pushrebase_action( async fn convert_post_resolve_pushrebase_action(
&self, &self,
ctx: CoreContext, ctx: &CoreContext,
orig: PostResolvePushRebase, orig: PostResolvePushRebase,
) -> Result<PostResolvePushRebase, Error> { ) -> Result<PostResolvePushRebase, Error> {
// Note: the `maybe_raw_bundle2_id` field here contains a bundle, which // Note: the `maybe_raw_bundle2_id` field here contains a bundle, which
@ -354,18 +355,14 @@ impl PushRedirector {
// changesets to be rewritten // changesets to be rewritten
let maybe_renamed_bookmark = self let maybe_renamed_bookmark = self
.small_to_large_commit_syncer .small_to_large_commit_syncer
.rename_bookmark(&ctx, bookmark_spec.get_bookmark_name())?; .rename_bookmark(ctx, bookmark_spec.get_bookmark_name())?;
let uploaded_bonsais = self let uploaded_bonsais = self
.sync_uploaded_changesets( .sync_uploaded_changesets(ctx, uploaded_bonsais, maybe_renamed_bookmark.as_ref())
ctx.clone(),
uploaded_bonsais,
maybe_renamed_bookmark.as_ref(),
)
.await?; .await?;
let bookmark_spec = self let bookmark_spec = self
.convert_pushrebase_bookmark_spec(ctx.clone(), bookmark_spec) .convert_pushrebase_bookmark_spec(ctx, bookmark_spec)
.await?; .await?;
let source_repo = self.small_to_large_commit_syncer.get_source_repo().clone(); let source_repo = self.small_to_large_commit_syncer.get_source_repo().clone();
@ -419,7 +416,7 @@ impl PushRedirector {
/// the large repo /// the large repo
async fn convert_post_resolve_infinitepush_action( async fn convert_post_resolve_infinitepush_action(
&self, &self,
ctx: CoreContext, ctx: &CoreContext,
orig: PostResolveInfinitePush, orig: PostResolveInfinitePush,
) -> Result<PostResolveInfinitePush, Error> { ) -> Result<PostResolveInfinitePush, Error> {
let PostResolveInfinitePush { let PostResolveInfinitePush {
@ -432,11 +429,11 @@ impl PushRedirector {
is_cross_backend_sync, is_cross_backend_sync,
} = orig; } = orig;
let uploaded_bonsais = self let uploaded_bonsais = self
.sync_uploaded_changesets(ctx.clone(), uploaded_bonsais, None) .sync_uploaded_changesets(ctx, uploaded_bonsais, None)
.await?; .await?;
let maybe_bookmark_push = match maybe_bookmark_push { let maybe_bookmark_push = match maybe_bookmark_push {
Some(bookmark_push) => Some( Some(bookmark_push) => Some(
self.convert_infinite_bookmark_push_small_to_large(ctx.clone(), bookmark_push) self.convert_infinite_bookmark_push_small_to_large(ctx, bookmark_push)
.await .await
.context("while converting infinite bookmark push small-to-large")?, .context("while converting infinite bookmark push small-to-large")?,
), ),
@ -458,7 +455,7 @@ impl PushRedirector {
/// direction, to be suitable for a processing in a large repo /// direction, to be suitable for a processing in a large repo
async fn convert_post_resolve_bookmark_only_pushrebase_action( async fn convert_post_resolve_bookmark_only_pushrebase_action(
&self, &self,
ctx: CoreContext, ctx: &CoreContext,
orig: PostResolveBookmarkOnlyPushRebase, orig: PostResolveBookmarkOnlyPushRebase,
) -> Result<PostResolveBookmarkOnlyPushRebase, Error> { ) -> Result<PostResolveBookmarkOnlyPushRebase, Error> {
let PostResolveBookmarkOnlyPushRebase { let PostResolveBookmarkOnlyPushRebase {
@ -470,7 +467,7 @@ impl PushRedirector {
} = orig; } = orig;
let bookmark_push = self let bookmark_push = self
.convert_plain_bookmark_push_small_to_large(ctx.clone(), bookmark_push) .convert_plain_bookmark_push_small_to_large(ctx, bookmark_push)
.await .await
.context("while converting converting plain bookmark push small-to-large")?; .context("while converting converting plain bookmark push small-to-large")?;
@ -489,7 +486,7 @@ impl PushRedirector {
/// to be suitable for response generation in the small repo /// to be suitable for response generation in the small repo
async fn convert_unbundle_response( async fn convert_unbundle_response(
&self, &self,
ctx: CoreContext, ctx: &CoreContext,
orig: UnbundleResponse, orig: UnbundleResponse,
) -> Result<UnbundleResponse, Error> { ) -> Result<UnbundleResponse, Error> {
use UnbundleResponse::*; use UnbundleResponse::*;
@ -521,7 +518,7 @@ impl PushRedirector {
/// direction to be suitable for response generation in the small repo /// direction to be suitable for response generation in the small repo
async fn convert_unbundle_pushrebase_response( async fn convert_unbundle_pushrebase_response(
&self, &self,
ctx: CoreContext, ctx: &CoreContext,
orig: UnbundlePushRebaseResponse, orig: UnbundlePushRebaseResponse,
) -> Result<UnbundlePushRebaseResponse, Error> { ) -> Result<UnbundlePushRebaseResponse, Error> {
let UnbundlePushRebaseResponse { let UnbundlePushRebaseResponse {
@ -546,7 +543,7 @@ impl PushRedirector {
let (pushrebased_rev, pushrebased_changesets) = try_join!( let (pushrebased_rev, pushrebased_changesets) = try_join!(
async { async {
self.remap_changeset_expect_rewritten_or_preserved( self.remap_changeset_expect_rewritten_or_preserved(
ctx.clone(), ctx,
&self.large_to_small_commit_syncer, &self.large_to_small_commit_syncer,
pushrebased_rev, pushrebased_rev,
) )
@ -554,7 +551,7 @@ impl PushRedirector {
.context("while remapping pushrebased rev") .context("while remapping pushrebased rev")
}, },
async { async {
self.convert_pushrebased_changesets(ctx.clone(), pushrebased_changesets) self.convert_pushrebased_changesets(ctx, pushrebased_changesets)
.await .await
.context("while converting pushrebased changesets") .context("while converting pushrebased changesets")
}, },
@ -562,7 +559,7 @@ impl PushRedirector {
let onto = self let onto = self
.large_to_small_commit_syncer .large_to_small_commit_syncer
.rename_bookmark(&ctx, &onto)? .rename_bookmark(ctx, &onto)?
.ok_or(format_err!( .ok_or(format_err!(
"bookmark_renamer unexpectedly dropped {} in {:?}", "bookmark_renamer unexpectedly dropped {} in {:?}",
onto, onto,
@ -582,7 +579,7 @@ impl PushRedirector {
/// direction to be suitable for response generation in the small repo /// direction to be suitable for response generation in the small repo
async fn convert_unbundle_bookmark_only_pushrebase_response( async fn convert_unbundle_bookmark_only_pushrebase_response(
&self, &self,
ctx: CoreContext, ctx: &CoreContext,
orig: UnbundleBookmarkOnlyPushRebaseResponse, orig: UnbundleBookmarkOnlyPushRebaseResponse,
) -> Result<UnbundleBookmarkOnlyPushRebaseResponse, Error> { ) -> Result<UnbundleBookmarkOnlyPushRebaseResponse, Error> {
// `UnbundleBookmarkOnlyPushRebaseResponse` consists of only one field: // `UnbundleBookmarkOnlyPushRebaseResponse` consists of only one field:
@ -604,7 +601,7 @@ impl PushRedirector {
/// direction to be suitable for response generation in the small repo /// direction to be suitable for response generation in the small repo
async fn convert_unbundle_push_response( async fn convert_unbundle_push_response(
&self, &self,
ctx: CoreContext, ctx: &CoreContext,
orig: UnbundlePushResponse, orig: UnbundlePushResponse,
) -> Result<UnbundlePushResponse, Error> { ) -> Result<UnbundlePushResponse, Error> {
// `UnbundlePushResponse` consists of only two fields: // `UnbundlePushResponse` consists of only two fields:
@ -626,7 +623,7 @@ impl PushRedirector {
/// direction to be suitable for response generation in the small repo /// direction to be suitable for response generation in the small repo
async fn convert_unbundle_infinite_push_response( async fn convert_unbundle_infinite_push_response(
&self, &self,
_ctx: CoreContext, _ctx: &CoreContext,
_orig: UnbundleInfinitePushResponse, _orig: UnbundleInfinitePushResponse,
) -> Result<UnbundleInfinitePushResponse, Error> { ) -> Result<UnbundleInfinitePushResponse, Error> {
// TODO: this can only be implemented once we have a way // TODO: this can only be implemented once we have a way
@ -645,7 +642,7 @@ impl PushRedirector {
/// for details /// for details
async fn get_small_to_large_commit_equivalent( async fn get_small_to_large_commit_equivalent(
&self, &self,
ctx: CoreContext, ctx: &CoreContext,
source_cs_id: ChangesetId, source_cs_id: ChangesetId,
) -> Result<ChangesetId, Error> { ) -> Result<ChangesetId, Error> {
self.remap_changeset_expect_rewritten_or_preserved( self.remap_changeset_expect_rewritten_or_preserved(
@ -665,11 +662,11 @@ impl PushRedirector {
/// preserved from a different repo. /// preserved from a different repo.
async fn remap_changeset_expect_rewritten_or_preserved( async fn remap_changeset_expect_rewritten_or_preserved(
&self, &self,
ctx: CoreContext, ctx: &CoreContext,
syncer: &CommitSyncer<Arc<dyn SyncedCommitMapping>>, syncer: &CommitSyncer<Arc<dyn SyncedCommitMapping>>,
cs_id: ChangesetId, cs_id: ChangesetId,
) -> Result<ChangesetId, Error> { ) -> Result<ChangesetId, Error> {
let maybe_commit_sync_outcome = syncer.get_commit_sync_outcome(&ctx, cs_id).await?; let maybe_commit_sync_outcome = syncer.get_commit_sync_outcome(ctx, cs_id).await?;
maybe_commit_sync_outcome maybe_commit_sync_outcome
.ok_or(format_err!( .ok_or(format_err!(
"Unexpected absence of CommitSyncOutcome for {} in {:?}", "Unexpected absence of CommitSyncOutcome for {} in {:?}",
@ -692,7 +689,7 @@ impl PushRedirector {
/// all the syncing is expected to be done prior to calling this fn. /// all the syncing is expected to be done prior to calling this fn.
async fn convert_infinite_bookmark_push_small_to_large( async fn convert_infinite_bookmark_push_small_to_large(
&self, &self,
ctx: CoreContext, ctx: &CoreContext,
orig: InfiniteBookmarkPush<ChangesetId>, orig: InfiniteBookmarkPush<ChangesetId>,
) -> Result<InfiniteBookmarkPush<ChangesetId>, Error> { ) -> Result<InfiniteBookmarkPush<ChangesetId>, Error> {
let maybe_old = orig.old.clone(); let maybe_old = orig.old.clone();
@ -703,12 +700,12 @@ impl PushRedirector {
match maybe_old { match maybe_old {
None => Ok(None), None => Ok(None),
Some(old) => self Some(old) => self
.get_small_to_large_commit_equivalent(ctx.clone(), old) .get_small_to_large_commit_equivalent(ctx, old)
.await .await
.map(Some), .map(Some),
} }
}, },
self.get_small_to_large_commit_equivalent(ctx.clone(), new), self.get_small_to_large_commit_equivalent(ctx, new),
)?; )?;
Ok(InfiniteBookmarkPush { old, new, ..orig }) Ok(InfiniteBookmarkPush { old, new, ..orig })
@ -719,7 +716,7 @@ impl PushRedirector {
/// all the syncing is expected to be done prior to calling this fn. /// all the syncing is expected to be done prior to calling this fn.
async fn convert_plain_bookmark_push_small_to_large( async fn convert_plain_bookmark_push_small_to_large(
&self, &self,
ctx: CoreContext, ctx: &CoreContext,
orig: PlainBookmarkPush<ChangesetId>, orig: PlainBookmarkPush<ChangesetId>,
) -> Result<PlainBookmarkPush<ChangesetId>, Error> { ) -> Result<PlainBookmarkPush<ChangesetId>, Error> {
let PlainBookmarkPush { let PlainBookmarkPush {
@ -745,7 +742,7 @@ impl PushRedirector {
match maybe_old { match maybe_old {
None => Ok(None), None => Ok(None),
Some(old) => self Some(old) => self
.get_small_to_large_commit_equivalent(ctx.clone(), old) .get_small_to_large_commit_equivalent(ctx, old)
.await .await
.map(Some), .map(Some),
} }
@ -754,7 +751,7 @@ impl PushRedirector {
match maybe_new { match maybe_new {
None => Ok(None), None => Ok(None),
Some(new) => self Some(new) => self
.get_small_to_large_commit_equivalent(ctx.clone(), new) .get_small_to_large_commit_equivalent(ctx, new)
.await .await
.map(Some), .map(Some),
} }
@ -763,7 +760,7 @@ impl PushRedirector {
let name = self let name = self
.small_to_large_commit_syncer .small_to_large_commit_syncer
.rename_bookmark(&ctx, &name)? .rename_bookmark(ctx, &name)?
.ok_or(format_err!( .ok_or(format_err!(
"Bookmark {} unexpectedly dropped in {:?}", "Bookmark {} unexpectedly dropped in {:?}",
name, name,
@ -781,14 +778,14 @@ impl PushRedirector {
/// Convert the `PushrebaseBookmarkSpec` struct in the small-to-large direction /// Convert the `PushrebaseBookmarkSpec` struct in the small-to-large direction
async fn convert_pushrebase_bookmark_spec( async fn convert_pushrebase_bookmark_spec(
&self, &self,
ctx: CoreContext, ctx: &CoreContext,
pushrebase_bookmark_spec: PushrebaseBookmarkSpec<ChangesetId>, pushrebase_bookmark_spec: PushrebaseBookmarkSpec<ChangesetId>,
) -> Result<PushrebaseBookmarkSpec<ChangesetId>, Error> { ) -> Result<PushrebaseBookmarkSpec<ChangesetId>, Error> {
match pushrebase_bookmark_spec { match pushrebase_bookmark_spec {
PushrebaseBookmarkSpec::NormalPushrebase(bookmark) => { PushrebaseBookmarkSpec::NormalPushrebase(bookmark) => {
let bookmark = self let bookmark = self
.small_to_large_commit_syncer .small_to_large_commit_syncer
.rename_bookmark(&ctx, &bookmark)? .rename_bookmark(ctx, &bookmark)?
.ok_or(format_err!( .ok_or(format_err!(
"Bookmark {} unexpectedly dropped in {:?}", "Bookmark {} unexpectedly dropped in {:?}",
bookmark, bookmark,
@ -799,7 +796,7 @@ impl PushRedirector {
} }
PushrebaseBookmarkSpec::ForcePushrebase(plain_push) => { PushrebaseBookmarkSpec::ForcePushrebase(plain_push) => {
let converted = self let converted = self
.convert_plain_bookmark_push_small_to_large(ctx.clone(), plain_push) .convert_plain_bookmark_push_small_to_large(ctx, plain_push)
.await?; .await?;
Ok(PushrebaseBookmarkSpec::ForcePushrebase(converted)) Ok(PushrebaseBookmarkSpec::ForcePushrebase(converted))
} }
@ -809,18 +806,18 @@ impl PushRedirector {
/// Convert `PushrebaseChangesetPair` struct in the large-to-small direction /// Convert `PushrebaseChangesetPair` struct in the large-to-small direction
async fn convert_pushrebase_changeset_pair( async fn convert_pushrebase_changeset_pair(
&self, &self,
ctx: CoreContext, ctx: &CoreContext,
pushrebase_changeset_pair: PushrebaseChangesetPair, pushrebase_changeset_pair: PushrebaseChangesetPair,
) -> Result<PushrebaseChangesetPair, Error> { ) -> Result<PushrebaseChangesetPair, Error> {
let PushrebaseChangesetPair { id_old, id_new } = pushrebase_changeset_pair; let PushrebaseChangesetPair { id_old, id_new } = pushrebase_changeset_pair;
let (id_old, id_new) = try_join!( let (id_old, id_new) = try_join!(
self.remap_changeset_expect_rewritten_or_preserved( self.remap_changeset_expect_rewritten_or_preserved(
ctx.clone(), ctx,
&self.large_to_small_commit_syncer, &self.large_to_small_commit_syncer,
id_old id_old
), ),
self.remap_changeset_expect_rewritten_or_preserved( self.remap_changeset_expect_rewritten_or_preserved(
ctx.clone(), ctx,
&self.large_to_small_commit_syncer, &self.large_to_small_commit_syncer,
id_new id_new
), ),
@ -832,12 +829,12 @@ impl PushRedirector {
/// large-to-small direction /// large-to-small direction
async fn convert_pushrebased_changesets( async fn convert_pushrebased_changesets(
&self, &self,
ctx: CoreContext, ctx: &CoreContext,
pushrebased_changesets: Vec<PushrebaseChangesetPair>, pushrebased_changesets: Vec<PushrebaseChangesetPair>,
) -> Result<Vec<PushrebaseChangesetPair>, Error> { ) -> Result<Vec<PushrebaseChangesetPair>, Error> {
try_join_all(pushrebased_changesets.into_iter().map({ try_join_all(pushrebased_changesets.into_iter().map({
|pushrebase_changeset_pair| { |pushrebase_changeset_pair| {
self.convert_pushrebase_changeset_pair(ctx.clone(), pushrebase_changeset_pair) self.convert_pushrebase_changeset_pair(ctx, pushrebase_changeset_pair)
} }
})) }))
.await .await
@ -848,7 +845,7 @@ impl PushRedirector {
/// corresponds to which large cs id /// corresponds to which large cs id
async fn sync_uploaded_changesets( async fn sync_uploaded_changesets(
&self, &self,
ctx: CoreContext, ctx: &CoreContext,
uploaded_map: UploadedBonsais, uploaded_map: UploadedBonsais,
maybe_bookmark: Option<&BookmarkName>, maybe_bookmark: Option<&BookmarkName>,
) -> Result<HashMap<ChangesetId, BonsaiChangeset>, Error> { ) -> Result<HashMap<ChangesetId, BonsaiChangeset>, Error> {
@ -893,7 +890,7 @@ impl PushRedirector {
for bcs_id in to_sync.iter() { for bcs_id in to_sync.iter() {
let synced_bcs_id = self let synced_bcs_id = self
.small_to_large_commit_syncer .small_to_large_commit_syncer
.unsafe_sync_commit(&ctx, *bcs_id, candidate_selection_hint.clone()) .unsafe_sync_commit(ctx, *bcs_id, candidate_selection_hint.clone())
.await? .await?
.ok_or(format_err!( .ok_or(format_err!(
"{} was rewritten into nothingness during uploaded changesets sync", "{} was rewritten into nothingness during uploaded changesets sync",