mononoke: migrate megarepotool move subcommand to core mononoke movers

Summary:
Rather than using hardcoded path maps and ad-hoc moveres, lets use the
logic which creates moves from config.

Reviewed By: farnz

Differential Revision: D17424678

fbshipit-source-id: 64a0a0b1c7332661408444a6d81f5931ed680c3c
This commit is contained in:
Kostia Balytskyi 2019-09-19 03:19:48 -07:00 committed by Facebook Github Bot
parent 9efd8b1a5d
commit e972a82545
4 changed files with 69 additions and 22 deletions

View File

@ -760,13 +760,7 @@ pub fn get_usize<'a>(matches: &ArgMatches<'a>, key: &str, default: usize) -> usi
#[inline]
pub fn get_u64<'a>(matches: &ArgMatches<'a>, key: &str, default: u64) -> u64 {
matches
.value_of(key)
.map(|val| {
val.parse::<u64>()
.expect(&format!("{} must be integer", key))
})
.unwrap_or(default)
get_u64_opt(matches, key).unwrap_or(default)
}
#[inline]
@ -777,15 +771,17 @@ pub fn get_u64_opt<'a>(matches: &ArgMatches<'a>, key: &str) -> Option<u64> {
})
}
#[inline]
pub fn get_i32_opt<'a>(matches: &ArgMatches<'a>, key: &str) -> Option<i32> {
matches.value_of(key).map(|val| {
val.parse::<i32>()
.expect(&format!("{} must be integer", key))
})
}
#[inline]
pub fn get_i32<'a>(matches: &ArgMatches<'a>, key: &str, default: i32) -> i32 {
matches
.value_of(key)
.map(|val| {
val.parse::<i32>()
.expect(&format!("{} must be integer", key))
})
.unwrap_or(default)
get_i32_opt(matches, key).unwrap_or(default)
}
#[inline]

View File

@ -0,0 +1,46 @@
# Common definition for commit sync path mapping
#
# A top-level config must have a name and a repo-id of a large repo
# It may have multiple subconfigs, named `<top-level-name>.small_repos`
# Each of the the `small_repos` configs MUST have:
# - a repo id
# - a bookmark prefix to prepend to every bookmark name
# - a default path syncing action. Is used when none of the
# "map" values matches a path. Can be one of:
# - "preserve": keep this path as it is when syncing
# - "prepend_prefix": prepend the "default_prefix" to this path
# when syncing
# Each of the `small_repos` configs MAY have:
# - a map of prefixes to new prefixes, key "map"
#
# Note: config is written from the "bottom-up" perspective, e.g.
# it contains mappings, needed to sync small repos into a
# a large repo. This mapping needs to be reversable
# (and is reversed when the sync happens in a large-to-small
# direction)
[megarepo_test]
large_repo_id = 0
direction = "small_to_large"
common_pushrebase_bookmarks = ["master"]
[[megarepo_test.small_repos]]
repoid = 1
bookmark_prefix = "fbsource"
default_action = "preserve"
[megarepo_test.small_repos.map]
"arvr" = ".fbsource-rest/arvr"
[[megarepo_test.small_repos]]
repoid = 2
bookmark_prefix = "ovrsource"
default_action = "prepend_prefix"
default_prefix = "arvr-legacy"
[megarepo_test.small_repos.map]
"arvr" = "arvr"
"fbcode" = ".ovrsource-rest/fbcode"
"fbandroid" = ".ovrsource-rest/fbandroid"
"fbobjc" = ".ovrsource-rest/fbobjc"
"xplat" = ".ovrsource-rest/xplat"

View File

@ -369,6 +369,10 @@ db.local_db_path = "$TESTTMP/disabled_repo"
CONFIG
}
function setup_commitsyncmap {
cp "$TEST_FIXTURES/commitsyncmap.toml" "$TESTTMP/mononoke-config/common/commitsyncmap.toml"
}
function setup_mononoke_repo_config {
cd "$TESTTMP/mononoke-config" || exit
local reponame="$1"

View File

@ -4,6 +4,7 @@ setup configuration
$ REPOTYPE="blob:files"
$ setup_common_config $REPOTYPE
$ setup_commitsyncmap
$ cd $TESTTMP
@ -23,7 +24,7 @@ setup hg server repo
$ hg ci -m "fbsource-like commit"
$ hg book -r . fbsourcemaster
-- create soem semblance of ovrsource
-- create some semblance of ovrsource
$ hg up null -q
$ createfile fbcode/fbcodfile_ovrsource
$ createfile fbobjc/fbobjcfile_ovrsource
@ -50,23 +51,23 @@ blobimport
$ export COMMIT_DATE="1985-04-12T23:20:50.52Z"
move things in fbsource
$ megarepo_tool move fbsource 4da689e6447cf99bbc121eaa7b05ea1504cf2f7c user "fbsource move" --mark-public --commit-date-rfc3339 "$COMMIT_DATE"
$ megarepo_tool move 1 4da689e6447cf99bbc121eaa7b05ea1504cf2f7c user "fbsource move" --mark-public --commit-date-rfc3339 "$COMMIT_DATE"
* using repo "repo" repoid RepositoryId(0) (glob)
* Requesting the hg changeset (glob)
* Hg changeset: HgChangesetId(HgNodeHash(Sha1(ed8feccfa30ef541a15a1616e4e4db66ee7f91e2))) (glob)
* Hg changeset: HgChangesetId(HgNodeHash(Sha1(2d1c2ac8acbc245768933d05d23bd248cf6a16bb))) (glob)
* Marking changeset as public (glob)
* Done marking as public (glob)
move things in ovrsource
$ megarepo_tool move ovrsource 4d79e7d65a781c6c80b3ee4faf63452e8beafa97 user "ovrsource move" --mark-public --commit-date-rfc3339 "$COMMIT_DATE"
$ megarepo_tool move 2 4d79e7d65a781c6c80b3ee4faf63452e8beafa97 user "ovrsource move" --mark-public --commit-date-rfc3339 "$COMMIT_DATE"
* using repo "repo" repoid RepositoryId(0) (glob)
* Requesting the hg changeset (glob)
* Hg changeset: HgChangesetId(HgNodeHash(Sha1(88783bf39cdb412fbc8762d45bad226470b381c6))) (glob)
* Hg changeset: HgChangesetId(HgNodeHash(Sha1(3c5f72c6d1ed24bd0914ff5ecd96b98f216002b4))) (glob)
* Marking changeset as public (glob)
* Done marking as public (glob)
merge things in both repos
$ megarepo_tool merge ed8feccfa30ef541a15a1616e4e4db66ee7f91e2 88783bf39cdb412fbc8762d45bad226470b381c6 user "megarepo merge" --mark-public --commit-date-rfc3339 "$COMMIT_DATE"
$ megarepo_tool merge 2d1c2ac8acbc245768933d05d23bd248cf6a16bb 3c5f72c6d1ed24bd0914ff5ecd96b98f216002b4 user "megarepo merge" --mark-public --commit-date-rfc3339 "$COMMIT_DATE"
* using repo "repo" repoid RepositoryId(0) (glob)
* Creating a merge commit (glob)
* Checking if there are any path conflicts (glob)
@ -74,8 +75,8 @@ merge things in both repos
* Creating a merge bonsai changeset with parents: * (glob)
* Marked as public * (glob)
* Created *. Generating an HG equivalent (glob)
* Hg changeset: HgChangesetId(HgNodeHash(Sha1(fa2c1aadd78fd99ca6e45a0e1d8b5a80182cf908))) (glob)
$ mononoke_admin bookmarks set master fa2c1aadd78fd99ca6e45a0e1d8b5a80182cf908
* Hg changeset: HgChangesetId(HgNodeHash(Sha1(0383059155f1a61cdba994a8bb686c15f378794b))) (glob)
$ mononoke_admin bookmarks set master 0383059155f1a61cdba994a8bb686c15f378794b
* using repo "repo" repoid RepositoryId(0) (glob)
start mononoke server