cli: unify "bench revset"/"revsets" commands

This commit is contained in:
Yuya Nishihara 2023-04-01 11:14:41 +09:00
parent 6c6fdae88d
commit 5a771c913b

View file

@ -37,8 +37,6 @@ pub enum BenchCommands {
ResolvePrefix(BenchResolvePrefixArgs), ResolvePrefix(BenchResolvePrefixArgs),
#[command(name = "revset")] #[command(name = "revset")]
Revset(BenchRevsetArgs), Revset(BenchRevsetArgs),
#[command(name = "revsets")]
Revsets(BenchRevsetsArgs),
} }
/// Find the common ancestor(s) of a set of commits /// Find the common ancestor(s) of a set of commits
@ -61,18 +59,13 @@ pub struct BenchIsAncestorArgs {
/// Walk the revisions in the revset /// Walk the revisions in the revset
#[derive(clap::Args, Clone, Debug)] #[derive(clap::Args, Clone, Debug)]
#[command(group(clap::ArgGroup::new("revset_source").required(true)))]
pub struct BenchRevsetArgs { pub struct BenchRevsetArgs {
#[arg(required = true)] #[arg(group = "revset_source")]
revisions: Vec<String>, revisions: Vec<String>,
#[command(flatten)] /// Read revsets from file
criterion: CriterionArgs, #[arg(long, short = 'f', group = "revset_source", value_hint = clap::ValueHint::FilePath)]
} file: Option<String>,
/// Benchmark multiple revsets specified in a file
#[derive(clap::Args, Clone, Debug)]
pub struct BenchRevsetsArgs {
#[arg(value_hint = clap::ValueHint::FilePath)]
file: String,
#[command(flatten)] #[command(flatten)]
criterion: CriterionArgs, criterion: CriterionArgs,
} }
@ -185,26 +178,18 @@ pub(crate) fn cmd_bench(
} }
BenchCommands::Revset(command_matches) => { BenchCommands::Revset(command_matches) => {
let workspace_command = command.workspace_helper(ui)?; let workspace_command = command.workspace_helper(ui)?;
let revsets = if let Some(file_path) = &command_matches.file {
std::fs::read_to_string(command.cwd().join(file_path))?
.lines()
.map(|line| line.trim().to_owned())
.filter(|line| !line.is_empty() && !line.starts_with('#'))
.collect()
} else {
command_matches.revisions.clone()
};
let mut criterion = new_criterion(ui, &command_matches.criterion); let mut criterion = new_criterion(ui, &command_matches.criterion);
let mut group = criterion.benchmark_group("revsets"); let mut group = criterion.benchmark_group("revsets");
for revset in &command_matches.revisions { for revset in &revsets {
bench_revset(ui, command, &workspace_command, &mut group, revset)?;
}
// Neither of these seem to report anything...
group.finish();
criterion.final_summary();
}
BenchCommands::Revsets(command_matches) => {
let workspace_command = command.workspace_helper(ui)?;
let file_path = command.cwd().join(&command_matches.file);
let revsets = std::fs::read_to_string(&file_path)?;
let mut criterion = new_criterion(ui, &command_matches.criterion);
let mut group = criterion.benchmark_group("revsets");
for revset in revsets.lines() {
let revset = revset.trim();
if revset.starts_with('#') || revset.is_empty() {
continue;
}
bench_revset(ui, command, &workspace_command, &mut group, revset)?; bench_revset(ui, command, &workspace_command, &mut group, revset)?;
} }
// Neither of these seem to report anything... // Neither of these seem to report anything...