diff --git a/CHANGELOG.md b/CHANGELOG.md index e8f4d8b2..934cf18f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * syntax errors in `key_bindings.ron` will be logged ([#1491](https://github.com/extrawurst/gitui/issues/1491)) * commit hooks report "command not found" on Windows with wsl2 installed ([#1528](https://github.com/extrawurst/gitui/issues/1528)) * crashes on entering submodules ([#1510](https://github.com/extrawurst/gitui/issues/1510)) +* fix race issue: revlog messages sometimes appear empty ([#1473](https://github.com/extrawurst/gitui/issues/1473)) ### Changed * minimum supported rust version bumped to 1.64 (thank you `clap`) diff --git a/src/components/commitlist.rs b/src/components/commitlist.rs index 603c5332..91e48dd6 100644 --- a/src/components/commitlist.rs +++ b/src/components/commitlist.rs @@ -43,7 +43,7 @@ pub struct CommitList { scroll_state: (Instant, f32), tags: Option, branches: BTreeMap>, - current_size: Cell<(u16, u16)>, + current_size: Cell>, scroll_top: Cell, theme: SharedTheme, queue: Queue, @@ -68,7 +68,7 @@ impl CommitList { scroll_state: (Instant::now(), 0_f32), tags: None, branches: BTreeMap::default(), - current_size: Cell::new((0, 0)), + current_size: Cell::new(None), scroll_top: Cell::new(0), theme, queue, @@ -87,8 +87,8 @@ impl CommitList { self.selection } - /// - pub fn current_size(&self) -> (u16, u16) { + /// will return view size or None before the first render + pub fn current_size(&self) -> Option<(u16, u16)> { self.current_size.get() } @@ -208,8 +208,10 @@ impl CommitList { #[allow(clippy::cast_possible_truncation)] let speed_int = usize::try_from(self.scroll_state.1 as i64)?.max(1); - let page_offset = - usize::from(self.current_size.get().1).saturating_sub(1); + let page_offset = usize::from( + self.current_size.get().unwrap_or_default().1, + ) + .saturating_sub(1); let new_selection = match scroll { ScrollType::Up => { @@ -475,9 +477,9 @@ impl DrawableComponent for CommitList { area.width.saturating_sub(2), area.height.saturating_sub(2), ); - self.current_size.set(current_size); + self.current_size.set(Some(current_size)); - let height_in_lines = self.current_size.get().1 as usize; + let height_in_lines = current_size.1 as usize; let selection = self.relative_selection(); self.scroll_top.set(calc_scroll_top( diff --git a/src/tabs/revlog.rs b/src/tabs/revlog.rs index b1faf69c..63a02cc3 100644 --- a/src/tabs/revlog.rs +++ b/src/tabs/revlog.rs @@ -160,7 +160,10 @@ impl Revlog { let commits = sync::get_commits_info( &self.repo.borrow(), &self.git_log.get_slice(want_min, SLICE_SIZE)?, - self.list.current_size().0.into(), + self.list + .current_size() + .map_or(100u16, |size| size.0) + .into(), ); if let Ok(commits) = commits {