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,
IndexComponent,
},
git_utils::{self, Diff},
keys, strings,
git_utils, keys, strings,
};
use crossterm::event::Event;
use git2::StatusShow;
@ -210,15 +209,19 @@ impl App {
DiffTarget::WorkingDir => (&self.index_wd, false),
};
let new_diff = match idx.selection() {
Some(i) => git_utils::get_diff(
Path::new(i.path.as_str()),
is_stage,
),
None => Diff::default(),
};
if let Some(i) = idx.selection() {
let path = i.path;
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> {

View File

@ -18,6 +18,7 @@ pub struct DiffComponent {
diff: Diff,
scroll: u16,
focused: bool,
current_path: String,
}
impl DiffComponent {
@ -26,7 +27,12 @@ impl DiffComponent {
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 {
self.diff = diff;
self.scroll = 0;