From a689d5260d4e8afb69aeeba07293427c7538ad40 Mon Sep 17 00:00:00 2001 From: Rajiv Sharma Date: Thu, 5 Dec 2024 09:15:55 -0800 Subject: [PATCH] Add factory constructors for git ref content mapping facet Summary: We would need this facet in the repo definition for Mononoke Git server so we need to add factory constructors for it which this diff does. Reviewed By: mitrandir77 Differential Revision: D66651008 fbshipit-source-id: 7ced915b60117d7bfb0abbcc104f6c240db54900 --- eden/mononoke/repo_factory/Cargo.toml | 1 + eden/mononoke/repo_factory/src/lib.rs | 19 +++++++++++++++++++ .../repo_factory/test_repo_factory/Cargo.toml | 1 + .../repo_factory/test_repo_factory/src/lib.rs | 14 ++++++++++++++ 4 files changed, 35 insertions(+) diff --git a/eden/mononoke/repo_factory/Cargo.toml b/eden/mononoke/repo_factory/Cargo.toml index cad38020826ba..0295a79b2855e 100644 --- a/eden/mononoke/repo_factory/Cargo.toml +++ b/eden/mononoke/repo_factory/Cargo.toml @@ -40,6 +40,7 @@ fbinit = { version = "0.2.0", git = "https://github.com/facebookexperimental/rus filenodes = { version = "0.1.0", path = "../filenodes" } filestore = { version = "0.1.0", path = "../filestore" } futures_watchdog = { version = "0.1.0", path = "../common/futures_watchdog" } +git_ref_content_mapping = { version = "0.1.0", path = "../git_ref_content_mapping" } git_source_of_truth = { version = "0.1.0", path = "../git_source_of_truth" } git_symbolic_refs = { version = "0.1.0", path = "../git_symbolic_refs" } hook_manager = { version = "0.1.0", path = "../repo_attributes/hook_manager/hook_manager" } diff --git a/eden/mononoke/repo_factory/src/lib.rs b/eden/mononoke/repo_factory/src/lib.rs index bdedb4617d7d8..cdd7eb88b9ab1 100644 --- a/eden/mononoke/repo_factory/src/lib.rs +++ b/eden/mononoke/repo_factory/src/lib.rs @@ -104,6 +104,8 @@ use filenodes::ArcFilenodes; use filestore::ArcFilestoreConfig; use filestore::FilestoreConfig; use futures_watchdog::WatchdogExt; +use git_ref_content_mapping::ArcGitRefContentMapping; +use git_ref_content_mapping::SqlGitRefContentMappingBuilder; use git_source_of_truth::ArcGitSourceOfTruthConfig; use git_source_of_truth::SqlGitSourceOfTruthConfigBuilder; use git_symbolic_refs::ArcGitSymbolicRefs; @@ -778,6 +780,9 @@ pub enum RepoFactoryError { #[error("Error opening bonsai-tag mapping")] BonsaiTagMapping, + #[error("Error opening git-ref-content mapping")] + GitRefContentMapping, + #[error("Error opening git-symbolic-refs")] GitSymbolicRefs, @@ -1031,6 +1036,20 @@ impl RepoFactory { Ok(Arc::new(bonsai_tag_mapping)) } + pub async fn git_ref_content_mapping( + &self, + repo_config: &ArcRepoConfig, + repo_identity: &ArcRepoIdentity, + ) -> Result { + let git_ref_content_mapping = self + .open_sql::(repo_config) + .await + .context(RepoFactoryError::GitRefContentMapping)? + .build(repo_identity.id()); + // TODO(rajshar): Add caching for git_ref_content_mapping + Ok(Arc::new(git_ref_content_mapping)) + } + pub async fn git_symbolic_refs( &self, repo_config: &ArcRepoConfig, diff --git a/eden/mononoke/repo_factory/test_repo_factory/Cargo.toml b/eden/mononoke/repo_factory/test_repo_factory/Cargo.toml index 33f1774a9c9ad..68797d66042c5 100644 --- a/eden/mononoke/repo_factory/test_repo_factory/Cargo.toml +++ b/eden/mononoke/repo_factory/test_repo_factory/Cargo.toml @@ -28,6 +28,7 @@ facet = { version = "0.1.0", git = "https://github.com/facebookexperimental/rust fbinit = { version = "0.2.0", git = "https://github.com/facebookexperimental/rust-shed.git", branch = "main" } filenodes = { version = "0.1.0", path = "../../filenodes" } filestore = { version = "0.1.0", path = "../../filestore" } +git_ref_content_mapping = { version = "0.1.0", path = "../../git_ref_content_mapping" } git_source_of_truth = { version = "0.1.0", path = "../../git_source_of_truth" } git_symbolic_refs = { version = "0.1.0", path = "../../git_symbolic_refs" } hook_manager = { version = "0.1.0", path = "../../repo_attributes/hook_manager/hook_manager" } diff --git a/eden/mononoke/repo_factory/test_repo_factory/src/lib.rs b/eden/mononoke/repo_factory/test_repo_factory/src/lib.rs index 51c6769c7f9ae..a2ce576bcff7a 100644 --- a/eden/mononoke/repo_factory/test_repo_factory/src/lib.rs +++ b/eden/mononoke/repo_factory/test_repo_factory/src/lib.rs @@ -46,6 +46,8 @@ use fbinit::FacebookInit; use filenodes::ArcFilenodes; use filestore::ArcFilestoreConfig; use filestore::FilestoreConfig; +use git_ref_content_mapping::ArcGitRefContentMapping; +use git_ref_content_mapping::SqlGitRefContentMappingBuilder; use git_source_of_truth::ArcGitSourceOfTruthConfig; use git_source_of_truth::SqlGitSourceOfTruthConfigBuilder; use git_symbolic_refs::ArcGitSymbolicRefs; @@ -489,6 +491,18 @@ impl TestRepoFactory { )) } + /// Construct Git Ref Content Mapping using the in-memory metadata + /// database. + pub fn git_ref_content_mapping( + &self, + repo_identity: &ArcRepoIdentity, + ) -> Result { + Ok(Arc::new( + SqlGitRefContentMappingBuilder::from_sql_connections(self.metadata_db.clone()) + .build(repo_identity.id()), + )) + } + /// Construct Repo Metadata Checkpoint using the in-memory metadata pub fn repo_metadata_checkpoint( &self,