mirror of
https://github.com/facebook/sapling.git
synced 2024-10-10 08:47:12 +03:00
handlers: update location-to-hash endpoint with count parameter
Summary: To reduce the size over the wire on cases where we would be traversing the changelog on the client, we want to allow the endpoint to return a whole parent chain with their hashes. Reviewed By: kulshrax Differential Revision: D23456216 fbshipit-source-id: d048462fa8415d0466dd8e814144347df7a3452a
This commit is contained in:
parent
7122cdded7
commit
932450fb15
@ -60,8 +60,6 @@ pub enum ErrorKind {
|
||||
CompleteTreeRequestFailed,
|
||||
#[error("Dag location to hash request failed")]
|
||||
CommitLocationToHashRequestFailed,
|
||||
#[error("Functionality not implemented")]
|
||||
NotImplemented,
|
||||
#[error("Commit data request failed")]
|
||||
CommitRevlogDataRequestFailed,
|
||||
#[error("HgId not found: {0}")]
|
||||
|
@ -5,7 +5,7 @@
|
||||
* GNU General Public License version 2.
|
||||
*/
|
||||
|
||||
use anyhow::{format_err, Context, Error};
|
||||
use anyhow::{Context, Error};
|
||||
use futures::{stream, StreamExt};
|
||||
use gotham::state::{FromState, State};
|
||||
use gotham_derive::{StateData, StaticResponseExtender};
|
||||
@ -73,19 +73,18 @@ async fn translate_location(
|
||||
hg_repo_ctx: HgRepoContext,
|
||||
location: CommitLocation,
|
||||
) -> Result<CommitLocationToHash, Error> {
|
||||
if location.count != 1 {
|
||||
return Err(
|
||||
format_err!("location to hash with count different that 1 is unimplemented")
|
||||
.context(ErrorKind::NotImplemented),
|
||||
);
|
||||
}
|
||||
let known_descendant = HgChangesetId::new(HgNodeHash::from(location.known_descendant));
|
||||
|
||||
let ancestor: HgChangesetId = hg_repo_ctx
|
||||
.location_to_hg_changeset_id(known_descendant, location.distance_to_descendant)
|
||||
let ancestors: Vec<HgChangesetId> = hg_repo_ctx
|
||||
.location_to_hg_changeset_id(
|
||||
known_descendant,
|
||||
location.distance_to_descendant,
|
||||
location.count,
|
||||
)
|
||||
.await
|
||||
.with_context(|| ErrorKind::CommitLocationToHashRequestFailed)?;
|
||||
let answer = CommitLocationToHash::new(location, ancestor.into_nodehash().into());
|
||||
let converted = ancestors.iter().map(|a| a.into_nodehash().into()).collect();
|
||||
let answer = CommitLocationToHash::new(location, converted);
|
||||
|
||||
Ok(answer)
|
||||
}
|
||||
|
@ -9,10 +9,9 @@ use blobrepo::BlobRepo;
|
||||
use blobrepo_hg::BlobRepoHg;
|
||||
use bytes::Bytes;
|
||||
use context::CoreContext;
|
||||
use futures::{
|
||||
compat::{Future01CompatExt, Stream01CompatExt},
|
||||
TryStream, TryStreamExt,
|
||||
};
|
||||
use futures::compat::{Future01CompatExt, Stream01CompatExt};
|
||||
use futures::future;
|
||||
use futures::{TryStream, TryStreamExt};
|
||||
use hgproto::GettreepackArgs;
|
||||
use mercurial_types::blobs::RevlogChangeset;
|
||||
use mercurial_types::{HgChangesetId, HgFileNodeId, HgManifestId};
|
||||
@ -127,7 +126,8 @@ impl HgRepoContext {
|
||||
&self,
|
||||
known_descendant: HgChangesetId,
|
||||
distance_to_descendant: u64,
|
||||
) -> Result<HgChangesetId, MononokeError> {
|
||||
count: u64,
|
||||
) -> Result<Vec<HgChangesetId>, MononokeError> {
|
||||
let known_descendent_csid = self
|
||||
.blob_repo()
|
||||
.get_bonsai_from_hg(self.ctx().clone(), known_descendant)
|
||||
@ -139,16 +139,18 @@ impl HgRepoContext {
|
||||
known_descendant
|
||||
))
|
||||
})?;
|
||||
let result_csid = self
|
||||
let result_csids = self
|
||||
.repo()
|
||||
.location_to_changeset_id(known_descendent_csid, distance_to_descendant)
|
||||
.location_to_changeset_id(known_descendent_csid, distance_to_descendant, count)
|
||||
.await?;
|
||||
let result = self
|
||||
.blob_repo()
|
||||
.get_hg_from_bonsai_changeset(self.ctx().clone(), result_csid)
|
||||
.compat()
|
||||
.await?;
|
||||
Ok(result)
|
||||
let hg_id_futures = result_csids.iter().map(|result_csid| {
|
||||
self.blob_repo()
|
||||
.get_hg_from_bonsai_changeset(self.ctx().clone(), *result_csid)
|
||||
.compat()
|
||||
});
|
||||
future::try_join_all(hg_id_futures)
|
||||
.await
|
||||
.map_err(MononokeError::from)
|
||||
}
|
||||
|
||||
pub async fn revlog_commit_data(
|
||||
|
@ -1172,7 +1172,8 @@ impl RepoContext {
|
||||
&self,
|
||||
known_descendant: ChangesetId,
|
||||
distance_to_descendant: u64,
|
||||
) -> Result<ChangesetId, MononokeError> {
|
||||
count: u64,
|
||||
) -> Result<Vec<ChangesetId>, MononokeError> {
|
||||
let blob_repo = self.blob_repo();
|
||||
let segmented_changelog =
|
||||
blob_repo
|
||||
@ -1183,7 +1184,12 @@ impl RepoContext {
|
||||
))
|
||||
})?;
|
||||
let ancestor = segmented_changelog
|
||||
.location_to_changeset_id(&self.ctx, known_descendant, distance_to_descendant)
|
||||
.location_to_many_changeset_ids(
|
||||
&self.ctx,
|
||||
known_descendant,
|
||||
distance_to_descendant,
|
||||
count,
|
||||
)
|
||||
.await
|
||||
.map_err(MononokeError::from)?;
|
||||
Ok(ancestor)
|
||||
|
@ -50,7 +50,7 @@ pub struct CommitLocationToHashRequest {
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct CommitLocationToHash {
|
||||
pub location: CommitLocation,
|
||||
pub hgid: HgId,
|
||||
pub hgids: Vec<HgId>,
|
||||
}
|
||||
|
||||
impl CommitLocation {
|
||||
@ -64,8 +64,8 @@ impl CommitLocation {
|
||||
}
|
||||
|
||||
impl CommitLocationToHash {
|
||||
pub fn new(location: CommitLocation, hgid: HgId) -> Self {
|
||||
Self { location, hgid }
|
||||
pub fn new(location: CommitLocation, hgids: Vec<HgId>) -> Self {
|
||||
Self { location, hgids }
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user