Skip to content

Commit

Permalink
edenapi_service: support git flavour of slapi for commit graph segments
Browse files Browse the repository at this point in the history
Summary: Enable git as a commit identity scheme for the graph segments endpoint.

Reviewed By: lmvasquezg

Differential Revision: D64134398

fbshipit-source-id: 1b78c472e549b4a2b730f86cbd265e52908a55d9
  • Loading branch information
markbt authored and facebook-github-bot committed Oct 14, 2024
1 parent 389faba commit 5880a1b
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 19 deletions.
64 changes: 45 additions & 19 deletions eden/mononoke/edenapi_service/src/handlers/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -803,42 +803,68 @@ impl SaplingRemoteApiHandler for GraphSegmentsHandler {
const HTTP_METHOD: hyper::Method = hyper::Method::POST;
const API_METHOD: SaplingRemoteApiMethod = SaplingRemoteApiMethod::CommitGraphSegments;
const ENDPOINT: &'static str = "/commit/graph_segments";
const SUPPORTED_FLAVOURS: &'static [SlapiCommitIdentityScheme] = &[
SlapiCommitIdentityScheme::Hg,
SlapiCommitIdentityScheme::Git,
];

async fn handler(
ectx: SaplingRemoteApiContext<Self::PathExtractor, Self::QueryStringExtractor, Repo>,
request: Self::Request,
) -> HandlerResult<'async_trait, Self::Response> {
let slapi_flavour = ectx.slapi_flavour();
let repo = ectx.repo();
let heads: Vec<_> = request
.heads
.into_iter()
.map(|hg_id| HgChangesetId::new(HgNodeHash::from(hg_id)))
.collect();
let common: Vec<_> = request
.common
.into_iter()
.map(|hg_id| HgChangesetId::new(HgNodeHash::from(hg_id)))
.collect();

Ok(try_stream! {
let graph_segments = repo.repo_ctx().graph_segments_hg(common, heads).await?;
let graph_segments = match slapi_flavour {
SlapiCommitIdentityScheme::Hg => {
let heads: Vec<_> = request
.heads
.into_iter()
.map(|hg_id| HgChangesetId::new(HgNodeHash::from(hg_id)))
.collect();
let common: Vec<_> = request
.common
.into_iter()
.map(|hg_id| HgChangesetId::new(HgNodeHash::from(hg_id)))
.collect();
repo.repo_ctx()
.graph_segments_hg(common, heads)
.await?
.map_ok(|segment| segment.map_ids(|id| HgId::from(id.into_nodehash())))
.left_stream()
}
SlapiCommitIdentityScheme::Git => {
let heads: Vec<_> = request
.heads
.into_iter()
.map(|id| GitSha1::from(id.into_byte_array()))
.collect();
let common: Vec<_> = request
.common
.into_iter()
.map(|id| GitSha1::from(id.into_byte_array()))
.collect();
repo.repo_ctx()
.graph_segments_git(common, heads)
.await?
.map_ok(|segment| segment.map_ids(|id| HgId::from(id.into_inner())))
.right_stream()
}
};

for await segment in graph_segments {
let segment = segment?;
yield CommitGraphSegmentsEntry {
head: HgId::from(segment.head.into_nodehash()),
base: HgId::from(segment.base.into_nodehash()),
head: segment.head,
base: segment.base,
length: segment.length,
parents: segment
.parents
.into_iter()
.map(|parent| CommitGraphSegmentParent {
hgid: HgId::from(parent.id.into_nodehash()),
location: parent.location.map(|location| {
location.map_descendant(|descendant| {
HgId::from(descendant.into_nodehash())
})
}),
hgid: parent.id,
location: parent.location,
})
.collect(),
}
Expand Down
26 changes: 26 additions & 0 deletions eden/mononoke/mononoke_api/src/repo/commit_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,37 @@ pub struct ChangesetSegment<Id> {
pub parents: Vec<ChangesetSegmentParent<Id>>,
}

impl<Id> ChangesetSegment<Id> {
pub fn map_ids<NewId>(self, map_id: impl Fn(Id) -> NewId + Clone) -> ChangesetSegment<NewId> {
ChangesetSegment {
head: map_id(self.head),
base: map_id(self.base),
length: self.length,
parents: self
.parents
.into_iter()
.map(|parent| parent.map_ids(map_id.clone()))
.collect(),
}
}
}

pub struct ChangesetSegmentParent<Id> {
pub id: Id,
pub location: Option<Location<Id>>,
}

impl<Id> ChangesetSegmentParent<Id> {
pub fn map_ids<NewId>(self, map_id: impl Fn(Id) -> NewId) -> ChangesetSegmentParent<NewId> {
ChangesetSegmentParent {
id: map_id(self.id),
location: self
.location
.map(|location| location.map_descendant(map_id)),
}
}
}

impl<R: MononokeRepo> RepoContext<R> {
fn make_graph_segments_stream<Id: Copy + 'static>(
&self,
Expand Down

0 comments on commit 5880a1b

Please sign in to comment.