mirror of
https://github.com/facebook/sapling.git
synced 2024-10-11 09:17:30 +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
110 lines
3.1 KiB
Rust
110 lines
3.1 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 anyhow::{Error, Result};
|
|
use bytes::Bytes;
|
|
use clap::Arg;
|
|
use cmdlib::{args, helpers::block_execute};
|
|
use context::CoreContext;
|
|
use fbinit::FacebookInit;
|
|
use futures::{
|
|
compat::Future01CompatExt,
|
|
future::TryFutureExt,
|
|
stream::{self, TryStreamExt},
|
|
};
|
|
use futures_ext::FutureExt;
|
|
use lfs_import_lib::lfs_upload;
|
|
use mercurial_types::blobs::File;
|
|
|
|
const NAME: &str = "lfs_import";
|
|
|
|
const ARG_LFS_HELPER: &str = "lfs-helper";
|
|
const ARG_CONCURRENCY: &str = "concurrency";
|
|
const ARG_POINTERS: &str = "pointers";
|
|
const ARG_NO_CREATE: &str = "no-create";
|
|
|
|
const DEFAULT_CONCURRENCY: usize = 16;
|
|
|
|
#[fbinit::main]
|
|
fn main(fb: FacebookInit) -> Result<()> {
|
|
let app = args::MononokeApp::new(NAME)
|
|
.with_advanced_args_hidden()
|
|
.build()
|
|
.version("0.0.0")
|
|
.about("Import LFS blobs")
|
|
.arg(
|
|
Arg::with_name(ARG_CONCURRENCY)
|
|
.long("concurrency")
|
|
.takes_value(true)
|
|
.help("The number of OIDs to process in parallel"),
|
|
)
|
|
.arg(
|
|
Arg::with_name(ARG_NO_CREATE)
|
|
.long(ARG_NO_CREATE)
|
|
.takes_value(false)
|
|
.required(false)
|
|
.help("If provided won't create a new repo"),
|
|
)
|
|
.arg(
|
|
Arg::with_name(ARG_LFS_HELPER)
|
|
.required(true)
|
|
.takes_value(true)
|
|
.help("LFS Helper"),
|
|
)
|
|
.arg(
|
|
Arg::with_name(ARG_POINTERS)
|
|
.takes_value(true)
|
|
.required(true)
|
|
.min_values(1)
|
|
.help("Raw LFS pointers to be imported"),
|
|
);
|
|
|
|
let matches = app.get_matches();
|
|
args::init_cachelib(fb, &matches, None);
|
|
|
|
let logger = args::init_logging(fb, &matches);
|
|
let ctx = CoreContext::new_with_logger(fb, logger.clone());
|
|
let blobrepo = if matches.is_present(ARG_NO_CREATE) {
|
|
args::open_repo(fb, &logger, &matches).left_future()
|
|
} else {
|
|
args::create_repo(fb, &logger, &matches).right_future()
|
|
};
|
|
let lfs_helper = matches.value_of(ARG_LFS_HELPER).unwrap().to_string();
|
|
|
|
let concurrency: usize = matches
|
|
.value_of(ARG_CONCURRENCY)
|
|
.map_or(Ok(DEFAULT_CONCURRENCY), |j| j.parse())
|
|
.map_err(Error::from)?;
|
|
|
|
let entries: Vec<_> = matches
|
|
.values_of(ARG_POINTERS)
|
|
.unwrap()
|
|
.into_iter()
|
|
.map(|e| File::new(Bytes::copy_from_slice(e.as_bytes()), None, None).get_lfs_content())
|
|
.collect();
|
|
|
|
let import = async move {
|
|
let blobrepo = blobrepo.compat().await?;
|
|
stream::iter(entries)
|
|
.try_for_each_concurrent(concurrency, |lfs| {
|
|
lfs_upload(ctx.clone(), blobrepo.clone(), lfs_helper.clone(), lfs)
|
|
.compat()
|
|
.map_ok(|_| ())
|
|
})
|
|
.await
|
|
};
|
|
|
|
block_execute(
|
|
import,
|
|
fb,
|
|
NAME,
|
|
&logger,
|
|
&matches,
|
|
cmdlib::monitoring::AliveService,
|
|
)
|
|
}
|