mirror of
https://github.com/facebook/sapling.git
synced 2024-10-11 17:27:53 +03:00
e988a88be9
Summary: Context: https://fb.workplace.com/groups/rust.language/permalink/3338940432821215/ This codemod replaces *all* dependencies on `//common/rust/renamed:futures-preview` with `fbsource//third-party/rust:futures-preview` and their uses in Rust code from `futures_preview::` to `futures::`. This does not introduce any collisions with `futures::` meaning 0.1 futures because D20168958 previously renamed all of those to `futures_old::` in crates that depend on *both* 0.1 and 0.3 futures. Codemod performed by: ``` rg \ --files-with-matches \ --type-add buck:TARGETS \ --type buck \ --glob '!/experimental' \ --regexp '(_|\b)rust(_|\b)' \ | sed 's,TARGETS$,:,' \ | xargs \ -x \ buck query "labels(srcs, rdeps(%Ss, //common/rust/renamed:futures-preview, 1))" \ | xargs sed -i 's,\bfutures_preview::,futures::,' rg \ --files-with-matches \ --type-add buck:TARGETS \ --type buck \ --glob '!/experimental' \ --regexp '(_|\b)rust(_|\b)' \ | xargs sed -i 's,//common/rust/renamed:futures-preview,fbsource//third-party/rust:futures-preview,' ``` Reviewed By: k21 Differential Revision: D20213432 fbshipit-source-id: 07ee643d350c5817cda1f43684d55084f8ac68a6
77 lines
2.4 KiB
Rust
77 lines
2.4 KiB
Rust
/*
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This software may be used and distributed according to the terms of the
|
|
* GNU General Public License version 2.
|
|
*/
|
|
|
|
use clap::ArgMatches;
|
|
use fbinit::FacebookInit;
|
|
use futures::compat::Future01CompatExt;
|
|
use futures_ext::FutureExt;
|
|
use futures_old::prelude::*;
|
|
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 async fn subcommand_hash_convert<'a>(
|
|
fb: FacebookInit,
|
|
logger: Logger,
|
|
matches: &'a ArgMatches<'_>,
|
|
sub_m: &'a ArgMatches<'_>,
|
|
) -> Result<(), 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(fb, &matches, None);
|
|
let ctx = CoreContext::new_with_logger(fb, logger.clone());
|
|
args::open_repo(fb, &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()
|
|
.compat()
|
|
.await
|
|
}
|