From bea8eb55cb26db5dc50958665668759716ff6830 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Tue, 27 Feb 2018 02:24:07 -0500 Subject: clean up the verbose output process --- src/vcs/git.rs | 47 +++++++++++++---------------------------------- 1 file changed, 13 insertions(+), 34 deletions(-) (limited to 'src/vcs') diff --git a/src/vcs/git.rs b/src/vcs/git.rs index 29d50da..32369a3 100644 --- a/src/vcs/git.rs +++ b/src/vcs/git.rs @@ -16,8 +16,7 @@ pub struct GitInfo { impl GitInfo { pub fn new(git: &git2::Repository) -> GitInfo { - #[cfg(feature = "verbose")] - let now = std::time::Instant::now(); + start_talking_about_time!("git"); let mut modified_statuses = git2::Status::empty(); modified_statuses.insert(git2::STATUS_WT_DELETED); @@ -33,9 +32,7 @@ impl GitInfo { staged_statuses.insert(git2::STATUS_INDEX_TYPECHANGE); let mut new_statuses = git2::Status::empty(); new_statuses.insert(git2::STATUS_WT_NEW); - - #[cfg(feature = "verbose")] - let now = talk_about_time(now, "status bitsets"); + talk_about_time!("status bitsets"); let mut status_options = git2::StatusOptions::new(); status_options.include_untracked(true); @@ -47,11 +44,11 @@ impl GitInfo { status_options.update_index(false); status_options.no_refresh(true); } - #[cfg(feature = "verbose")] - let now = talk_about_time(now, "status options"); + talk_about_time!("status options"); + let status = git.statuses(Some(&mut status_options)); - #[cfg(feature = "verbose")] - let now = talk_about_time(now, "statuses"); + talk_about_time!("statuses"); + let mut modified_files = false; let mut staged_files = false; let mut new_files = false; @@ -68,12 +65,11 @@ impl GitInfo { } } } - #[cfg(feature = "verbose")] - let now = talk_about_time(now, "status iteration"); + talk_about_time!("status iteration"); let head = git.head(); - #[cfg(feature = "verbose")] - let now = talk_about_time(now, "head"); + talk_about_time!("head"); + let commits = head.is_ok(); let branch = head.ok().and_then(|head| { if head.is_branch() { @@ -92,8 +88,7 @@ impl GitInfo { ) } }); - #[cfg(feature = "verbose")] - let now = talk_about_time(now, "branch"); + talk_about_time!("branch"); let active_operation = match git.state() { git2::RepositoryState::Merge => super::ActiveOperation::Merge, @@ -113,8 +108,7 @@ impl GitInfo { } _ => super::ActiveOperation::None, }; - #[cfg(feature = "verbose")] - let now = talk_about_time(now, "active operation"); + talk_about_time!("active operation"); let remote_branch_diff = git.head() .ok() @@ -143,8 +137,8 @@ impl GitInfo { }) }) }); - #[cfg(feature = "verbose")] - let _ = talk_about_time(now, "remote branch diff"); + talk_about_time!("remote branch diff"); + stop_talking_about_time!(); GitInfo { modified_files, @@ -158,21 +152,6 @@ impl GitInfo { } } -#[cfg(feature = "verbose")] -fn talk_about_time( - now: std::time::Instant, - what: &str, -) -> std::time::Instant { - let elapsed = now.elapsed(); - println!( - "calculating {} took {}.{:09}s", - what, - elapsed.as_secs(), - elapsed.subsec_nanos() - ); - std::time::Instant::now() -} - impl super::VcsInfo for GitInfo { fn vcs(&self) -> super::VcsType { super::VcsType::Git -- cgit v1.2.3-54-g00ecf