add git identifiers to Source Control Service

Summary: This allows us to translate git hashes

Reviewed By: markbt

Differential Revision: D19972870

fbshipit-source-id: 871a4cf94d468d987221cb08fe7b6135050bac93
This commit is contained in:
Mateusz Kwapich 2020-02-27 07:41:48 -08:00 committed by Facebook Github Bot
parent 5825db21c6
commit 6f9f82767c
3 changed files with 84 additions and 8 deletions

View File

@ -7,6 +7,7 @@
use std::collections::{BTreeMap, BTreeSet};
use cloned::cloned;
use faster_hex::hex_string;
use futures_util::{future, FutureExt};
use mononoke_api::{ChangesetContext, ChangesetId, MononokeError, RepoContext};
@ -52,6 +53,20 @@ pub(crate) async fn map_commit_identity(
};
scheme_identities.push(identity.boxed());
}
if schemes.contains(&thrift::CommitIdentityScheme::GIT) {
let identity = async {
if let Some(git_sha1) = changeset_ctx.git_sha1().await? {
let result: Result<Option<_>, MononokeError> = Ok(Some((
thrift::CommitIdentityScheme::GIT,
thrift::CommitId::git(git_sha1.as_ref().into()),
)));
result
} else {
Ok(None)
}
};
scheme_identities.push(identity.boxed());
}
let scheme_identities = future::try_join_all(scheme_identities).await?;
for maybe_identity in scheme_identities {
if let Some((scheme, id)) = maybe_identity {
@ -101,6 +116,26 @@ pub(crate) async fn map_commit_identities(
};
scheme_identities.push(identities.boxed());
}
if schemes.contains(&thrift::CommitIdentityScheme::GIT) {
cloned!(ids);
let identities = async {
let bonsai_git_shas = repo_ctx
.changeset_git_sha1s(ids)
.await?
.into_iter()
.map(|(cs_id, git_sha1)| {
(
cs_id,
thrift::CommitIdentityScheme::GIT,
thrift::CommitId::git(git_sha1.as_ref().into()),
)
})
.collect::<Vec<_>>();
let result: Result<_, MononokeError> = Ok(bonsai_git_shas);
result
};
scheme_identities.push(identities.boxed());
}
if schemes.contains(&thrift::CommitIdentityScheme::GLOBALREV) {
let identities = async {
let bonsai_globalrev_ids = repo_ctx

View File

@ -12,7 +12,7 @@ use std::str::FromStr;
use chrono::{DateTime, FixedOffset, TimeZone};
use faster_hex::hex_string;
use mercurial_types::Globalrev;
use mononoke_api::specifiers::{GitSha1, Globalrev};
use mononoke_api::{
ChangesetId, ChangesetIdPrefix, ChangesetPrefixSpecifier, ChangesetSpecifier, CopyInfo,
CreateCopyInfo, FileId, FileType, HgChangesetId, HgChangesetIdPrefix, MononokePath, TreeId,
@ -60,6 +60,17 @@ impl FromRequest<thrift::CommitId> for ChangesetSpecifier {
})?);
Ok(ChangesetSpecifier::Globalrev(rev))
}
thrift::CommitId::git(git_sha1) => {
let git_sha1 = GitSha1::from_bytes(&git_sha1).map_err(|e| {
errors::invalid_request(format!(
"invalid commit id (scheme={} {}): {}",
commit.scheme(),
commit.to_string(),
e
))
})?;
Ok(ChangesetSpecifier::GitSha1(git_sha1))
}
_ => Err(errors::invalid_request(format!(
"unsupported commit identity scheme ({})",
commit.scheme()

View File

@ -7,7 +7,7 @@
$ . "${TEST_FIXTURES}/library.sh"
Setup config repo:
$ setup_common_config
$ POPULATE_GIT_MAPPING=1 setup_common_config
$ cd "$TESTTMP"
Setup testing repo for mononoke:
@ -45,6 +45,13 @@ Commit with globalrev:
$ hg commit -Am "commit with globalrev" --extra global_rev=9999999999
$ hg bookmark -i BOOKMARK_C
Commit git SHA:
$ touch d
$ hg add
adding d
$ hg commit -Am "commit with git sha" --extra convert_revision=37b0a167e07f2b84149c918cec818ffeb183dddd --extra hg-git-rename-source=git
$ hg bookmark -i BOOKMARK_D
A commit with file move and copy
$ hg update -q $COMMIT_B
@ -524,7 +531,7 @@ log skip and time filters conflict
error: The argument '--skip <SKIP>' cannot be used with '--after <AFTER>'
USAGE:
scsc <--tier <TIER>|--host <HOST:PORT>> log --after <AFTER> --limit <LIMIT> --path <PATH> --repo <REPO> --schemes <SCHEMES>... --skip <SKIP> <--commit-id <COMMIT_ID>|--bookmark <BOOKMARK>|--hg-commit-id <HG_COMMIT_ID>|--bonsai-id <BONSAI_ID>|--globalrev <GLOBALREV>>
scsc <--tier <TIER>|--host <HOST:PORT>> log --after <AFTER> --limit <LIMIT> --path <PATH> --repo <REPO> --schemes <SCHEMES>... --skip <SKIP> <--commit-id <COMMIT_ID>|--bookmark <BOOKMARK>|--hg-commit-id <HG_COMMIT_ID>|--bonsai-id <BONSAI_ID>|--git <GIT_SHA1>|--globalrev <GLOBALREV>>
For more information try --help
[1]
@ -538,13 +545,14 @@ log request a single commit
log-check-4
lookup, commit without globalrev
$ scsc lookup --repo repo -B BOOKMARK_B -S bonsai,hg,globalrev
bonsai=c63b71178d240f05632379cf7345e139fe5d4eb1deca50b3e23c26115493bbbb
hg=323afe77a1b1e632e54e8d5a683ba2cc8511f299
lookup, commit with git
$ scsc lookup --repo repo -B BOOKMARK_D -S bonsai,hg,globalrev,git
bonsai=227d4402516061c45a7ba66cf4561bdadaf3ac96eb12c6e75aa9c72dbabd42b6
git=37b0a167e07f2b84149c918cec818ffeb183dddd
hg=6e602c2eaa591b482602f5f3389de6c2749516d5
lookup, commit with globalrev
$ scsc lookup --repo repo -B BOOKMARK_C -S bonsai,hg,globalrev
$ scsc lookup --repo repo -B BOOKMARK_C -S bonsai,hg,globalrev,git
bonsai=006c988c4a9f60080a6bc2a2fff47565fafea2ca5b16c4d994aecdef0c89973b
globalrev=9999999999
hg=ee87eb8cfeb218e7352a94689b241ea973b80402
@ -561,6 +569,10 @@ lookup using globalrev to identify commit
globalrev=9999999999
hg=ee87eb8cfeb218e7352a94689b241ea973b80402
lookup using git to identify commit
$ scsc lookup --repo repo --git 37b0a167e07f2b84149c918cec818ffeb183dddd -S bonsai,hg,globalrev
bonsai=227d4402516061c45a7ba66cf4561bdadaf3ac96eb12c6e75aa9c72dbabd42b6
hg=6e602c2eaa591b482602f5f3389de6c2749516d5
lookup using hg to identify commit
$ scsc lookup --repo repo --hg-commit-id ee87eb8cfeb218e7352a94689b241ea973b80402 -S bonsai,hg,globalrev
bonsai=006c988c4a9f60080a6bc2a2fff47565fafea2ca5b16c4d994aecdef0c89973b
@ -637,6 +649,24 @@ show commit info
commit with globalrev
show commit info for git commit
$ scsc info --repo repo -i 37b0a167e07f2b84149c918cec818ffeb183dddd -S bonsai,hg,globalrev,git
Commit:
bonsai=227d4402516061c45a7ba66cf4561bdadaf3ac96eb12c6e75aa9c72dbabd42b6
git=37b0a167e07f2b84149c918cec818ffeb183dddd
hg=6e602c2eaa591b482602f5f3389de6c2749516d5
Parent:
bonsai=006c988c4a9f60080a6bc2a2fff47565fafea2ca5b16c4d994aecdef0c89973b
globalrev=9999999999
hg=ee87eb8cfeb218e7352a94689b241ea973b80402
Date: 1970-01-01 00:00:00 +00:00
Author: test
Extra:
convert_revision=37b0a167e07f2b84149c918cec818ffeb183dddd
hg-git-rename-source=git
commit with git sha
show tree info
$ scsc info --repo repo -i ee87eb8cfeb218e7352a94689b241ea973b80402 -p ""
Path: