Skip to content

Commit 51b1440

Browse files
author
Stephan Dilly
committed
log tab refreshes when head changes (closes #78)
1 parent 2f54a60 commit 51b1440

File tree

4 files changed

+54
-17
lines changed

4 files changed

+54
-17
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
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

Lines changed: 43 additions & 16 deletions
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,23 +58,46 @@ 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<()> {
5983
if !self.is_pending() {
60-
self.clear()?;
61-
62-
let arc_current = Arc::clone(&self.current);
63-
let sender = self.sender.clone();
64-
let arc_pending = Arc::clone(&self.pending);
65-
66-
rayon_core::spawn(move || {
67-
scope_time!("async::revlog");
68-
arc_pending.store(true, Ordering::Relaxed);
69-
AsyncLog::fetch_helper(arc_current, &sender)
70-
.expect("failed to fetch");
71-
arc_pending.store(false, Ordering::Relaxed);
72-
Self::notify(&sender);
73-
});
84+
if self.head_changed()? {
85+
self.clear()?;
86+
87+
let arc_current = Arc::clone(&self.current);
88+
let sender = self.sender.clone();
89+
let arc_pending = Arc::clone(&self.pending);
90+
91+
rayon_core::spawn(move || {
92+
scope_time!("async::revlog");
93+
94+
arc_pending.store(true, Ordering::Relaxed);
95+
AsyncLog::fetch_helper(arc_current, &sender)
96+
.expect("failed to fetch");
97+
arc_pending.store(false, Ordering::Relaxed);
98+
Self::notify(&sender);
99+
});
100+
}
74101
}
75102
Ok(())
76103
}

src/app.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,11 @@ impl App {
137137
}
138138

139139
//TODO: do we need this?
140-
///
140+
/// forward ticking to components that require it
141141
pub fn update(&mut self) {
142142
trace!("update");
143143
self.status_tab.update();
144+
self.revlog.update();
144145
}
145146

146147
///

src/tabs/revlog/mod.rs

Lines changed: 6 additions & 0 deletions
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)