From 445bfb39b8acd22dfdabd5170b47d1c47a02b674 Mon Sep 17 00:00:00 2001 From: Mark Juggurnauth-Thomas Date: Tue, 31 Dec 2024 06:39:13 -0800 Subject: [PATCH] tools/admin: print missing parts of cross-repo configs Summary: The admin command for printing cross-repo config is missing the newly added Git submodule expansion fields. Add them to the output, as well as a new command for printing the common config. Reviewed By: RajivTS Differential Revision: D67735987 fbshipit-source-id: a90b29e9bd821bda0eec1c5102805ce4966d041a --- .../newadmin/test-admin-cross-repo-config.t | 40 ++++++--- .../admin/src/commands/cross_repo_config.rs | 83 +++++++++++++++++-- 2 files changed, 102 insertions(+), 21 deletions(-) diff --git a/eden/mononoke/tests/integration/newadmin/test-admin-cross-repo-config.t b/eden/mononoke/tests/integration/newadmin/test-admin-cross-repo-config.t index d71118b433dae..81090ba04e72b 100644 --- a/eden/mononoke/tests/integration/newadmin/test-admin-cross-repo-config.t +++ b/eden/mononoke/tests/integration/newadmin/test-admin-cross-repo-config.t @@ -18,13 +18,14 @@ setup configerator configs $ mononoke_admin cross-repo-config -R repo list --with-contents TEST_VERSION_NAME: large repo: 0 - common pushrebase bookmarks: [BookmarkKey { name: BookmarkName { bookmark: "master_bookmark" }, category: Branch }] + common pushrebase bookmarks: ["master_bookmark"] version name: TEST_VERSION_NAME - small repo: 1 + small repo: 1 default action: Preserve prefix map: arvr->.fbsource-rest/arvr - small repo: 2 + submodule action: Strip + small repo: 2 default action: PrependPrefix(NonRootMPath("arvr-legacy")) prefix map: arvr->arvr @@ -32,20 +33,22 @@ setup configerator configs fbcode->.ovrsource-rest/fbcode fbobjc->.ovrsource-rest/fbobjc xplat->.ovrsource-rest/xplat + submodule action: Strip TEST_VERSION_NAME_COMPLEX: large repo: 0 - common pushrebase bookmarks: [BookmarkKey { name: BookmarkName { bookmark: "master_bookmark" }, category: Branch }] + common pushrebase bookmarks: ["master_bookmark"] version name: TEST_VERSION_NAME_COMPLEX - small repo: 1 + small repo: 1 default action: Preserve prefix map: a/b/c1->ma/b/c1 a/b/c2->ma/b/c2 arvr->.fbsource-rest/arvr d/e->ma/b/c2/d/e - small repo: 2 + submodule action: Strip + small repo: 2 default action: PrependPrefix(NonRootMPath("arvr-legacy")) prefix map: a/b/c1->ma/b/c1 @@ -56,17 +59,19 @@ setup configerator configs fbcode->.ovrsource-rest/fbcode fbobjc->.ovrsource-rest/fbobjc xplat->.ovrsource-rest/xplat + submodule action: Strip TEST_VERSION_NAME_OLD: large repo: 0 - common pushrebase bookmarks: [BookmarkKey { name: BookmarkName { bookmark: "master_bookmark" }, category: Branch }] + common pushrebase bookmarks: ["master_bookmark"] version name: TEST_VERSION_NAME_OLD - small repo: 1 + small repo: 1 default action: Preserve prefix map: arvr->.fbsource-rest/arvr_old - small repo: 2 + submodule action: Strip + small repo: 2 default action: PrependPrefix(NonRootMPath("arvr-legacy")) prefix map: arvr->arvr @@ -74,17 +79,19 @@ setup configerator configs fbcode->.ovrsource-rest/fbcode_old fbobjc->.ovrsource-rest/fbobjc xplat->.ovrsource-rest/xplat + submodule action: Strip $ mononoke_admin cross-repo-config -R repo by-version TEST_VERSION_NAME_OLD large repo: 0 - common pushrebase bookmarks: [BookmarkKey { name: BookmarkName { bookmark: "master_bookmark" }, category: Branch }] + common pushrebase bookmarks: ["master_bookmark"] version name: TEST_VERSION_NAME_OLD - small repo: 1 + small repo: 1 default action: Preserve prefix map: arvr->.fbsource-rest/arvr_old - small repo: 2 + submodule action: Strip + small repo: 2 default action: PrependPrefix(NonRootMPath("arvr-legacy")) prefix map: arvr->arvr @@ -92,3 +99,12 @@ setup configerator configs fbcode->.ovrsource-rest/fbcode_old fbobjc->.ovrsource-rest/fbobjc xplat->.ovrsource-rest/xplat + submodule action: Strip + + $ mononoke_admin cross-repo-config -R repo common + large repo: 0 + common pushrebase bookmarks: ["master_bookmark"] + small repo: 1 + bookmark prefix: fbsource/ + small repo: 2 + bookmark prefix: ovrsource/ diff --git a/eden/mononoke/tools/admin/src/commands/cross_repo_config.rs b/eden/mononoke/tools/admin/src/commands/cross_repo_config.rs index b53bb3d85fbb7..465706aa1c642 100644 --- a/eden/mononoke/tools/admin/src/commands/cross_repo_config.rs +++ b/eden/mononoke/tools/admin/src/commands/cross_repo_config.rs @@ -13,6 +13,7 @@ use context::CoreContext; use itertools::Itertools; use metaconfig_types::CommitSyncConfig; use metaconfig_types::CommitSyncConfigVersion; +use metaconfig_types::DEFAULT_GIT_SUBMODULE_METADATA_FILE_PREFIX; use mononoke_app::args::RepoArgs; use mononoke_app::MononokeApp; use repo_cross_repo::RepoCrossRepo; @@ -36,6 +37,8 @@ pub enum ConfigSubcommand { ByVersion(ByVersionArgs), /// List all available CommitSyncConfig versions for the repo List(ListArgs), + /// Show common config + Common, } #[derive(Args)] @@ -68,6 +71,7 @@ pub async fn run(app: MononokeApp, args: CommandArgs) -> Result<()> { match args.subcommand { ConfigSubcommand::ByVersion(args) => by_version(&ctx, &repo, args).await, ConfigSubcommand::List(args) => list(&ctx, &repo, args).await, + ConfigSubcommand::Common => common(&ctx, &repo).await, } } @@ -109,11 +113,46 @@ async fn list(_ctx: &CoreContext, repo: &Repo, args: ListArgs) -> Result<()> { Ok(()) } +async fn common(_ctx: &CoreContext, repo: &Repo) -> Result<()> { + let common_config = repo + .repo_cross_repo() + .live_commit_sync_config() + .get_common_config(repo.repo_identity().id())?; + println!("large repo: {}", common_config.large_repo_id); + println!( + "common pushrebase bookmarks: {:?}", + common_config + .common_pushrebase_bookmarks + .iter() + .map(ToString::to_string) + .collect::>() + ); + for (small_repo_id, small_repo_config) in common_config + .small_repos + .into_iter() + .sorted_by_key(|(small_repo_id, _)| *small_repo_id) + { + println!("small repo: {}", small_repo_id); + println!(" bookmark prefix: {}", small_repo_config.bookmark_prefix); + if !small_repo_config.common_pushrebase_bookmarks_map.is_empty() { + println!(" common pushrebase bookmarks map:"); + for (k, v) in small_repo_config.common_pushrebase_bookmarks_map.iter() { + println!(" {} => {}", k, v); + } + } + } + Ok(()) +} + fn print_commit_sync_config(csc: CommitSyncConfig, line_prefix: &str) { println!("{}large repo: {}", line_prefix, csc.large_repo_id); println!( "{}common pushrebase bookmarks: {:?}", - line_prefix, csc.common_pushrebase_bookmarks + line_prefix, + csc.common_pushrebase_bookmarks + .iter() + .map(ToString::to_string) + .collect::>(), ); println!("{}version name: {}", line_prefix, csc.version_name); for (small_repo_id, small_repo_config) in csc @@ -121,18 +160,44 @@ fn print_commit_sync_config(csc: CommitSyncConfig, line_prefix: &str) { .into_iter() .sorted_by_key(|(small_repo_id, _)| *small_repo_id) { - println!("{} small repo: {}", line_prefix, small_repo_id); + println!("{}small repo: {}", line_prefix, small_repo_id); println!( "{} default action: {:?}", line_prefix, small_repo_config.default_action ); - println!("{} prefix map:", line_prefix); - for (from, to) in small_repo_config - .map - .into_iter() - .sorted_by_key(|(from, _)| from.clone()) - { - println!("{} {}->{}", line_prefix, from, to); + if !small_repo_config.map.is_empty() { + println!("{} prefix map:", line_prefix); + for (from, to) in small_repo_config + .map + .into_iter() + .sorted_by_key(|(from, _)| from.clone()) + { + println!("{} {}->{}", line_prefix, from, to); + } + } + let submodule_config = &small_repo_config.submodule_config; + println!( + "{} submodule action: {:?}", + line_prefix, submodule_config.git_submodules_action, + ); + let file_prefix = &submodule_config.submodule_metadata_file_prefix; + if file_prefix != DEFAULT_GIT_SUBMODULE_METADATA_FILE_PREFIX { + println!( + "{} submodule metadata file prefix: {:?}", + line_prefix, file_prefix + ); + } + if !submodule_config.submodule_dependencies.is_empty() { + println!("{} submodule dependencies:", line_prefix); + for (path, repo_id) in submodule_config.submodule_dependencies.iter() { + println!("{} {} => {}", line_prefix, path, repo_id); + } + } + if !submodule_config.dangling_submodule_pointers.is_empty() { + println!("{} dangling submodule pointers:", line_prefix); + for pointer in submodule_config.dangling_submodule_pointers.iter() { + println!("{} {}", line_prefix, pointer); + } } } }