From e1071942ef453afd3f5081d4b8fa52e3fe7cd010 Mon Sep 17 00:00:00 2001 From: tjh Date: Mon, 13 Oct 2025 18:48:37 +0100 Subject: [PATCH] feat: add flag to limit search time Signed-off-by: tjh --- Cargo.toml | 3 +++ src/cli.rs | 5 +++++ src/main.rs | 14 ++++++++++++++ 3 files changed, 22 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index b55a52d..79ff707 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,6 +14,9 @@ clap = { version = "4.5.39", features = ["derive"] } gix = { version = "0.73.0", default-features = false, features = ["max-performance"] } time = { version = "0.3.41", features = ["formatting"] } +[features] +time-budget = [] + [profile.release] strip = true lto = "fat" diff --git a/src/cli.rs b/src/cli.rs index 66f099c..cd9dcd0 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -24,5 +24,10 @@ pub struct Arguments { #[arg(long, short = 'R', value_hint = ValueHint::DirPath, default_value = ".")] pub repository: PathBuf, + /// Maximum search time in milliseconds. + #[cfg(feature = "time-budget")] + #[arg(long, default_value_t = u64::MAX)] + pub time_limit: u64, + pub subtree: Option, } diff --git a/src/main.rs b/src/main.rs index 9c1fc86..def8873 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,10 +11,19 @@ use gix::revision::walk::Sorting; use gix::traverse::commit::simple::CommitTimeOrder; use std::collections::HashSet; +#[cfg(feature = "time-budget")] +use std::time::Duration; +#[cfg(feature = "time-budget")] +use std::time::Instant; + mod cli; fn main() -> anyhow::Result<()> { let arguments = cli::parse(); + + #[cfg(feature = "time-budget")] + let (time_limit, start) = (Duration::from_millis(arguments.time_limit), Instant::now()); + let repository = gix::open(arguments.repository)?; let mut current_commit = repository.resolve_revspec(&arguments.from)?; @@ -71,6 +80,11 @@ fn main() -> anyhow::Result<()> { break; } + #[cfg(feature = "time-budget")] + if start.elapsed() > time_limit { + break; + } + let revision = revision?; let Some(&parent_id) = revision.parent_ids.first() else { // The revision has no parents. Assume any remaining entries belong -- 2.51.2