edenapi: build EagerRepo on demand

Summary:
Now EdenApi trait is moved to a separate crate, we can inline the EdenApi
backed by EagerRepo without using dynamic registration functions.

Reviewed By: andll

Differential Revision: D28006553

fbshipit-source-id: 427513da94db228745b1a7e90af0e62296056128
This commit is contained in:
Jun Wu 2021-05-04 16:57:31 -07:00 committed by Facebook GitHub Bot
parent abe4222df9
commit bf409c27d4
4 changed files with 13 additions and 1 deletions

View File

@ -8,7 +8,7 @@ edition = "2018"
anyhow = "1.0"
async-trait = "0.1.45"
dag = { path = "../dag" }
edenapi = { path = "../edenapi" }
edenapi_trait = { path = "../edenapi/trait" }
futures = { version = "0.3.13", features = ["async-await", "compat"] }
http = "0.2"
metalog = { path = "../metalog" }

View File

@ -33,6 +33,7 @@ use edenapi::EdenApiError;
use edenapi::Fetch;
use edenapi::ProgressCallback;
use edenapi::ResponseMeta;
use edenapi_trait as edenapi;
use futures::stream::BoxStream;
use futures::stream::TryStreamExt;
use futures::StreamExt;

View File

@ -18,6 +18,7 @@ chrono = { version = "0.4", features = ["serde"] }
configmodel = { path = "../configmodel" }
configparser = { path = "../configparser" }
dirs = "2.0"
eagerepo = { path = "../eagerepo" }
edenapi_trait = { path = "trait" }
edenapi_types = { path = "types" }
env_logger = "0.7"

View File

@ -16,6 +16,7 @@ use url::Url;
use auth::AuthSection;
use configmodel::ConfigExt;
use eagerepo::EagerRepo;
use http_client::HttpVersion;
use crate::client::Client;
@ -49,6 +50,15 @@ impl<'a> Builder<'a> {
/// Build the client.
pub fn build(self) -> Result<Arc<dyn EdenApi>, EdenApiError> {
for (section, name) in [("paths", "default"), ("edenapi", "url")].iter() {
if let Ok(value) = self.config.get_or_default::<String>(section, name) {
if let Some(path) = EagerRepo::url_to_dir(&value) {
let repo = EagerRepo::open(&path).map_err(|e| EdenApiError::Other(e.into()))?;
return Ok(Arc::new(repo));
}
}
}
let client = Arc::new(
HttpClientBuilder::from_config(self.config)?
.correlator(self.correlator)