abstract queue into custom type

This commit is contained in:
Stephan Dilly 2021-06-07 22:57:27 +02:00
parent ab5b29e0ee
commit 7058ab14d3
25 changed files with 209 additions and 290 deletions

View file

@ -83,7 +83,7 @@ impl App {
theme: Theme,
key_config: KeyConfig,
) -> Self {
let queue = Queue::default();
let queue = Queue::new();
let theme = Rc::new(theme);
let key_config = Rc::new(key_config);
@ -544,14 +544,14 @@ impl App {
let mut flags = NeedsUpdate::empty();
loop {
let front = self.queue.borrow_mut().pop_front();
let front = self.queue.pop();
if let Some(e) = front {
flags.insert(self.process_internal_event(e)?);
} else {
break;
}
}
self.queue.borrow_mut().clear();
self.queue.clear();
Ok(flags)
}
@ -609,11 +609,9 @@ impl App {
}
InternalEvent::SelectCommitInRevlog(id) => {
if let Err(error) = self.revlog.select_commit(id) {
self.queue.borrow_mut().push_back(
InternalEvent::ShowErrorMsg(
error.to_string(),
),
);
self.queue.push(InternalEvent::ShowErrorMsg(
error.to_string(),
));
} else {
self.tags_popup.hide();
flags.insert(NeedsUpdate::ALL);
@ -677,9 +675,9 @@ impl App {
Action::DeleteBranch(branch_ref) => {
if let Err(e) = sync::delete_branch(CWD, &branch_ref)
{
self.queue.borrow_mut().push_back(
InternalEvent::ShowErrorMsg(e.to_string()),
);
self.queue.push(InternalEvent::ShowErrorMsg(
e.to_string(),
));
} else {
flags.insert(NeedsUpdate::ALL);
self.select_branch_popup.update_branches()?;
@ -687,20 +685,17 @@ impl App {
}
Action::DeleteTag(tag_name) => {
if let Err(error) = sync::delete_tag(CWD, &tag_name) {
self.queue.borrow_mut().push_back(
InternalEvent::ShowErrorMsg(
error.to_string(),
),
);
self.queue.push(InternalEvent::ShowErrorMsg(
error.to_string(),
));
} else {
flags.insert(NeedsUpdate::ALL);
self.tags_popup.update_tags()?;
}
}
Action::ForcePush(branch, force) => self
.queue
.borrow_mut()
.push_back(InternalEvent::Push(branch, force)),
Action::ForcePush(branch, force) => {
self.queue.push(InternalEvent::Push(branch, force))
}
Action::PullMerge { rebase, .. } => {
self.pull_popup.try_conflict_free_merge(rebase);
flags.insert(NeedsUpdate::ALL);

View file

@ -209,7 +209,7 @@ impl Component for BlameFileComponent {
return self.selected_commit().map_or(
Ok(EventState::NotConsumed),
|id| {
self.queue.borrow_mut().push_back(
self.queue.push(
InternalEvent::InspectCommit(
id, None,
),

View file

@ -199,36 +199,29 @@ impl Component for BranchListComponent {
} else if e == self.key_config.create_branch
&& self.local
{
self.queue
.borrow_mut()
.push_back(InternalEvent::CreateBranch);
self.queue.push(InternalEvent::CreateBranch);
} else if e == self.key_config.rename_branch
&& self.valid_selection()
{
let cur_branch =
&self.branches[self.selection as usize];
self.queue.borrow_mut().push_back(
InternalEvent::RenameBranch(
cur_branch.reference.clone(),
cur_branch.name.clone(),
),
);
self.queue.push(InternalEvent::RenameBranch(
cur_branch.reference.clone(),
cur_branch.name.clone(),
));
self.update_branches()?;
} else if e == self.key_config.delete_branch
&& !self.selection_is_cur_branch()
&& self.valid_selection()
{
self.queue.borrow_mut().push_back(
InternalEvent::ConfirmAction(
Action::DeleteBranch(
self.branches
[self.selection as usize]
.reference
.clone(),
),
self.queue.push(InternalEvent::ConfirmAction(
Action::DeleteBranch(
self.branches[self.selection as usize]
.reference
.clone(),
),
);
));
} else if e == self.key_config.merge_branch
&& !self.selection_is_cur_branch()
&& self.valid_selection()
@ -239,9 +232,9 @@ impl Component for BranchListComponent {
self.merge_branch()
);
self.hide();
self.queue.borrow_mut().push_back(
InternalEvent::Update(NeedsUpdate::ALL),
);
self.queue.push(InternalEvent::Update(
NeedsUpdate::ALL,
));
} else if e == self.key_config.tab_toggle {
self.local = !self.local;
self.update_branches()?;
@ -506,9 +499,7 @@ impl BranchListComponent {
self.update_branches()?;
}
self.queue
.borrow_mut()
.push_back(InternalEvent::Update(NeedsUpdate::ALL));
self.queue.push(InternalEvent::Update(NeedsUpdate::ALL));
Ok(())
}

View file

@ -88,9 +88,8 @@ impl ChangesComponent {
};
if self.is_empty() {
self.queue.borrow_mut().push_back(
InternalEvent::StatusLastFileMoved,
);
self.queue
.push(InternalEvent::StatusLastFileMoved);
}
return Ok(true);
@ -116,9 +115,7 @@ impl ChangesComponent {
fn index_add_all(&mut self) -> Result<()> {
sync::stage_add_all(CWD, "*")?;
self.queue
.borrow_mut()
.push_back(InternalEvent::Update(NeedsUpdate::ALL));
self.queue.push(InternalEvent::Update(NeedsUpdate::ALL));
Ok(())
}
@ -126,9 +123,7 @@ impl ChangesComponent {
fn stage_remove_all(&mut self) -> Result<()> {
sync::reset_stage(CWD, "*")?;
self.queue
.borrow_mut()
.push_back(InternalEvent::Update(NeedsUpdate::ALL));
self.queue.push(InternalEvent::Update(NeedsUpdate::ALL));
Ok(())
}
@ -137,14 +132,12 @@ impl ChangesComponent {
if let Some(tree_item) = self.selection() {
let is_folder =
matches!(tree_item.kind, FileTreeItemKind::Path(_));
self.queue.borrow_mut().push_back(
InternalEvent::ConfirmAction(Action::Reset(
ResetItem {
path: tree_item.info.full_path,
is_folder,
},
)),
);
self.queue.push(InternalEvent::ConfirmAction(
Action::Reset(ResetItem {
path: tree_item.info.full_path,
is_folder,
}),
));
return true;
}
@ -156,16 +149,15 @@ impl ChangesComponent {
if let Err(e) =
sync::add_to_ignore(CWD, &tree_item.info.full_path)
{
self.queue.borrow_mut().push_back(
InternalEvent::ShowErrorMsg(format!(
self.queue.push(InternalEvent::ShowErrorMsg(
format!(
"ignore error:\n{}\nfile:\n{:?}",
e, tree_item.info.full_path
)),
);
),
));
} else {
self.queue.borrow_mut().push_back(
InternalEvent::Update(NeedsUpdate::ALL),
);
self.queue
.push(InternalEvent::Update(NeedsUpdate::ALL));
return true;
}
@ -253,9 +245,7 @@ impl Component for ChangesComponent {
&& !self.is_working_dir
&& !self.is_empty()
{
self.queue
.borrow_mut()
.push_back(InternalEvent::OpenCommit);
self.queue.push(InternalEvent::OpenCommit);
Ok(EventState::Consumed)
} else if e == self.key_config.enter {
try_or_popup!(
@ -264,9 +254,9 @@ impl Component for ChangesComponent {
self.index_add_remove()
);
self.queue.borrow_mut().push_back(
InternalEvent::Update(NeedsUpdate::ALL),
);
self.queue.push(InternalEvent::Update(
NeedsUpdate::ALL,
));
Ok(EventState::Consumed)
} else if e == self.key_config.status_stage_all
&& !self.is_empty()
@ -280,9 +270,8 @@ impl Component for ChangesComponent {
} else {
self.stage_remove_all()?;
}
self.queue.borrow_mut().push_back(
InternalEvent::StatusLastFileMoved,
);
self.queue
.push(InternalEvent::StatusLastFileMoved);
Ok(EventState::Consumed)
} else if e == self.key_config.status_reset_item
&& self.is_working_dir

View file

@ -187,12 +187,10 @@ impl CommitComponent {
fn commit_with_msg(&mut self, msg: String) -> Result<()> {
if let HookResult::NotOk(e) = sync::hooks_pre_commit(CWD)? {
log::error!("pre-commit hook error: {}", e);
self.queue.borrow_mut().push_back(
InternalEvent::ShowErrorMsg(format!(
"pre-commit hook error:\n{}",
e
)),
);
self.queue.push(InternalEvent::ShowErrorMsg(format!(
"pre-commit hook error:\n{}",
e
)));
return Ok(());
}
let mut msg = msg;
@ -200,12 +198,10 @@ impl CommitComponent {
sync::hooks_commit_msg(CWD, &mut msg)?
{
log::error!("commit-msg hook error: {}", e);
self.queue.borrow_mut().push_back(
InternalEvent::ShowErrorMsg(format!(
"commit-msg hook error:\n{}",
e
)),
);
self.queue.push(InternalEvent::ShowErrorMsg(format!(
"commit-msg hook error:\n{}",
e
)));
return Ok(());
}
@ -217,30 +213,24 @@ impl CommitComponent {
if let Err(e) = res {
log::error!("commit error: {}", &e);
self.queue.borrow_mut().push_back(
InternalEvent::ShowErrorMsg(format!(
"commit failed:\n{}",
&e
)),
);
self.queue.push(InternalEvent::ShowErrorMsg(format!(
"commit failed:\n{}",
&e
)));
return Ok(());
}
if let HookResult::NotOk(e) = sync::hooks_post_commit(CWD)? {
log::error!("post-commit hook error: {}", e);
self.queue.borrow_mut().push_back(
InternalEvent::ShowErrorMsg(format!(
"post-commit hook error:\n{}",
e
)),
);
self.queue.push(InternalEvent::ShowErrorMsg(format!(
"post-commit hook error:\n{}",
e
)));
}
self.hide();
self.queue
.borrow_mut()
.push_back(InternalEvent::Update(NeedsUpdate::ALL));
self.queue.push(InternalEvent::Update(NeedsUpdate::ALL));
Ok(())
}
@ -349,7 +339,7 @@ impl Component for CommitComponent {
{
self.amend()?;
} else if e == self.key_config.open_commit_editor {
self.queue.borrow_mut().push_back(
self.queue.push(
InternalEvent::OpenExternalEditor(None),
);
self.hide();

View file

@ -122,18 +122,15 @@ impl CreateBranchComponent {
match res {
Ok(_) => {
self.queue.borrow_mut().push_back(
InternalEvent::Update(NeedsUpdate::BRANCHES),
);
self.queue.push(InternalEvent::Update(
NeedsUpdate::BRANCHES,
));
}
Err(e) => {
log::error!("create branch: {}", e,);
self.queue.borrow_mut().push_back(
InternalEvent::ShowErrorMsg(format!(
"create branch error:\n{}",
e,
)),
);
self.queue.push(InternalEvent::ShowErrorMsg(
format!("create branch error:\n{}", e,),
));
}
}
}

View file

@ -491,10 +491,7 @@ impl DiffComponent {
}
fn queue_update(&self) {
self.queue
.as_ref()
.borrow_mut()
.push_back(InternalEvent::Update(NeedsUpdate::ALL));
self.queue.push(InternalEvent::Update(NeedsUpdate::ALL));
}
fn reset_hunk(&self) {
@ -502,23 +499,23 @@ impl DiffComponent {
if let Some(hunk) = self.selected_hunk {
let hash = diff.hunks[hunk].header_hash;
self.queue.as_ref().borrow_mut().push_back(
InternalEvent::ConfirmAction(Action::ResetHunk(
self.queue.push(InternalEvent::ConfirmAction(
Action::ResetHunk(
self.current.path.clone(),
hash,
)),
);
),
));
}
}
}
fn reset_lines(&self) {
self.queue.as_ref().borrow_mut().push_back(
InternalEvent::ConfirmAction(Action::ResetLines(
self.queue.push(InternalEvent::ConfirmAction(
Action::ResetLines(
self.current.path.clone(),
self.selected_lines(),
)),
);
),
));
}
fn stage_lines(&self) {
@ -569,12 +566,12 @@ impl DiffComponent {
}
fn reset_untracked(&self) {
self.queue.as_ref().borrow_mut().push_back(
InternalEvent::ConfirmAction(Action::Reset(ResetItem {
self.queue.push(InternalEvent::ConfirmAction(Action::Reset(
ResetItem {
path: self.current.path.clone(),
is_folder: false,
})),
);
},
)));
}
fn stage_unstage_hunk(&mut self) -> Result<()> {

View file

@ -129,9 +129,7 @@ impl FileTreeComponent {
if changed {
if let Some(ref queue) = self.queue {
queue.borrow_mut().push_back(InternalEvent::Update(
NeedsUpdate::DIFF,
));
queue.push(InternalEvent::Update(NeedsUpdate::DIFF));
}
}
@ -409,11 +407,9 @@ impl Component for FileTreeComponent {
return if e == self.key_config.blame {
match (&self.queue, self.selection_file()) {
(Some(queue), Some(status_item)) => {
queue.borrow_mut().push_back(
InternalEvent::BlameFile(
status_item.path,
),
);
queue.push(InternalEvent::BlameFile(
status_item.path,
));
Ok(EventState::Consumed)
}

View file

@ -138,9 +138,9 @@ impl Component for InspectCommitComponent {
self.diff.focus(false);
} else if e == self.key_config.open_file_tree {
if let Some(commit) = self.commit_id {
self.queue.borrow_mut().push_back(
InternalEvent::OpenFileTree(commit),
);
self.queue.push(InternalEvent::OpenFileTree(
commit,
));
self.hide();
}
} else if e == self.key_config.focus_left {

View file

@ -136,12 +136,9 @@ impl PullComponent {
} else {
self.pending = false;
self.hide();
self.queue.borrow_mut().push_back(
InternalEvent::ShowErrorMsg(format!(
"fetch failed:\n{}",
err
)),
);
self.queue.push(InternalEvent::ShowErrorMsg(
format!("fetch failed:\n{}", err),
));
}
}
}
@ -186,13 +183,13 @@ impl PullComponent {
}
fn confirm_merge(&mut self, incoming: usize) {
self.queue.borrow_mut().push_back(
InternalEvent::ConfirmAction(Action::PullMerge {
self.queue.push(InternalEvent::ConfirmAction(
Action::PullMerge {
incoming,
rebase: sync::config_is_pull_rebase(CWD)
.unwrap_or_default(),
}),
);
},
));
self.hide();
}
}

View file

@ -148,12 +148,9 @@ impl PushComponent {
if !self.pending {
if let Some(err) = self.git_push.last_result()? {
self.queue.borrow_mut().push_back(
InternalEvent::ShowErrorMsg(format!(
"push failed:\n{}",
err
)),
);
self.queue.push(InternalEvent::ShowErrorMsg(
format!("push failed:\n{}", err),
));
}
self.hide();
}

View file

@ -117,12 +117,9 @@ impl PushTagsComponent {
if !self.pending {
if let Some(err) = self.git_push.last_result()? {
self.queue.borrow_mut().push_back(
InternalEvent::ShowErrorMsg(format!(
"push tags failed:\n{}",
err
)),
);
self.queue.push(InternalEvent::ShowErrorMsg(
format!("push tags failed:\n{}", err),
));
}
self.hide();
}

View file

@ -135,29 +135,22 @@ impl RenameBranchComponent {
match res {
Ok(_) => {
self.queue.borrow_mut().push_back(
InternalEvent::Update(NeedsUpdate::ALL),
);
self.queue.push(InternalEvent::Update(
NeedsUpdate::ALL,
));
self.hide();
self.queue
.borrow_mut()
.push_back(InternalEvent::SelectBranch);
self.queue.push(InternalEvent::SelectBranch);
}
Err(e) => {
log::error!("create branch: {}", e,);
self.queue.borrow_mut().push_back(
InternalEvent::ShowErrorMsg(format!(
"rename branch error:\n{}",
e,
)),
);
self.queue.push(InternalEvent::ShowErrorMsg(
format!("rename branch error:\n{}", e,),
));
}
}
} else {
log::error!("create branch: No branch selected");
self.queue
.borrow_mut()
.push_back(InternalEvent::ShowErrorMsg(
self.queue.push(InternalEvent::ShowErrorMsg(
"rename branch error: No branch selected to rename"
.to_string(),
));

View file

@ -126,9 +126,7 @@ impl ResetComponent {
///
pub fn confirm(&mut self) {
if let Some(a) = self.target.take() {
self.queue
.borrow_mut()
.push_back(InternalEvent::ConfirmedAction(a));
self.queue.push(InternalEvent::ConfirmedAction(a));
}
self.hide();

View file

@ -130,14 +130,12 @@ impl RevisionFilesComponent {
fn blame(&self) -> bool {
self.tree.selected_file().map_or(false, |file| {
self.queue.borrow_mut().push_back(
InternalEvent::BlameFile(
file.full_path_str()
.strip_prefix("./")
.unwrap_or_default()
.to_string(),
),
);
self.queue.push(InternalEvent::BlameFile(
file.full_path_str()
.strip_prefix("./")
.unwrap_or_default()
.to_string(),
));
true
})
}

View file

@ -77,11 +77,9 @@ impl Component for StashMsgComponent {
self.input.clear();
self.hide();
self.queue.borrow_mut().push_back(
InternalEvent::Update(
NeedsUpdate::ALL,
),
);
self.queue.push(InternalEvent::Update(
NeedsUpdate::ALL,
));
}
Err(e) => {
self.hide();
@ -90,7 +88,7 @@ impl Component for StashMsgComponent {
e,
self.options
);
self.queue.borrow_mut().push_back(
self.queue.push(
InternalEvent::ShowErrorMsg(format!(
"stash error:\n{}\noptions:\n{:?}",
e, self.options

View file

@ -126,19 +126,16 @@ impl TagCommitComponent {
self.input.clear();
self.hide();
self.queue.borrow_mut().push_back(
InternalEvent::Update(NeedsUpdate::ALL),
);
self.queue.push(InternalEvent::Update(
NeedsUpdate::ALL,
));
}
Err(e) => {
self.hide();
log::error!("e: {}", e,);
self.queue.borrow_mut().push_back(
InternalEvent::ShowErrorMsg(format!(
"tag error:\n{}",
e,
)),
);
self.queue.push(InternalEvent::ShowErrorMsg(
format!("tag error:\n{}", e,),
));
}
}
}

View file

@ -179,7 +179,7 @@ impl Component for TagListComponent {
return self.selected_tag().map_or(
Ok(EventState::NotConsumed),
|tag| {
self.queue.borrow_mut().push_back(
self.queue.push(
InternalEvent::ConfirmAction(
Action::DeleteTag(
tag.name.clone(),
@ -193,7 +193,7 @@ impl Component for TagListComponent {
return self.selected_tag().map_or(
Ok(EventState::NotConsumed),
|tag| {
self.queue.borrow_mut().push_back(
self.queue.push(
InternalEvent::SelectCommitInRevlog(
tag.commit_id,
),

View file

@ -13,12 +13,10 @@ macro_rules! try_or_popup {
($self:ident, $msg:literal, $e:expr) => {
if let Err(err) = $e {
::log::error!("{} {}", $msg, err);
$self.queue.borrow_mut().push_back(
InternalEvent::ShowErrorMsg(format!(
"{}\n{}",
$msg, err
)),
);
$self.queue.push(InternalEvent::ShowErrorMsg(format!(
"{}\n{}",
$msg, err
)));
}
};
}

View file

@ -85,5 +85,28 @@ pub enum InternalEvent {
OpenFileTree(CommitId),
}
///
pub type Queue = Rc<RefCell<VecDeque<InternalEvent>>>;
/// single threaded simple queue for components to communicate with each other
#[derive(Clone)]
pub struct Queue {
data: Rc<RefCell<VecDeque<InternalEvent>>>,
}
impl Queue {
pub fn new() -> Self {
Self {
data: Rc::new(RefCell::new(VecDeque::new())),
}
}
pub fn push(&self, ev: InternalEvent) {
self.data.borrow_mut().push_back(ev);
}
pub fn pop(&self) -> Option<InternalEvent> {
self.data.borrow_mut().pop_front()
}
pub fn clear(&self) {
self.data.borrow_mut().clear();
}
}

View file

@ -20,7 +20,6 @@ use crossbeam_channel::Sender;
pub struct FilesTab {
visible: bool,
theme: SharedTheme,
queue: Queue,
key_config: SharedKeyConfig,
files: RevisionFilesComponent,
}
@ -35,7 +34,6 @@ impl FilesTab {
) -> Self {
Self {
visible: false,
queue: queue.clone(),
files: RevisionFilesComponent::new(
queue,
sender,

View file

@ -225,17 +225,14 @@ impl Component for Revlog {
self.copy_commit_hash()?;
return Ok(EventState::Consumed);
} else if k == self.key_config.push {
self.queue
.borrow_mut()
.push_back(InternalEvent::PushTags);
self.queue.push(InternalEvent::PushTags);
return Ok(EventState::Consumed);
} else if k == self.key_config.log_tag_commit {
return self.selected_commit().map_or(
Ok(EventState::NotConsumed),
|id| {
self.queue.borrow_mut().push_back(
InternalEvent::TagCommit(id),
);
self.queue
.push(InternalEvent::TagCommit(id));
Ok(EventState::Consumed)
},
);
@ -245,7 +242,7 @@ impl Component for Revlog {
return self.selected_commit().map_or(
Ok(EventState::NotConsumed),
|id| {
self.queue.borrow_mut().push_back(
self.queue.push(
InternalEvent::InspectCommit(
id,
self.selected_commit_tags(&Some(
@ -257,24 +254,20 @@ impl Component for Revlog {
},
);
} else if k == self.key_config.select_branch {
self.queue
.borrow_mut()
.push_back(InternalEvent::SelectBranch);
self.queue.push(InternalEvent::SelectBranch);
return Ok(EventState::Consumed);
} else if k == self.key_config.open_file_tree {
return self.selected_commit().map_or(
Ok(EventState::NotConsumed),
|id| {
self.queue.borrow_mut().push_back(
self.queue.push(
InternalEvent::OpenFileTree(id),
);
Ok(EventState::Consumed)
},
);
} else if k == self.key_config.tags {
self.queue
.borrow_mut()
.push_back(InternalEvent::Tags);
self.queue.push(InternalEvent::Tags);
return Ok(EventState::Consumed);
}
}

View file

@ -221,9 +221,9 @@ impl Component for Stashing {
return if k == self.key_config.stashing_save
&& !self.index.is_empty()
{
self.queue.borrow_mut().push_back(
InternalEvent::PopupStashing(self.options),
);
self.queue.push(InternalEvent::PopupStashing(
self.options,
));
Ok(EventState::Consumed)
} else if k == self.key_config.stashing_toggle_index {

View file

@ -59,17 +59,12 @@ impl StashList {
if let Some(e) = self.list.selected_entry() {
match sync::stash_apply(CWD, e.id, false) {
Ok(_) => {
self.queue
.borrow_mut()
.push_back(InternalEvent::TabSwitch);
self.queue.push(InternalEvent::TabSwitch);
}
Err(e) => {
self.queue.borrow_mut().push_back(
InternalEvent::ShowErrorMsg(format!(
"stash apply error:\n{}",
e,
)),
);
self.queue.push(InternalEvent::ShowErrorMsg(
format!("stash apply error:\n{}", e,),
));
}
}
}
@ -77,25 +72,23 @@ impl StashList {
fn drop_stash(&mut self) {
if let Some(e) = self.list.selected_entry() {
self.queue.borrow_mut().push_back(
InternalEvent::ConfirmAction(Action::StashDrop(e.id)),
);
self.queue.push(InternalEvent::ConfirmAction(
Action::StashDrop(e.id),
));
}
}
fn pop_stash(&mut self) {
if let Some(e) = self.list.selected_entry() {
self.queue.borrow_mut().push_back(
InternalEvent::ConfirmAction(Action::StashPop(e.id)),
);
self.queue.push(InternalEvent::ConfirmAction(
Action::StashPop(e.id),
));
}
}
fn inspect(&mut self) {
if let Some(e) = self.list.selected_entry() {
self.queue
.borrow_mut()
.push_back(InternalEvent::InspectCommit(e.id, None));
self.queue.push(InternalEvent::InspectCommit(e.id, None));
}
}
@ -115,18 +108,13 @@ impl StashList {
fn pop(&self, id: CommitId) -> bool {
match sync::stash_pop(CWD, id) {
Ok(_) => {
self.queue
.borrow_mut()
.push_back(InternalEvent::TabSwitch);
self.queue.push(InternalEvent::TabSwitch);
true
}
Err(e) => {
self.queue.borrow_mut().push_back(
InternalEvent::ShowErrorMsg(format!(
"stash pop error:\n{}",
e,
)),
);
self.queue.push(InternalEvent::ShowErrorMsg(
format!("stash pop error:\n{}", e,),
));
true
}
}

View file

@ -422,12 +422,10 @@ impl Status {
/// called after confirmation
pub fn reset(&mut self, item: &ResetItem) -> bool {
if let Err(e) = sync::reset_workdir(CWD, item.path.as_str()) {
self.queue.borrow_mut().push_back(
InternalEvent::ShowErrorMsg(format!(
"reset failed:\n{}",
e
)),
);
self.queue.push(InternalEvent::ShowErrorMsg(format!(
"reset failed:\n{}",
e
)));
false
} else {
@ -446,15 +444,12 @@ impl Status {
if self.can_push() {
if let Some(branch) = self.git_branch_name.last() {
if force {
self.queue.borrow_mut().push_back(
InternalEvent::ConfirmAction(
Action::ForcePush(branch, force),
),
);
self.queue.push(InternalEvent::ConfirmAction(
Action::ForcePush(branch, force),
));
} else {
self.queue.borrow_mut().push_back(
InternalEvent::Push(branch, force),
);
self.queue
.push(InternalEvent::Push(branch, force));
}
}
}
@ -462,9 +457,7 @@ impl Status {
fn pull(&self) {
if let Some(branch) = self.git_branch_name.last() {
self.queue
.borrow_mut()
.push_back(InternalEvent::Pull(branch));
self.queue.push(InternalEvent::Pull(branch));
}
}
@ -646,7 +639,7 @@ impl Component for Status {
|| self.is_focus_on_diff())
{
if let Some((path, _)) = self.selected_path() {
self.queue.borrow_mut().push_back(
self.queue.push(
InternalEvent::OpenExternalEditor(Some(
path,
)),
@ -681,9 +674,7 @@ impl Component for Status {
} else if k == self.key_config.select_branch
&& !self.is_focus_on_diff()
{
self.queue
.borrow_mut()
.push_back(InternalEvent::SelectBranch);
self.queue.push(InternalEvent::SelectBranch);
Ok(EventState::Consumed)
} else if k == self.key_config.force_push
&& !self.is_focus_on_diff()
@ -705,18 +696,16 @@ impl Component for Status {
&& !self.is_focus_on_diff()
{
self.undo_last_commit();
self.queue.borrow_mut().push_back(
InternalEvent::Update(NeedsUpdate::ALL),
);
self.queue.push(InternalEvent::Update(
NeedsUpdate::ALL,
));
Ok(EventState::Consumed)
} else if k == self.key_config.abort_merge
&& Self::can_abort_merge()
{
self.queue.borrow_mut().push_back(
InternalEvent::ConfirmAction(
Action::AbortMerge,
),
);
self.queue.push(InternalEvent::ConfirmAction(
Action::AbortMerge,
));
Ok(EventState::Consumed)
} else {