From 1da6f656d6f69d4ceb711f0a92df75d8a9ecbc6c Mon Sep 17 00:00:00 2001 From: Jun Wu Date: Wed, 19 Jan 2022 16:35:42 -0800 Subject: [PATCH] edenapi: add pull_lazy client-side implementation Summary: This will replace pull_fast_forward_master. Reviewed By: DurhamG Differential Revision: D33594527 fbshipit-source-id: a8a52567ec2395978228f4c3bf5ff385ad0e6d46 --- eden/scm/lib/edenapi/src/client.rs | 37 ++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/eden/scm/lib/edenapi/src/client.rs b/eden/scm/lib/edenapi/src/client.rs index c2aa2f0b1f..1eadce1bea 100644 --- a/eden/scm/lib/edenapi/src/client.rs +++ b/eden/scm/lib/edenapi/src/client.rs @@ -107,6 +107,7 @@ use crate::retryable::RetryableFiles; use crate::retryable::RetryableStreamRequest; use crate::retryable::RetryableTrees; use crate::types::wire::pull::PullFastForwardRequest; +use crate::types::wire::pull::PullLazyRequest; /// All non-alphanumeric characters (except hypens, underscores, and periods) /// found in the repo's name will be percent-encoded before being used in URLs. @@ -131,6 +132,7 @@ mod paths { pub const COMMIT_REVLOG_DATA: &str = "commit/revlog_data"; pub const CLONE_DATA: &str = "clone"; pub const PULL_FAST_FORWARD: &str = "pull_fast_forward_master"; + pub const PULL_LAZY: &str = "pull_lazy"; pub const COMMIT_LOCATION_TO_HASH: &str = "commit/location_to_hash"; pub const COMMIT_HASH_TO_LOCATION: &str = "commit/hash_to_location"; pub const COMMIT_HASH_LOOKUP: &str = "commit/hash_lookup"; @@ -522,6 +524,21 @@ impl Client { })? } + async fn pull_lazy_attempt( + &self, + req: PullLazyRequest, + ) -> Result, EdenApiError> { + let url = self.build_url(paths::PULL_LAZY)?; + let req = self + .configure_request(self.inner.client.post(url))? + .cbor(&req.to_wire()) + .map_err(EdenApiError::RequestSerializationFailed)?; + let mut fetch = self.fetch::>(vec![req])?; + fetch.entries.next().await.ok_or_else(|| { + EdenApiError::Other(format_err!("clone data missing from reponse body")) + })? + } + async fn fast_forward_pull_attempt( &self, req: PullFastForwardRequest, @@ -794,6 +811,26 @@ impl EdenApi for Client { .await } + async fn pull_lazy( + &self, + common: Vec, + missing: Vec, + ) -> Result, EdenApiError> { + tracing::info!( + "Requesting pull lazy data for the '{}' repository", + self.repo_name() + ); + + self.with_retry(|this| { + let req = PullLazyRequest { + common: common.clone(), + missing: missing.clone(), + }; + this.pull_lazy_attempt(req).boxed() + }) + .await + } + async fn commit_location_to_hash( &self, requests: Vec,