aboutsummaryrefslogtreecommitdiffstats
path: root/src/vcs/git.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/vcs/git.rs')
-rw-r--r--src/vcs/git.rs47
1 files changed, 13 insertions, 34 deletions
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