Skip to content

Commit

Permalink
log tab refreshes when head changes (closes #78)
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephan Dilly committed May 20, 2020
1 parent 2f54a60 commit 51b1440
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 17 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed
- log tab refreshes when head changes ([#78](https://github.com/extrawurst/gitui/issues/78))

## [0.3.0] - 2020-05-20

### Added
Expand Down
59 changes: 43 additions & 16 deletions asyncgit/src/revlog.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
use crate::{error::Result, sync, AsyncNotification, CWD};
use crate::{
error::Result,
sync::{utils::repo, LogWalker},
AsyncNotification, CWD,
};
use crossbeam_channel::Sender;
use git2::Oid;
use log::debug;
use scopetime::scope_time;
use std::{
iter::FromIterator,
Expand All @@ -9,7 +14,6 @@ use std::{
Arc, Mutex,
},
};
use sync::{utils::repo, LogWalker};

///
pub struct AsyncLog {
Expand Down Expand Up @@ -54,23 +58,46 @@ impl AsyncLog {
self.pending.load(Ordering::Relaxed)
}

///
fn current_head(&self) -> Result<Oid> {
Ok(self.current.lock()?.first().map_or(Oid::zero(), |f| *f))
}

///
fn head_changed(&self) -> Result<bool> {
if let Ok(head) = repo(CWD)?.head() {
if let Some(head) = head.target() {
debug!(
"repo head vs current log head: {} vs. {}",
head,
self.current_head()?
);
return Ok(head != self.current_head()?);
}
}
Ok(false)
}

///
pub fn fetch(&mut self) -> Result<()> {
if !self.is_pending() {
self.clear()?;

let arc_current = Arc::clone(&self.current);
let sender = self.sender.clone();
let arc_pending = Arc::clone(&self.pending);

rayon_core::spawn(move || {
scope_time!("async::revlog");
arc_pending.store(true, Ordering::Relaxed);
AsyncLog::fetch_helper(arc_current, &sender)
.expect("failed to fetch");
arc_pending.store(false, Ordering::Relaxed);
Self::notify(&sender);
});
if self.head_changed()? {
self.clear()?;

let arc_current = Arc::clone(&self.current);
let sender = self.sender.clone();
let arc_pending = Arc::clone(&self.pending);

rayon_core::spawn(move || {
scope_time!("async::revlog");

arc_pending.store(true, Ordering::Relaxed);
AsyncLog::fetch_helper(arc_current, &sender)
.expect("failed to fetch");
arc_pending.store(false, Ordering::Relaxed);
Self::notify(&sender);
});
}
}
Ok(())
}
Expand Down
3 changes: 2 additions & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,11 @@ impl App {
}

//TODO: do we need this?
///
/// forward ticking to components that require it
pub fn update(&mut self) {
trace!("update");
self.status_tab.update();
self.revlog.update();
}

///
Expand Down
6 changes: 6 additions & 0 deletions src/tabs/revlog/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,15 @@ impl Revlog {

///
pub fn update(&mut self) {
if self.visible {
self.git_log.fetch().unwrap();
}

let old_total = self.count_total;
self.count_total = self.git_log.count().unwrap();

if self.items.needs_data(self.selection, self.selection_max())
|| old_total != self.count_total
{
self.fetch_commits();
}
Expand Down

0 comments on commit 51b1440

Please sign in to comment.