Skip to content

Commit

Permalink
mononoke/megarepotool: make megarepotool public
Browse files Browse the repository at this point in the history
Summary: The tool is used in some integration tests, make it public so that the tests might pass

Differential Revision: D22815283

fbshipit-source-id: 4d7142be46b069586764709d3527d6556e926312
  • Loading branch information
lukaspiatkowski authored and facebook-github-bot committed Jul 29, 2020
1 parent 786b4c4 commit 2d07488
Show file tree
Hide file tree
Showing 12 changed files with 978 additions and 7 deletions.
2 changes: 1 addition & 1 deletion eden/mononoke/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ members = [
"commit_rewriting/cross_repo_sync",
"commit_rewriting/cross_repo_sync/test_utils",
"commit_rewriting/live_commit_sync_config",
"commit_rewriting/megarepolib",
"commit_rewriting/megarepo",
"commit_rewriting/movers",
"commit_rewriting/synced_commit_mapping",
"common/allocation_tracing",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ blobstore = { path = "../../../blobstore" }
bookmarks = { path = "../../../bookmarks" }
context = { path = "../../../server/context" }
cross_repo_sync = { path = ".." }
megarepolib = { path = "../../megarepolib" }
megarepolib = { path = "../../megarepo" }
metaconfig_types = { path = "../../../metaconfig/types" }
mononoke_types = { path = "../../../mononoke_types" }
sql_construct = { path = "../../../common/sql_construct" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,45 @@ edition = "2018"
version = "0.1.0"
authors = ['Facebook']
license = "GPLv2+"
include = ["src/**/*.rs"]
include = ["src/**/*.rs", "tool/**/*.rs"]

[lib]
path = "src/lib.rs"

[[bin]]
name = "megarepotool"
path = "tool/main.rs"

[dependencies]
blobrepo = { path = "../../blobrepo" }
blobrepo_hg = { path = "../../blobrepo/blobrepo_hg" }
blobrepo_utils = { path = "../../blobrepo_utils" }
blobstore = { path = "../../blobstore" }
bookmarks = { path = "../../bookmarks" }
cmdlib = { path = "../../cmdlib" }
context = { path = "../../server/context" }
cross_repo_sync = { path = "../cross_repo_sync" }
manifest = { path = "../../manifest" }
mercurial_types = { path = "../../mercurial/types" }
metaconfig_types = { path = "../../metaconfig/types" }
mononoke_types = { path = "../../mononoke_types" }
movers = { path = "../movers" }
revset = { path = "../../revset" }
skiplist = { path = "../../reachabilityindex/skiplist" }
synced_commit_mapping = { path = "../synced_commit_mapping" }
cloned = { git = "https://github.com/facebookexperimental/rust-shed.git", branch = "master" }
fbinit = { git = "https://github.com/facebookexperimental/rust-shed.git", branch = "master" }
futures_ext = { git = "https://github.com/facebookexperimental/rust-shed.git", branch = "master" }
anyhow = "1.0"
clap = "2.33"
futures = { version = "0.3.5", features = ["async-await", "compat"] }
futures-old = { package = "futures", version = "0.1" }
itertools = "0.8"
maplit = "1.0"
slog = { version = "2.5", features = ["max_level_debug"] }

[dev-dependencies]
fixtures = { path = "../../tests/fixtures" }
tests_utils = { path = "../../tests/utils" }
async_unit = { git = "https://github.com/facebookexperimental/rust-shed.git", branch = "master" }
cloned = { git = "https://github.com/facebookexperimental/rust-shed.git", branch = "master" }
fbinit = { git = "https://github.com/facebookexperimental/rust-shed.git", branch = "master" }
futures-old = { package = "futures", version = "0.1" }
maplit = "1.0"
tokio-compat = "0.1"
160 changes: 160 additions & 0 deletions eden/mononoke/commit_rewriting/megarepo/tool/cli.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
/*
* 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::{format_err, Error};
use bookmarks::BookmarkName;
use clap::{App, Arg, ArgMatches, SubCommand};
use cmdlib::args;
use futures_ext::{try_boxfuture, BoxFuture, FutureExt};
use futures_old::future::{err, ok};
use megarepolib::common::ChangesetArgs;
use mononoke_types::DateTime;

pub const COMMIT_HASH: &'static str = "commit-hash";
pub const MOVE: &'static str = "move";
pub const MERGE: &'static str = "merge";
pub const MARK_PUBLIC: &'static str = "mark-public";
pub const ORIGIN_REPO: &'static str = "origin-repo";
pub const CHANGESET: &'static str = "commit";
pub const FIRST_PARENT: &'static str = "first-parent";
pub const SECOND_PARENT: &'static str = "second-parent";
pub const COMMIT_MESSAGE: &'static str = "commit-message";
pub const COMMIT_AUTHOR: &'static str = "commit-author";
pub const COMMIT_DATE_RFC3339: &'static str = "commit-date-rfc3339";
pub const COMMIT_BOOKMARK: &'static str = "bookmark";
pub const SYNC_DIAMOND_MERGE: &'static str = "sync-diamond-merge";
pub const MAX_NUM_OF_MOVES_IN_COMMIT: &'static str = "max-num-of-moves-in-commit";

pub fn cs_args_from_matches<'a>(sub_m: &ArgMatches<'a>) -> BoxFuture<ChangesetArgs, Error> {
let message = try_boxfuture!(sub_m
.value_of(COMMIT_MESSAGE)
.ok_or_else(|| format_err!("missing argument {}", COMMIT_MESSAGE)))
.to_string();
let author = try_boxfuture!(sub_m
.value_of(COMMIT_AUTHOR)
.ok_or_else(|| format_err!("missing argument {}", COMMIT_AUTHOR)))
.to_string();
let datetime = try_boxfuture!(sub_m
.value_of(COMMIT_DATE_RFC3339)
.map(|datetime_str| DateTime::from_rfc3339(datetime_str))
.unwrap_or_else(|| Ok(DateTime::now())));
let bookmark = try_boxfuture!(sub_m
.value_of(COMMIT_BOOKMARK)
.map(|bookmark_str| BookmarkName::new(bookmark_str))
.transpose());
let mark_public = sub_m.is_present(MARK_PUBLIC);
if !mark_public && bookmark.is_some() {
return err(format_err!(
"--mark-public is required if --bookmark is provided"
))
.boxify();
}

ok(ChangesetArgs {
author,
message,
datetime,
bookmark,
mark_public,
})
.boxify()
}

fn add_resulting_commit_args<'a, 'b>(subcommand: App<'a, 'b>) -> App<'a, 'b> {
subcommand
.arg(
Arg::with_name(COMMIT_AUTHOR)
.help("commit author to use")
.takes_value(true)
.required(true),
)
.arg(
Arg::with_name(COMMIT_MESSAGE)
.help("commit message to use")
.takes_value(true)
.required(true),
)
.arg(
Arg::with_name(MARK_PUBLIC)
.help("add the resulting commit to the public phase")
.long(MARK_PUBLIC),
)
.arg(
Arg::with_name(COMMIT_DATE_RFC3339)
.help("commit date to use (default is now)")
.long(COMMIT_DATE_RFC3339)
.takes_value(true),
)
.arg(
Arg::with_name(COMMIT_BOOKMARK)
.help("bookmark to point to resulting commits (no sanity checks, will move existing bookmark, be careful)")
.long(COMMIT_BOOKMARK)
.takes_value(true)
)
}

pub fn setup_app<'a, 'b>() -> App<'a, 'b> {
let move_subcommand = SubCommand::with_name(MOVE)
.about("create a move commit, using a provided spec")
.arg(
Arg::with_name(MAX_NUM_OF_MOVES_IN_COMMIT)
.long(MAX_NUM_OF_MOVES_IN_COMMIT)
.help("how many files a single commit moves (note - that might create a stack of move commits instead of just one)")
.takes_value(true)
.required(false),
)
.arg(
Arg::with_name(ORIGIN_REPO)
.help("use predefined mover for part of megarepo, coming from this repo")
.takes_value(true)
.required(true),
)
.arg(
Arg::with_name(CHANGESET)
.help("a changeset hash or bookmark of move commit's parent")
.takes_value(true)
.required(true),
);

let merge_subcommand = SubCommand::with_name(MERGE)
.about("create a merge commit with given parents")
.arg(
Arg::with_name(FIRST_PARENT)
.help("first parent of a produced merge commit")
.takes_value(true)
.required(true),
)
.arg(
Arg::with_name(SECOND_PARENT)
.help("second parent of a produced merge commit")
.takes_value(true)
.required(true),
);

let sync_diamond_subcommand = SubCommand::with_name(SYNC_DIAMOND_MERGE)
.about("sync a diamond merge commit from a small repo into large repo")
.arg(
Arg::with_name(COMMIT_HASH)
.help("diamond merge commit from small repo to sync")
.takes_value(true)
.required(true),
)
.arg(
Arg::with_name(COMMIT_BOOKMARK)
.help("bookmark to point to resulting commits (no sanity checks, will move existing bookmark, be careful)")
.long(COMMIT_BOOKMARK)
.takes_value(true)
);

args::MononokeApp::new("megarepo preparation tool")
.with_advanced_args_hidden()
.with_source_and_target_repos()
.build()
.subcommand(add_resulting_commit_args(move_subcommand))
.subcommand(add_resulting_commit_args(merge_subcommand))
.subcommand(sync_diamond_subcommand)
}
Loading

0 comments on commit 2d07488

Please sign in to comment.