Skip to content

Commit

Permalink
fix race issue in revlog message fetching
Browse files Browse the repository at this point in the history
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
  • Loading branch information
extrawurst committed Mar 1, 2023
1 parent e1a40dd commit 2fa4c79
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand Down
18 changes: 10 additions & 8 deletions src/components/commitlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub struct CommitList {
scroll_state: (Instant, f32),
tags: Option<Tags>,
branches: BTreeMap<CommitId, Vec<String>>,
current_size: Cell<(u16, u16)>,
current_size: Cell<Option<(u16, u16)>>,
scroll_top: Cell<usize>,
theme: SharedTheme,
queue: Queue,
Expand All @@ -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,
Expand All @@ -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()
}

Expand Down Expand Up @@ -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 => {
Expand Down Expand 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(
Expand Down
5 changes: 4 additions & 1 deletion src/tabs/revlog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 2fa4c79

Please sign in to comment.