Skip to content

Commit 5be397b

Browse files
authored
stash list does not update after pop/drop (gitui-org#1865)
* move to stashlist after stashing * move to status after stash popping
1 parent 16c97ed commit 5be397b

File tree

6 files changed

+63
-16
lines changed

6 files changed

+63
-16
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Fixes
1111
* fix commit log not updating after branch switch ([#1862](https://github.com/extrawurst/gitui/issues/1862))
12+
* fix stashlist not updating after pop/drop ([#1864](https://github.com/extrawurst/gitui/issues/1864))
1213

1314
## [0.24.1] - 2023-08-30
1415

src/app.rs

+22-6
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ use crate::{
2020
options::{Options, SharedOptions},
2121
popup_stack::PopupStack,
2222
queue::{
23-
Action, InternalEvent, NeedsUpdate, Queue, StackablePopupOpen,
23+
Action, AppTabs, InternalEvent, NeedsUpdate, Queue,
24+
StackablePopupOpen,
2425
},
2526
setup_popups,
2627
strings::{self, ellipsis_trim_start, order},
@@ -697,15 +698,15 @@ impl App {
697698

698699
fn switch_tab(&mut self, k: &KeyEvent) -> Result<()> {
699700
if key_match(k, self.key_config.keys.tab_status) {
700-
self.set_tab(0)?;
701+
self.switch_to_tab(&AppTabs::Status)?;
701702
} else if key_match(k, self.key_config.keys.tab_log) {
702-
self.set_tab(1)?;
703+
self.switch_to_tab(&AppTabs::Log)?;
703704
} else if key_match(k, self.key_config.keys.tab_files) {
704-
self.set_tab(2)?;
705+
self.switch_to_tab(&AppTabs::Files)?;
705706
} else if key_match(k, self.key_config.keys.tab_stashing) {
706-
self.set_tab(3)?;
707+
self.switch_to_tab(&AppTabs::Stashing)?;
707708
} else if key_match(k, self.key_config.keys.tab_stashes) {
708-
self.set_tab(4)?;
709+
self.switch_to_tab(&AppTabs::Stashlist)?;
709710
}
710711

711712
Ok(())
@@ -727,6 +728,17 @@ impl App {
727728
Ok(())
728729
}
729730

731+
fn switch_to_tab(&mut self, tab: &AppTabs) -> Result<()> {
732+
match tab {
733+
AppTabs::Status => self.set_tab(0)?,
734+
AppTabs::Log => self.set_tab(1)?,
735+
AppTabs::Files => self.set_tab(2)?,
736+
AppTabs::Stashing => self.set_tab(3)?,
737+
AppTabs::Stashlist => self.set_tab(4)?,
738+
}
739+
Ok(())
740+
}
741+
730742
fn update_commands(&mut self) {
731743
if self.help.is_visible() {
732744
self.help.set_cmds(self.commands(true));
@@ -855,6 +867,10 @@ impl App {
855867
self.tags_popup.open()?;
856868
}
857869
InternalEvent::TabSwitchStatus => self.set_tab(0)?,
870+
InternalEvent::TabSwitch(tab) => {
871+
self.switch_to_tab(&tab)?;
872+
flags.insert(NeedsUpdate::ALL);
873+
}
858874
InternalEvent::SelectCommitInRevlog(id) => {
859875
if let Err(error) = self.revlog.select_commit(id) {
860876
self.queue.push(InternalEvent::ShowErrorMsg(

src/components/commitlist.rs

+22-6
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,11 @@ impl CommitList {
225225

226226
///
227227
pub fn set_commits(&mut self, commits: Vec<CommitId>) {
228-
self.commits = commits;
229-
self.fetch_commits(false);
228+
if commits != self.commits {
229+
self.items.clear();
230+
self.commits = commits;
231+
self.fetch_commits(false);
232+
}
230233
}
231234

232235
///
@@ -724,20 +727,33 @@ impl CommitList {
724727
self.items.needs_data(idx, idx_max)
725728
}
726729

730+
// checks if first entry in items is the same commit as we expect
731+
fn is_list_in_sync(&self) -> bool {
732+
self.items
733+
.index_offset_raw()
734+
.and_then(|index| {
735+
self.items
736+
.iter()
737+
.next()
738+
.map(|item| item.id == self.commits[index])
739+
})
740+
.unwrap_or_default()
741+
}
742+
727743
fn fetch_commits(&mut self, force: bool) {
728744
let want_min =
729745
self.selection().saturating_sub(SLICE_SIZE / 2);
730746
let commits = self.commits.len();
731747

732748
let want_min = want_min.min(commits);
733749

734-
if !self
750+
let index_in_sync = self
735751
.items
736752
.index_offset_raw()
737753
.map(|index| want_min == index)
738-
.unwrap_or_default()
739-
|| force
740-
{
754+
.unwrap_or_default();
755+
756+
if !index_in_sync || !self.is_list_in_sync() || force {
741757
let slice_end =
742758
want_min.saturating_add(SLICE_SIZE).min(commits);
743759

src/components/stashmsg.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use super::{
55
};
66
use crate::{
77
keys::{key_match, SharedKeyConfig},
8-
queue::{InternalEvent, NeedsUpdate, Queue},
8+
queue::{AppTabs, InternalEvent, Queue},
99
strings,
1010
tabs::StashingOptions,
1111
ui::style::SharedTheme,
@@ -79,9 +79,11 @@ impl Component for StashMsgComponent {
7979
self.input.clear();
8080
self.hide();
8181

82-
self.queue.push(InternalEvent::Update(
83-
NeedsUpdate::ALL,
84-
));
82+
self.queue.push(
83+
InternalEvent::TabSwitch(
84+
AppTabs::Stashlist,
85+
),
86+
);
8587
}
8688
Err(e) => {
8789
self.hide();

src/queue.rs

+10
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,14 @@ pub enum StackablePopupOpen {
7070
CompareCommits(InspectCommitOpen),
7171
}
7272

73+
pub enum AppTabs {
74+
Status,
75+
Log,
76+
Files,
77+
Stashing,
78+
Stashlist,
79+
}
80+
7381
///
7482
pub enum InternalEvent {
7583
///
@@ -91,6 +99,8 @@ pub enum InternalEvent {
9199
///
92100
TabSwitchStatus,
93101
///
102+
TabSwitch(AppTabs),
103+
///
94104
SelectCommitInRevlog(CommitId),
95105
///
96106
TagCommit(CommitId),

src/tabs/stashlist.rs

+2
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ impl StashList {
136136
self.list.clear_marked();
137137
self.update()?;
138138

139+
self.queue.push(InternalEvent::TabSwitchStatus);
140+
139141
Ok(())
140142
}
141143
}

0 commit comments

Comments
 (0)