Skip to content

Commit

Permalink
fix missing commit in single commit repo (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephan Dilly committed May 20, 2020
1 parent c17c927 commit 7c8b7bf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
22 changes: 14 additions & 8 deletions src/tabs/revlog/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ static SLICE_SIZE: usize = 1200;
///
pub struct Revlog {
selection: usize,
selection_max: usize,
count_total: usize,
items: ItemBatch,
git_log: AsyncLog,
visible: bool,
Expand All @@ -50,7 +50,7 @@ impl Revlog {
items: ItemBatch::default(),
git_log: AsyncLog::new(sender.clone()),
selection: 0,
selection_max: 0,
count_total: 0,
visible: false,
first_open_done: false,
scroll_state: (Instant::now(), 0_f32),
Expand All @@ -66,12 +66,16 @@ impl Revlog {
self.git_log.is_pending()
}

fn selection_max(&self) -> usize {
self.count_total.saturating_sub(1)
}

///
pub fn update(&mut self) {
self.selection_max =
self.git_log.count().unwrap().saturating_sub(1);
self.count_total = self.git_log.count().unwrap();

if self.items.needs_data(self.selection, self.selection_max) {
if self.items.needs_data(self.selection, self.selection_max())
{
self.fetch_commits();
}

Expand Down Expand Up @@ -119,10 +123,11 @@ impl Revlog {
self.selection.saturating_add(page_offset)
}
ScrollType::Home => 0,
ScrollType::End => self.selection_max,
ScrollType::End => self.selection_max(),
};

self.selection = cmp::min(self.selection, self.selection_max);
self.selection =
cmp::min(self.selection, self.selection_max());

self.update();
}
Expand Down Expand Up @@ -244,7 +249,8 @@ impl DrawableComponent for Revlog {

let title = format!(
"commit {}/{}",
self.selection, self.selection_max,
self.count_total.saturating_sub(self.selection),
self.count_total,
);

f.render_widget(
Expand Down
2 changes: 1 addition & 1 deletion src/tabs/revlog/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl ItemBatch {
.min(idx_max);

let needs_data_top = want_min < self.index_offset;
let needs_data_bottom = want_max > self.last_idx();
let needs_data_bottom = want_max >= self.last_idx();
needs_data_bottom || needs_data_top
}
}

0 comments on commit 7c8b7bf

Please sign in to comment.