mirror of
https://github.com/facebook/sapling.git
synced 2024-10-11 01:07:15 +03:00
18c6ad5b1a
Summary: Pushing compat one level down in main in upload_globalrevs Reviewed By: krallin Differential Revision: D20469436 fbshipit-source-id: 50abf7bb401f4c1d534080e8dc6e341b06e936a9
105 lines
3.1 KiB
Rust
105 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;
|
|
use blobrepo::BlobRepo;
|
|
use blobstore::Loadable;
|
|
use bonsai_globalrev_mapping::{
|
|
bulk_import_globalrevs, BonsaiGlobalrevMapping, SqlBonsaiGlobalrevMapping,
|
|
};
|
|
use bytes::Bytes;
|
|
use changesets::{deserialize_cs_entries, ChangesetEntry};
|
|
use clap::{App, Arg};
|
|
use cloned::cloned;
|
|
use cmdlib::{args, helpers::block_execute};
|
|
use context::CoreContext;
|
|
use fbinit::FacebookInit;
|
|
use futures::compat::Future01CompatExt;
|
|
use futures::future::try_join;
|
|
use futures_ext::{BoxFuture, FutureExt};
|
|
use futures_old::future::{Future, IntoFuture};
|
|
use futures_old::stream;
|
|
use futures_old::stream::Stream;
|
|
use std::fs;
|
|
use std::path::Path;
|
|
use std::sync::Arc;
|
|
|
|
fn setup_app<'a, 'b>() -> App<'a, 'b> {
|
|
args::MononokeApp::new("Tool to upload globalrevs from commits saved in file")
|
|
.build()
|
|
.version("0.0.0")
|
|
.arg(Arg::from_usage(
|
|
"<IN_FILENAME> 'file with bonsai changesets'",
|
|
))
|
|
}
|
|
|
|
fn parse_serialized_commits<P: AsRef<Path>>(file: P) -> Result<Vec<ChangesetEntry>, Error> {
|
|
let data = fs::read(file).map_err(Error::from)?;
|
|
deserialize_cs_entries(&Bytes::from(data))
|
|
}
|
|
|
|
pub fn upload<P: AsRef<Path>>(
|
|
ctx: CoreContext,
|
|
repo: BlobRepo,
|
|
in_path: P,
|
|
globalrevs_store: Arc<dyn BonsaiGlobalrevMapping>,
|
|
) -> BoxFuture<(), Error> {
|
|
let chunk_size = 1000;
|
|
parse_serialized_commits(in_path)
|
|
.into_future()
|
|
.and_then(move |changesets| {
|
|
stream::iter_ok(changesets)
|
|
.map({
|
|
cloned!(ctx, repo);
|
|
move |entry| entry.cs_id.load(ctx.clone(), repo.blobstore()).from_err()
|
|
})
|
|
.buffered(chunk_size)
|
|
.chunks(chunk_size)
|
|
.and_then(move |chunk| {
|
|
bulk_import_globalrevs(
|
|
ctx.clone(),
|
|
repo.get_repoid(),
|
|
globalrevs_store.clone(),
|
|
chunk.iter(),
|
|
)
|
|
})
|
|
.for_each(|_| Ok(()))
|
|
})
|
|
.boxify()
|
|
}
|
|
#[fbinit::main]
|
|
fn main(fb: FacebookInit) -> Result<(), Error> {
|
|
let matches = setup_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 globalrevs_store = args::open_sql::<SqlBonsaiGlobalrevMapping>(fb, &matches);
|
|
|
|
let blobrepo = args::open_repo(fb, &logger, &matches);
|
|
let run = async {
|
|
let (repo, globalrevs_store) =
|
|
try_join(blobrepo.compat(), globalrevs_store.compat()).await?;
|
|
let in_filename = matches.value_of("IN_FILENAME").unwrap();
|
|
let globalrevs_store = Arc::new(globalrevs_store);
|
|
upload(ctx, repo, in_filename, globalrevs_store)
|
|
.compat()
|
|
.await?;
|
|
Ok(())
|
|
};
|
|
|
|
block_execute(
|
|
run,
|
|
fb,
|
|
"upload_globalrevs",
|
|
&logger,
|
|
&matches,
|
|
cmdlib::monitoring::AliveService,
|
|
)
|
|
}
|