mirror of
https://github.com/facebook/sapling.git
synced 2024-10-05 14:28:17 +03:00
Migrate check_git_wc command to new Mononoke App
Summary: As in title Reviewed By: mitrandir77 Differential Revision: D46354685 fbshipit-source-id: 2a3e7e86772c71aed18cc6c83c31767c7454d65c
This commit is contained in:
parent
174b56b841
commit
0443bba2cf
@ -9,25 +9,20 @@ use std::str::FromStr;
|
||||
|
||||
use anyhow::Result;
|
||||
use check_git_wc::check_git_wc;
|
||||
use clap_old::Arg;
|
||||
use cmdlib::args;
|
||||
use cmdlib::args::MononokeClapApp;
|
||||
use cmdlib::args::MononokeMatches;
|
||||
use cmdlib::helpers::block_execute;
|
||||
use clap::Parser;
|
||||
use context::CoreContext;
|
||||
use fbinit::FacebookInit;
|
||||
use git2::Repository;
|
||||
use git2::RepositoryOpenFlags;
|
||||
use mononoke_app::args::RepoArgs;
|
||||
use mononoke_app::fb303::AliveService;
|
||||
use mononoke_app::fb303::Fb303AppExtension;
|
||||
use mononoke_app::MononokeApp;
|
||||
use mononoke_app::MononokeAppBuilder;
|
||||
use mononoke_types::ChangesetId;
|
||||
use repo_blobstore::RepoBlobstore;
|
||||
use repo_derived_data::RepoDerivedData;
|
||||
|
||||
const ARG_CS_ID: &str = "csid";
|
||||
const ARG_GIT_REPO_PATH: &str = "git-repo-path";
|
||||
const ARG_GIT_COMMIT: &str = "git-commit";
|
||||
const ARG_GIT_LFS: &str = "git-lfs";
|
||||
const ARG_SCHEDULED_MAX: &str = "scheduled-max";
|
||||
|
||||
#[facet::container]
|
||||
struct HgRepo {
|
||||
#[facet]
|
||||
@ -37,94 +32,61 @@ struct HgRepo {
|
||||
repo_derived_data: RepoDerivedData,
|
||||
}
|
||||
|
||||
fn setup_app<'a, 'b>() -> MononokeClapApp<'a, 'b> {
|
||||
args::MononokeAppBuilder::new("Check that a working copy will match a git checkout")
|
||||
.build()
|
||||
.about("Check that a working copy for a given Bonsai is a perfect match to a git commit")
|
||||
.arg(
|
||||
Arg::with_name(ARG_CS_ID)
|
||||
.long(ARG_CS_ID)
|
||||
.value_name("BONSAI")
|
||||
.required(true)
|
||||
.help("Bonsai changeset whose working copy should be verified"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name(ARG_GIT_REPO_PATH)
|
||||
.long(ARG_GIT_REPO_PATH)
|
||||
.value_name("PATH")
|
||||
.required(true)
|
||||
.help("Path to the git repo to compare to"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name(ARG_GIT_COMMIT)
|
||||
.long(ARG_GIT_COMMIT)
|
||||
.value_name("HASH")
|
||||
.required(true)
|
||||
.help("The git commit to compare to"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name(ARG_GIT_LFS)
|
||||
.long(ARG_GIT_LFS)
|
||||
.help("Enable git-lfs pointer parsing"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name(ARG_SCHEDULED_MAX)
|
||||
.long(ARG_SCHEDULED_MAX)
|
||||
.takes_value(true)
|
||||
.required(false)
|
||||
.help("Maximum number of directories to check in parallel. Default 1"),
|
||||
)
|
||||
/// Validate the working copy in Git
|
||||
#[derive(Parser)]
|
||||
#[clap(about = "Tool for checking that a working copy will match a git checkout.")]
|
||||
struct CheckGitWCArgs {
|
||||
/// The repo against which the command needs to be executed
|
||||
#[clap(flatten)]
|
||||
repo: RepoArgs,
|
||||
/// Bonsai changeset whose working copy should be verified
|
||||
#[clap(long, value_name = "BONSAI")]
|
||||
csid: String,
|
||||
/// Path to the git repo to compare to
|
||||
#[clap(long, value_name = "PATH")]
|
||||
git_repo_path: String,
|
||||
/// The git commit to compare to
|
||||
#[clap(long, value_name = "HASH")]
|
||||
git_commit: String,
|
||||
/// Enable git-lfs pointer parsing
|
||||
#[clap(long)]
|
||||
git_lfs: bool,
|
||||
/// Maximum number of directories to check in parallel. Default 100
|
||||
#[clap(long, default_value_t = 100)]
|
||||
scheduled_max: usize,
|
||||
}
|
||||
|
||||
async fn run_check_git_wc(
|
||||
fb: FacebookInit,
|
||||
ctx: &CoreContext,
|
||||
matches: &MononokeMatches<'_>,
|
||||
) -> Result<()> {
|
||||
let cs = ChangesetId::from_str(matches.value_of(ARG_CS_ID).expect("Need Bonsai CS"))?;
|
||||
async fn run_check_git_wc(app: MononokeApp) -> Result<()> {
|
||||
let logger = app.logger();
|
||||
let ctx = CoreContext::new_with_logger(app.fb, logger.clone());
|
||||
|
||||
let args: CheckGitWCArgs = app.args()?;
|
||||
let cs = ChangesetId::from_str(&args.csid)?;
|
||||
|
||||
let git_commit = matches
|
||||
.value_of(ARG_GIT_COMMIT)
|
||||
.expect("Need git commit")
|
||||
.to_string();
|
||||
let git_lfs = matches.is_present(ARG_GIT_LFS);
|
||||
let git_repo = Repository::open_ext(
|
||||
matches
|
||||
.value_of(ARG_GIT_REPO_PATH)
|
||||
.expect("Need git repo path"),
|
||||
args.git_repo_path,
|
||||
RepositoryOpenFlags::NO_SEARCH | RepositoryOpenFlags::BARE | RepositoryOpenFlags::NO_DOTGIT,
|
||||
std::iter::empty::<std::ffi::OsString>(),
|
||||
)?;
|
||||
|
||||
let hg_repo: HgRepo =
|
||||
args::not_shardmanager_compatible::open_repo(fb, ctx.logger(), matches).await?;
|
||||
let scheduled_max = args::get_usize_opt(matches, ARG_SCHEDULED_MAX).unwrap_or(100);
|
||||
let hg_repo: HgRepo = app.open_repo(&args.repo).await?;
|
||||
|
||||
check_git_wc(
|
||||
ctx,
|
||||
&ctx,
|
||||
&hg_repo,
|
||||
cs,
|
||||
git_repo,
|
||||
git_commit,
|
||||
git_lfs,
|
||||
scheduled_max,
|
||||
args.git_commit,
|
||||
args.git_lfs,
|
||||
args.scheduled_max,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
#[fbinit::main]
|
||||
fn main(fb: FacebookInit) -> Result<()> {
|
||||
let (matches, _runtime) = setup_app().get_matches(fb)?;
|
||||
|
||||
let logger = matches.logger();
|
||||
let ctx = CoreContext::new_with_logger(fb, logger.clone());
|
||||
|
||||
block_execute(
|
||||
run_check_git_wc(fb, &ctx, &matches),
|
||||
fb,
|
||||
"check_git_wc",
|
||||
logger,
|
||||
&matches,
|
||||
cmdlib::monitoring::AliveService,
|
||||
)
|
||||
let app = MononokeAppBuilder::new(fb)
|
||||
.with_app_extension(Fb303AppExtension {})
|
||||
.build::<CheckGitWCArgs>()?;
|
||||
app.run_with_monitoring_and_logging(run_check_git_wc, "check_git_wc", AliveService)
|
||||
}
|
||||
|
@ -46,9 +46,7 @@
|
||||
|
||||
# Validate with and without LFS, see that it's the same both ways round.
|
||||
$ check_git_wc --csid 9008b77c0e045e165185b0b969833b825a24d386207ad05dc614238116a11aca --git-repo-path "${GIT_REPO}/.git" --git-commit c141531763860520767a348d160d1c1c02339218 --git-lfs --scheduled-max 2
|
||||
*] using repo "repo" repoid RepositoryId(0) (glob)
|
||||
$ check_git_wc --csid 9008b77c0e045e165185b0b969833b825a24d386207ad05dc614238116a11aca --git-repo-path "${GIT_REPO}/.git" --git-commit c141531763860520767a348d160d1c1c02339218 --scheduled-max 2
|
||||
*] using repo "repo" repoid RepositoryId(0) (glob)
|
||||
|
||||
# Add an LFS pointer
|
||||
$ cd "$GIT_REPO"
|
||||
@ -72,21 +70,17 @@
|
||||
|
||||
# This time, LFS works, non-LFS fails because the git sha256 is of the pointer, not the content
|
||||
$ check_git_wc --csid ebb720a32798f440a3a998dd2863615011c558fd5bb9d77832cfb77b6e8321d2 --git-repo-path "${GIT_REPO}/.git" --git-commit 71ba3fb41d4d75215d50edc4c2061ff3f21225b8 --git-lfs --scheduled-max 2
|
||||
*] using repo "repo" repoid RepositoryId(0) (glob)
|
||||
$ check_git_wc --csid ebb720a32798f440a3a998dd2863615011c558fd5bb9d77832cfb77b6e8321d2 --git-repo-path "${GIT_REPO}/.git" --git-commit 71ba3fb41d4d75215d50edc4c2061ff3f21225b8 --scheduled-max 2
|
||||
*] using repo "repo" repoid RepositoryId(0) (glob)
|
||||
*] Execution error: file 'lfs-file' has hash 94cb9a4fb124ed218aeeaefa7927680d5a261652f400f9d4f6a4e729c995d088 in git and 5891b5b522d5df086d0ff0b110fbd9d21bb4fc7163af34d08286a2e846f6be03 in Mononoke (glob)
|
||||
Error: Execution failed
|
||||
[1]
|
||||
|
||||
# With two commits present, validate the older git commit against newer Mononoke and vice-versa
|
||||
$ check_git_wc --csid 9008b77c0e045e165185b0b969833b825a24d386207ad05dc614238116a11aca --git-repo-path "${GIT_REPO}/.git" --git-commit 71ba3fb41d4d75215d50edc4c2061ff3f21225b8 --git-lfs --scheduled-max 2
|
||||
*] using repo "repo" repoid RepositoryId(0) (glob)
|
||||
*] Execution error: file 'lfs-file' in git but not Bonsai (glob)
|
||||
Error: Execution failed
|
||||
[1]
|
||||
$ check_git_wc --csid ebb720a32798f440a3a998dd2863615011c558fd5bb9d77832cfb77b6e8321d2 --git-repo-path "${GIT_REPO}/.git" --git-commit c141531763860520767a348d160d1c1c02339218 --git-lfs --scheduled-max 2
|
||||
*] using repo "repo" repoid RepositoryId(0) (glob)
|
||||
*] Execution error: File (root path)/lfs-file in Bonsai but not git (glob)
|
||||
Error: Execution failed
|
||||
[1]
|
||||
|
Loading…
Reference in New Issue
Block a user