forked from mirrors/jj
cli: report snapshot progress after first 250ms
This commit is contained in:
parent
ccbb34fddb
commit
eeeb7ed234
2 changed files with 44 additions and 2 deletions
|
@ -1000,7 +1000,9 @@ impl WorkspaceCommandHelper {
|
|||
)));
|
||||
}
|
||||
};
|
||||
let new_tree_id = locked_wc.snapshot(base_ignores, None)?;
|
||||
let progress = crate::progress::snapshot_progress(ui);
|
||||
let new_tree_id = locked_wc.snapshot(base_ignores, progress.as_ref().map(|x| x as _))?;
|
||||
drop(progress);
|
||||
if new_tree_id != *wc_commit.tree_id() {
|
||||
let mut tx = start_repo_transaction(
|
||||
&self.repo,
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
use std::io;
|
||||
use std::path::Path;
|
||||
use std::sync::Mutex;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use crossterm::terminal::{Clear, ClearType};
|
||||
use jujutsu_lib::git;
|
||||
use jujutsu_lib::repo_path::RepoPath;
|
||||
|
||||
use crate::cleanup_guard::CleanupGuard;
|
||||
use crate::ui::Ui;
|
||||
use crate::ui::{OutputGuard, Ui};
|
||||
|
||||
pub struct Progress {
|
||||
next_print: Instant,
|
||||
|
@ -166,6 +169,43 @@ impl RateEstimateState {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn snapshot_progress(ui: &mut Ui) -> Option<impl Fn(&RepoPath) + '_> {
|
||||
struct State<'a> {
|
||||
guard: Option<OutputGuard>,
|
||||
ui: &'a mut Ui,
|
||||
}
|
||||
|
||||
if !ui.use_progress_indicator() {
|
||||
return None;
|
||||
}
|
||||
|
||||
let start = Instant::now();
|
||||
let state = Mutex::new(State { guard: None, ui });
|
||||
|
||||
Some(move |path: &RepoPath| {
|
||||
if start.elapsed() < Duration::from_millis(250) {
|
||||
// Don't clutter the output during fast operations. Future work: Display current
|
||||
// path after exactly 250ms has elapsed, to better handle large single files
|
||||
return;
|
||||
}
|
||||
let mut state = state.lock().unwrap();
|
||||
if state.guard.is_none() {
|
||||
state.guard = Some(
|
||||
state
|
||||
.ui
|
||||
.output_guard(format!("\r{}", Clear(ClearType::CurrentLine))),
|
||||
);
|
||||
}
|
||||
_ = write!(
|
||||
state.ui,
|
||||
"\r{}Snapshotting {}",
|
||||
Clear(ClearType::CurrentLine),
|
||||
path.to_fs_path(Path::new("")).display()
|
||||
);
|
||||
_ = state.ui.flush();
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
|
Loading…
Reference in a new issue