try reducing git-calls to optimize performance

This commit is contained in:
Stephan Dilly 2020-03-20 19:15:25 +01:00
parent 44a2fa9dc9
commit 5c771b0bbc
2 changed files with 20 additions and 11 deletions

View file

@ -3,8 +3,7 @@ use crate::{
CommandInfo, CommitComponent, Component, DiffComponent, CommandInfo, CommitComponent, Component, DiffComponent,
IndexComponent, IndexComponent,
}, },
git_utils::{self, Diff}, git_utils, keys, strings,
keys, strings,
}; };
use crossterm::event::Event; use crossterm::event::Event;
use git2::StatusShow; use git2::StatusShow;
@ -210,15 +209,19 @@ impl App {
DiffTarget::WorkingDir => (&self.index_wd, false), DiffTarget::WorkingDir => (&self.index_wd, false),
}; };
let new_diff = match idx.selection() { if let Some(i) = idx.selection() {
Some(i) => git_utils::get_diff( let path = i.path;
Path::new(i.path.as_str()),
is_stage,
),
None => Diff::default(),
};
self.diff.update(new_diff); if self.diff.path() != path {
self.diff.update(
path.clone(),
git_utils::get_diff(
Path::new(path.as_str()),
is_stage,
),
);
}
}
} }
fn commands(&self) -> Vec<CommandInfo> { fn commands(&self) -> Vec<CommandInfo> {

View file

@ -18,6 +18,7 @@ pub struct DiffComponent {
diff: Diff, diff: Diff,
scroll: u16, scroll: u16,
focused: bool, focused: bool,
current_path: String,
} }
impl DiffComponent { impl DiffComponent {
@ -26,7 +27,12 @@ impl DiffComponent {
self.diff.0.len() > 1 self.diff.0.len() > 1
} }
/// ///
pub fn update(&mut self, diff: Diff) { pub fn path(&self) -> String {
self.current_path.clone()
}
///
pub fn update(&mut self, path: String, diff: Diff) {
self.current_path = path;
if diff != self.diff { if diff != self.diff {
self.diff = diff; self.diff = diff;
self.scroll = 0; self.scroll = 0;