From 5858dc309e144d643f633a5128a3b25d3ba0450b Mon Sep 17 00:00:00 2001 From: Kostia Balytskyi Date: Mon, 30 Mar 2020 12:17:03 -0700 Subject: [PATCH] resolver.rs: make Bundle2Resolver contain refs to ctx and repo Summary: As suggested in D20680173, we can reduce the overall need to copy things by storing refs in the resolver. Reviewed By: krallin Differential Revision: D20696588 fbshipit-source-id: 9456e2e208cfef6faed57fc52ca59fafdccfc68c --- eden/mononoke/repo_client/src/client/mod.rs | 2 +- .../repo_client/unbundle/src/resolver.rs | 43 ++++++++----------- eden/mononoke/unbundle_replay/src/main.rs | 2 +- 3 files changed, 21 insertions(+), 26 deletions(-) diff --git a/eden/mononoke/repo_client/src/client/mod.rs b/eden/mononoke/repo_client/src/client/mod.rs index 68c22dd094..ebc49d1af5 100644 --- a/eden/mononoke/repo_client/src/client/mod.rs +++ b/eden/mononoke/repo_client/src/client/mod.rs @@ -1392,7 +1392,7 @@ impl HgCommands for RepoClient { async move { unbundle::resolve( &ctx, - blobrepo, + &blobrepo, infinitepush_writes_allowed, stream, read_write, diff --git a/eden/mononoke/repo_client/unbundle/src/resolver.rs b/eden/mononoke/repo_client/unbundle/src/resolver.rs index 5fa955ac7e..5281a3e7b6 100644 --- a/eden/mononoke/repo_client/unbundle/src/resolver.rs +++ b/eden/mononoke/repo_client/unbundle/src/resolver.rs @@ -198,9 +198,9 @@ pub enum PostResolveAction { /// The resolve function takes a bundle2, interprets it's content as Changesets, Filelogs and /// Manifests and uploades all of them to the provided BlobRepo in the correct order. /// It returns a Future that contains the response that should be send back to the requester. -pub async fn resolve( - ctx: &CoreContext, - repo: BlobRepo, +pub async fn resolve<'a>( + ctx: &'a CoreContext, + repo: &'a BlobRepo, infinitepush_writes_allowed: bool, bundle2: OldBoxStream, readonly: RepoReadOnly, @@ -208,12 +208,7 @@ pub async fn resolve( pure_push_allowed: bool, pushrebase_flags: PushrebaseFlags, ) -> Result { - let resolver = Bundle2Resolver::new( - ctx.clone(), - repo, - infinitepush_writes_allowed, - pushrebase_flags, - ); + let resolver = Bundle2Resolver::new(ctx, repo, infinitepush_writes_allowed, pushrebase_flags); let bundle2 = resolver.resolve_start_and_replycaps(bundle2); let (maybe_commonheads, bundle2) = resolver.maybe_resolve_commonheads(bundle2).await?; @@ -293,9 +288,9 @@ pub async fn resolve( } } -async fn resolve_push( - ctx: &CoreContext, - resolver: Bundle2Resolver, +async fn resolve_push<'r>( + ctx: &'r CoreContext, + resolver: Bundle2Resolver<'r>, bundle2: OldBoxStream, non_fast_forward_policy: NonFastForwardPolicy, maybe_full_content: Option>>, @@ -387,10 +382,10 @@ impl PushrebaseBookmarkSpec { } } -async fn resolve_pushrebase( - ctx: &CoreContext, +async fn resolve_pushrebase<'r>( + ctx: &'r CoreContext, commonheads: CommonHeads, - resolver: Bundle2Resolver, + resolver: Bundle2Resolver<'r>, bundle2: OldBoxStream, maybe_pushvars: Option>, maybe_full_content: Option>>, @@ -501,9 +496,9 @@ async fn resolve_pushrebase( } /// Do the right thing when pushrebase-enabled client only wants to manipulate bookmarks -async fn resolve_bookmark_only_pushrebase( - ctx: &CoreContext, - resolver: Bundle2Resolver, +async fn resolve_bookmark_only_pushrebase<'r>( + ctx: &'r CoreContext, + resolver: Bundle2Resolver<'r>, bundle2: OldBoxStream, non_fast_forward_policy: NonFastForwardPolicy, maybe_full_content: Option>>, @@ -610,17 +605,17 @@ enum Pushkey { /// Holds repo and logger for convienience access from it's methods #[derive(Clone)] -pub struct Bundle2Resolver { - ctx: CoreContext, - repo: BlobRepo, +pub struct Bundle2Resolver<'r> { + ctx: &'r CoreContext, + repo: &'r BlobRepo, infinitepush_writes_allowed: bool, pushrebase_flags: PushrebaseFlags, } -impl Bundle2Resolver { +impl<'r> Bundle2Resolver<'r> { fn new( - ctx: CoreContext, - repo: BlobRepo, + ctx: &'r CoreContext, + repo: &'r BlobRepo, infinitepush_writes_allowed: bool, pushrebase_flags: PushrebaseFlags, ) -> Self { diff --git a/eden/mononoke/unbundle_replay/src/main.rs b/eden/mononoke/unbundle_replay/src/main.rs index 36f58a8aa6..6e2f9f5860 100644 --- a/eden/mononoke/unbundle_replay/src/main.rs +++ b/eden/mononoke/unbundle_replay/src/main.rs @@ -265,7 +265,7 @@ async fn maybe_unbundle( async move { unbundle::resolve( &ctx, - repo, + &repo, false, // infinitepush_writes_allowed Box::new(bundle_stream), RepoReadOnly::ReadWrite,