From 2fa4c7932c50ecd0762da200e0187a4275ae264e Mon Sep 17 00:00:00 2001 From: extrawurst Date: Wed, 1 Mar 2023 13:48:38 +0100 Subject: [PATCH] fix race issue in revlog message fetching sometimes messages appear empty because getting the revlog is so fast (empty repo) that no draw happened yet and so we do not know yet what size the view will have. fixes #1473 --- CHANGELOG.md | 1 + src/components/commitlist.rs | 18 ++++++++++-------- src/tabs/revlog.rs | 5 ++++- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e8f4d8b2fc..934cf18f7a 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 603c53325e..91e48dd69f 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 b1faf69c77..63a02cc3e6 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 {