Skip to content

Commit 927c755

Browse files
author
Stephan Dilly
committed
Merge branch 'master' into #3-stashing
# Conflicts: # src/app.rs
2 parents a678208 + 5936757 commit 927c755

File tree

6 files changed

+67
-27
lines changed

6 files changed

+67
-27
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
### Changed
10+
- log tab refreshes when head changes ([#78](https://github.com/extrawurst/gitui/issues/78))
11+
912
## [0.3.0] - 2020-05-20
1013

1114
### Added

asyncgit/src/revlog.rs

+28-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
use crate::{error::Result, sync, AsyncNotification, CWD};
1+
use crate::{
2+
error::Result,
3+
sync::{utils::repo, LogWalker},
4+
AsyncNotification, CWD,
5+
};
26
use crossbeam_channel::Sender;
37
use git2::Oid;
8+
use log::debug;
49
use scopetime::scope_time;
510
use std::{
611
iter::FromIterator,
@@ -9,7 +14,6 @@ use std::{
914
Arc, Mutex,
1015
},
1116
};
12-
use sync::{utils::repo, LogWalker};
1317

1418
///
1519
pub struct AsyncLog {
@@ -54,9 +58,29 @@ impl AsyncLog {
5458
self.pending.load(Ordering::Relaxed)
5559
}
5660

61+
///
62+
fn current_head(&self) -> Result<Oid> {
63+
Ok(self.current.lock()?.first().map_or(Oid::zero(), |f| *f))
64+
}
65+
66+
///
67+
fn head_changed(&self) -> Result<bool> {
68+
if let Ok(head) = repo(CWD)?.head() {
69+
if let Some(head) = head.target() {
70+
debug!(
71+
"repo head vs current log head: {} vs. {}",
72+
head,
73+
self.current_head()?
74+
);
75+
return Ok(head != self.current_head()?);
76+
}
77+
}
78+
Ok(false)
79+
}
80+
5781
///
5882
pub fn fetch(&mut self) -> Result<()> {
59-
if !self.is_pending() {
83+
if !self.is_pending() && self.head_changed()? {
6084
self.clear()?;
6185

6286
let arc_current = Arc::clone(&self.current);
@@ -65,6 +89,7 @@ impl AsyncLog {
6589

6690
rayon_core::spawn(move || {
6791
scope_time!("async::revlog");
92+
6893
arc_pending.store(true, Ordering::Relaxed);
6994
AsyncLog::fetch_helper(arc_current, &sender)
7095
.expect("failed to fetch");

src/app.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,11 @@ impl App {
141141
}
142142

143143
//TODO: do we need this?
144-
///
144+
/// forward ticking to components that require it
145145
pub fn update(&mut self) {
146146
trace!("update");
147147
self.status_tab.update();
148+
self.revlog.update();
148149
self.stashing_tab.update();
149150
}
150151

src/components/help.rs

+12-19
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,13 @@ pub struct HelpComponent {
2727
impl DrawableComponent for HelpComponent {
2828
fn draw<B: Backend>(&mut self, f: &mut Frame<B>, _rect: Rect) {
2929
if self.visible {
30-
let (txt, selected_line) = self.get_text();
31-
32-
let height = 24;
33-
let scroll_threshold = height / 3;
34-
35-
let scroll = if selected_line > scroll_threshold {
36-
self.selection - scroll_threshold
37-
} else {
38-
0
39-
};
30+
const SIZE: (u16, u16) = (65, 24);
31+
let scroll_threshold = SIZE.1 / 3;
32+
let scroll =
33+
self.selection.saturating_sub(scroll_threshold);
4034

4135
let area =
42-
ui::centered_rect_absolute(65, height, f.size());
36+
ui::centered_rect_absolute(SIZE.0, SIZE.1, f.size());
4337

4438
f.render_widget(Clear, area);
4539
f.render_widget(
@@ -60,7 +54,7 @@ impl DrawableComponent for HelpComponent {
6054
.split(area);
6155

6256
f.render_widget(
63-
Paragraph::new(txt.iter())
57+
Paragraph::new(self.get_text().iter())
6458
.scroll(scroll)
6559
.alignment(Alignment::Left),
6660
chunks[0],
@@ -182,16 +176,17 @@ impl HelpComponent {
182176
};
183177
new_selection = cmp::max(new_selection, 0);
184178

185-
if let Ok(max) = u16::try_from(self.cmds.len() - 1) {
179+
if let Ok(max) =
180+
u16::try_from(self.cmds.len().saturating_sub(1))
181+
{
186182
self.selection = cmp::min(new_selection, max);
187183
}
188184
}
189185

190-
fn get_text<'a>(&self) -> (Vec<Text<'a>>, u16) {
186+
fn get_text<'a>(&self) -> Vec<Text<'a>> {
191187
let mut txt = Vec::new();
192188

193189
let mut processed = 0_u16;
194-
let mut selected_line = 0_u16;
195190

196191
for (key, group) in
197192
&self.cmds.iter().group_by(|e| e.text.group)
@@ -206,9 +201,7 @@ impl HelpComponent {
206201
.sorted_by_key(|e| e.order)
207202
.map(|e| {
208203
let is_selected = self.selection == processed;
209-
if is_selected {
210-
selected_line = processed;
211-
}
204+
212205
processed += 1;
213206

214207
let mut out = String::from(if is_selected {
@@ -236,6 +229,6 @@ impl HelpComponent {
236229
);
237230
}
238231

239-
(txt, selected_line)
232+
txt
240233
}
241234
}

src/main.rs

+16-4
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,9 @@ fn main() -> Result<()> {
5454
return Ok(());
5555
}
5656

57-
enable_raw_mode()?;
58-
io::stdout().execute(EnterAlternateScreen)?;
57+
setup_terminal()?;
5958
defer! {
60-
io::stdout().execute(LeaveAlternateScreen).unwrap();
61-
disable_raw_mode().unwrap();
59+
shutdown_terminal().expect("shutdown failed");
6260
}
6361

6462
set_panic_handlers();
@@ -118,6 +116,18 @@ fn main() -> Result<()> {
118116
Ok(())
119117
}
120118

119+
fn setup_terminal() -> Result<()> {
120+
enable_raw_mode()?;
121+
io::stdout().execute(EnterAlternateScreen)?;
122+
Ok(())
123+
}
124+
125+
fn shutdown_terminal() -> Result<()> {
126+
io::stdout().execute(LeaveAlternateScreen)?;
127+
disable_raw_mode()?;
128+
Ok(())
129+
}
130+
121131
fn draw<B: Backend>(
122132
terminal: &mut Terminal<B>,
123133
app: &mut App,
@@ -202,6 +212,8 @@ fn set_panic_handlers() {
202212
panic::set_hook(Box::new(|e| {
203213
let backtrace = Backtrace::new();
204214
error!("panic: {:?}\ntrace:\n{:?}", e, backtrace);
215+
shutdown_terminal().expect("shutdown failed inside panic");
216+
eprintln!("panic: {:?}\ntrace:\n{:?}", e, backtrace);
205217
}));
206218

207219
// global threadpool

src/tabs/revlog/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,15 @@ impl Revlog {
7272

7373
///
7474
pub fn update(&mut self) {
75+
if self.visible {
76+
self.git_log.fetch().unwrap();
77+
}
78+
79+
let old_total = self.count_total;
7580
self.count_total = self.git_log.count().unwrap();
7681

7782
if self.items.needs_data(self.selection, self.selection_max())
83+
|| old_total != self.count_total
7884
{
7985
self.fetch_commits();
8086
}

0 commit comments

Comments
 (0)