Skip to content

Fix file history for sizes <= 1200 entries #1648

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 28 additions & 4 deletions src/components/file_revlog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,16 +226,40 @@ impl FileRevlogComponent {
if let Some(git_log) = &mut self.git_log {
let table_state = self.table_state.take();

let start = table_state.selected().unwrap_or(0);

let commits = get_commits_info(
&self.repo_path.borrow(),
&git_log.get_slice(start, SLICE_SIZE)?,
&git_log.get_slice(0, SLICE_SIZE)?,
self.current_width.get(),
);

if let Ok(commits) = commits {
self.items.set_items(start, commits);
// 2023-04-12
//
// There is an issue with how windowing works in `self.items` and
// `self.table_state`. Because of that issue, we currently have to pass
// `0` as the first argument to `set_items`. If we did not do that, the
// offset that is kept separately in `self.items` and `self.table_state`
// would get out of sync, resulting in the table showing the wrong rows.
//
// The offset determines the number of rows `render_stateful_widget`
// skips when rendering a table. When `set_items` is called, it clears
// its internal `Vec` of items and sets `index_offset` based on the
// parameter passed. Unfortunately, there is no way for us to pass this
// information, `index_offset`, to `render_stateful_widget`. Because of
// that, `render_stateful_widget` assumes that the rows provided by
// `Table` are 0-indexed while in reality they are
// `index_offset`-indexed.
//
// This fix makes the `FileRevlog` unable to show histories that have
// more than `SLICE_SIZE` items, but since it is broken for larger
// histories anyway, this seems acceptable for the time being.
//
// This issue can only properly be fixed upstream, in `tui-rs`. See
// [tui-issue].
//
// [gitui-issue]: https://github.com/extrawurst/gitui/issues/1560
// [tui-issue]: https://github.com/fdehau/tui-rs/issues/626
self.items.set_items(0, commits);
}

self.table_state.set(table_state);
Expand Down