add svn rev numbers to mononoke_api crate

Summary: just some boilerplate to make the use from SCS code clean and easy

Reviewed By: StanislavGlebik

Differential Revision: D26453406

fbshipit-source-id: efc280e0be14c3e0f145a489a9fd77b5c0eefa58
This commit is contained in:
Mateusz Kwapich 2021-02-17 12:40:17 -08:00 committed by Facebook GitHub Bot
parent 3b32b1629f
commit db7a5abbf6
3 changed files with 46 additions and 2 deletions

View File

@ -26,7 +26,7 @@ use manifest::{Diff as ManifestDiff, Entry as ManifestEntry, ManifestOps, PathOr
use maplit::hashset;
use mercurial_types::Globalrev;
pub use mononoke_types::Generation;
use mononoke_types::{BonsaiChangeset, FileChange, MPath, MPathElement};
use mononoke_types::{BonsaiChangeset, FileChange, MPath, MPathElement, Svnrev};
use reachabilityindex::ReachabilityIndex;
use unodes::RootUnodeManifestId;
@ -167,6 +167,17 @@ impl ChangesetContext {
Ok(mapping.into_iter().next())
}
/// The SVN revision number for the changeset.
pub async fn svnrev(&self) -> Result<Option<Svnrev>, MononokeError> {
let mapping = self
.repo()
.blob_repo()
.bonsai_svnrev_mapping()
.get_svnrev_from_bonsai(&self.ctx(), self.id)
.await?;
Ok(mapping)
}
/// The git Sha1 for the changeset (if available).
pub async fn git_sha1(&self) -> Result<Option<GitSha1>, MononokeError> {
Ok(self

View File

@ -45,7 +45,7 @@ use metaconfig_types::{
};
use mononoke_types::{
hash::{GitSha1, Sha1, Sha256},
Generation, RepositoryId,
Generation, RepositoryId, Svnrev,
};
use mutable_counters::SqlMutableCounters;
use permission_checker::{ArcPermissionChecker, PermissionCheckerBuilder};
@ -820,6 +820,12 @@ impl RepoContext {
.get_bonsai_from_globalrev(&self.ctx, rev)
.await?
}
ChangesetSpecifier::Svnrev(rev) => {
self.blob_repo()
.bonsai_svnrev_mapping()
.get_bonsai_from_svnrev(&self.ctx, rev)
.await?
}
ChangesetSpecifier::GitSha1(git_sha1) => {
self.blob_repo()
.bonsai_git_mapping()
@ -965,6 +971,22 @@ impl RepoContext {
Ok(mapping)
}
/// Similar to changeset_hg_ids, but returning Svnrevs.
pub async fn changeset_svnrev_ids(
&self,
changesets: Vec<ChangesetId>,
) -> Result<Vec<(ChangesetId, Svnrev)>, MononokeError> {
let mapping = self
.blob_repo()
.bonsai_svnrev_mapping()
.get(&self.ctx, changesets.into())
.await?
.into_iter()
.map(|entry| (entry.bcs_id, entry.svnrev))
.collect();
Ok(mapping)
}
/// Get a list of bookmarks.
pub fn list_bookmarks(
&self,

View File

@ -20,6 +20,9 @@ pub type Globalrev = mercurial_types::Globalrev;
/// A Git SHA-1 hash.
pub type GitSha1 = mononoke_types::hash::GitSha1;
/// A SVN revision number.
pub type Svnrev = mononoke_types::Svnrev;
/// A changeset specifier. This is anything that may be used to specify a
/// unique changeset, such as its bonsai changeset ID, a changeset hash in an
/// alternative hashing scheme, a globally unique hash prefix, or an
@ -30,6 +33,7 @@ pub enum ChangesetSpecifier {
Hg(HgChangesetId),
Globalrev(Globalrev),
GitSha1(GitSha1),
Svnrev(Svnrev),
}
impl From<ChangesetId> for ChangesetSpecifier {
@ -50,6 +54,12 @@ impl From<Globalrev> for ChangesetSpecifier {
}
}
impl From<Svnrev> for ChangesetSpecifier {
fn from(id: Svnrev) -> Self {
Self::Svnrev(id)
}
}
impl From<GitSha1> for ChangesetSpecifier {
fn from(id: GitSha1) -> Self {
Self::GitSha1(id)
@ -142,6 +152,7 @@ impl fmt::Display for ChangesetSpecifier {
ChangesetSpecifier::Hg(hg_cs_id) => write!(f, "hg changeset {}", hg_cs_id),
ChangesetSpecifier::Globalrev(rev) => write!(f, "globalrev {}", rev.id()),
ChangesetSpecifier::GitSha1(git_sha1) => write!(f, "git sha1 {}", git_sha1),
ChangesetSpecifier::Svnrev(rev) => write!(f, "svn rev {}", rev.id()),
}
}
}