mirror of
https://github.com/extrawurst/gitui.git
synced 2024-12-24 17:45:00 +03:00
try reducing git-calls to optimize performance
This commit is contained in:
parent
44a2fa9dc9
commit
5c771b0bbc
23
src/app.rs
23
src/app.rs
@ -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> {
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user