mirror of
https://github.com/facebook/sapling.git
synced 2024-10-10 16:57:49 +03:00
add into_response that would map commit ids across identity schemes
Summary: This way we can go from list of changesets into changet ids that we're returning as an answer in few queries. Differential Revision: D22165005 fbshipit-source-id: 4da8ab2a89be0de34b2870044e44d35424be5510
This commit is contained in:
parent
ca644e16a3
commit
398ab603c2
@ -132,6 +132,11 @@ impl ChangesetContext {
|
||||
self.id
|
||||
}
|
||||
|
||||
pub fn into_repo_and_id(self) -> (RepoContext, ChangesetId) {
|
||||
let Self { repo, id, .. } = self;
|
||||
(repo, id)
|
||||
}
|
||||
|
||||
/// The Mercurial ID for the changeset.
|
||||
pub async fn hg_id(&self) -> Result<Option<HgChangesetId>, MononokeError> {
|
||||
let mapping = self
|
||||
|
@ -38,7 +38,7 @@ use metaconfig_types::{CommitSyncConfig, SourceControlServiceParams};
|
||||
use metaconfig_types::{CommonConfig, RepoConfig};
|
||||
use mononoke_types::{
|
||||
hash::{GitSha1, Sha1, Sha256},
|
||||
Generation,
|
||||
Generation, RepositoryId,
|
||||
};
|
||||
use permission_checker::{ArcPermissionChecker, MononokeIdentitySet, PermissionCheckerBuilder};
|
||||
use revset::AncestorsNodeStream;
|
||||
@ -50,6 +50,7 @@ use sql_construct::SqlConstruct;
|
||||
use sql_ext::facebook::MysqlOptions;
|
||||
use stats::prelude::*;
|
||||
use std::collections::HashSet;
|
||||
use std::hash::{Hash, Hasher};
|
||||
use synced_commit_mapping::{SqlSyncedCommitMapping, SyncedCommitMapping};
|
||||
use warm_bookmarks_cache::WarmBookmarksCache;
|
||||
|
||||
@ -563,10 +564,15 @@ impl RepoContext {
|
||||
}
|
||||
|
||||
/// The name of the underlying repo.
|
||||
pub(crate) fn name(&self) -> &str {
|
||||
pub fn name(&self) -> &str {
|
||||
&self.repo.name
|
||||
}
|
||||
|
||||
/// The internal id of the repo. Used for comparing the repo objects with each other.
|
||||
pub fn repoid(&self) -> RepositoryId {
|
||||
self.repo.blob_repo.get_repoid()
|
||||
}
|
||||
|
||||
/// The underlying `BlobRepo`.
|
||||
pub(crate) fn blob_repo(&self) -> &BlobRepo {
|
||||
&self.repo.blob_repo
|
||||
@ -1080,3 +1086,16 @@ mod tests {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for RepoContext {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.repoid() == other.repoid()
|
||||
}
|
||||
}
|
||||
impl Eq for RepoContext {}
|
||||
|
||||
impl Hash for RepoContext {
|
||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||
self.repoid().hash(state);
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,9 @@
|
||||
*/
|
||||
|
||||
use async_trait::async_trait;
|
||||
use futures::future::try_join_all;
|
||||
use futures_util::try_join;
|
||||
use itertools::Itertools;
|
||||
use mononoke_api::{
|
||||
ChangesetContext, ChangesetPathContext, ChangesetPathDiffContext, FileMetadata, FileType,
|
||||
MononokeError, TreeEntry, UnifiedDiff,
|
||||
@ -198,3 +200,44 @@ impl AsyncIntoResponse<thrift::CommitInfo>
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl AsyncIntoResponse<Vec<BTreeMap<thrift::CommitIdentityScheme, thrift::CommitId>>>
|
||||
for (
|
||||
Vec<ChangesetContext>,
|
||||
&BTreeSet<thrift::CommitIdentityScheme>,
|
||||
)
|
||||
{
|
||||
async fn into_response(
|
||||
self,
|
||||
) -> Result<Vec<BTreeMap<thrift::CommitIdentityScheme, thrift::CommitId>>, errors::ServiceError>
|
||||
{
|
||||
let (changesets, identity_schemes) = self;
|
||||
let res = try_join_all({
|
||||
let changesets_grouped_by_repo = changesets
|
||||
.into_iter()
|
||||
.map(|c| c.into_repo_and_id())
|
||||
.into_group_map();
|
||||
|
||||
changesets_grouped_by_repo
|
||||
.into_iter()
|
||||
.map(|(repo, changesets)| async move {
|
||||
Ok::<
|
||||
Vec<BTreeMap<thrift::CommitIdentityScheme, thrift::CommitId>>,
|
||||
errors::ServiceError,
|
||||
>(
|
||||
map_commit_identities(&repo, changesets, identity_schemes)
|
||||
.await?
|
||||
.into_iter()
|
||||
.map(|(_k, v)| v)
|
||||
.collect(),
|
||||
)
|
||||
})
|
||||
})
|
||||
.await?
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.collect();
|
||||
Ok(res)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user