mirror of
https://github.com/facebook/sapling.git
synced 2024-10-10 08:47:12 +03:00
d71642a013
Summary: Clean up non-test usage of CoreContext::test_mock left over from T37478150 Reviewed By: farnz Differential Revision: D16804838 fbshipit-source-id: f420b8186557a42e9b6c78437c0fb76c9a343b31
72 lines
2.3 KiB
Rust
72 lines
2.3 KiB
Rust
// Copyright (c) 2004-present, Facebook, Inc.
|
|
// All Rights Reserved.
|
|
//
|
|
// This software may be used and distributed according to the terms of the
|
|
// GNU General Public License version 2 or any later version.
|
|
|
|
use clap::ArgMatches;
|
|
use futures::prelude::*;
|
|
use futures_ext::{BoxFuture, FutureExt};
|
|
use std::str::FromStr;
|
|
|
|
use cmdlib::args;
|
|
use context::CoreContext;
|
|
use mercurial_types::HgChangesetId;
|
|
use mononoke_types::ChangesetId;
|
|
use slog::Logger;
|
|
|
|
use crate::error::SubcommandError;
|
|
|
|
pub fn subcommand_hash_convert(
|
|
logger: Logger,
|
|
matches: &ArgMatches<'_>,
|
|
sub_m: &ArgMatches<'_>,
|
|
) -> BoxFuture<(), SubcommandError> {
|
|
let source_hash = sub_m.value_of("HASH").unwrap().to_string();
|
|
let source = sub_m.value_of("from").unwrap().to_string();
|
|
let target = sub_m.value_of("to").unwrap();
|
|
// Check that source and target are different types.
|
|
assert_eq!(
|
|
false,
|
|
(source == "hg") ^ (target == "bonsai"),
|
|
"source and target should be different"
|
|
);
|
|
args::init_cachelib(&matches);
|
|
let ctx = CoreContext::new_with_logger(logger.clone());
|
|
args::open_repo(&logger, &matches)
|
|
.and_then(move |repo| {
|
|
if source == "hg" {
|
|
repo.get_bonsai_from_hg(
|
|
ctx,
|
|
HgChangesetId::from_str(&source_hash)
|
|
.expect("source hash is not valid hg changeset id"),
|
|
)
|
|
.and_then(move |maybebonsai| {
|
|
match maybebonsai {
|
|
Some(bonsai) => {
|
|
println!("{}", bonsai);
|
|
}
|
|
None => {
|
|
panic!("no matching mononoke id found");
|
|
}
|
|
}
|
|
Ok(())
|
|
})
|
|
.left_future()
|
|
} else {
|
|
repo.get_hg_from_bonsai_changeset(
|
|
ctx,
|
|
ChangesetId::from_str(&source_hash)
|
|
.expect("source hash is not valid mononoke id"),
|
|
)
|
|
.and_then(move |mercurial| {
|
|
println!("{}", mercurial);
|
|
Ok(())
|
|
})
|
|
.right_future()
|
|
}
|
|
})
|
|
.from_err()
|
|
.boxify()
|
|
}
|