Skip to content

Commit 7058ab1

Browse files
author
Stephan Dilly
committed
abstract queue into custom type
1 parent ab5b29e commit 7058ab1

25 files changed

+209
-290
lines changed

src/app.rs

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ impl App {
8383
theme: Theme,
8484
key_config: KeyConfig,
8585
) -> Self {
86-
let queue = Queue::default();
86+
let queue = Queue::new();
8787
let theme = Rc::new(theme);
8888
let key_config = Rc::new(key_config);
8989

@@ -544,14 +544,14 @@ impl App {
544544
let mut flags = NeedsUpdate::empty();
545545

546546
loop {
547-
let front = self.queue.borrow_mut().pop_front();
547+
let front = self.queue.pop();
548548
if let Some(e) = front {
549549
flags.insert(self.process_internal_event(e)?);
550550
} else {
551551
break;
552552
}
553553
}
554-
self.queue.borrow_mut().clear();
554+
self.queue.clear();
555555

556556
Ok(flags)
557557
}
@@ -609,11 +609,9 @@ impl App {
609609
}
610610
InternalEvent::SelectCommitInRevlog(id) => {
611611
if let Err(error) = self.revlog.select_commit(id) {
612-
self.queue.borrow_mut().push_back(
613-
InternalEvent::ShowErrorMsg(
614-
error.to_string(),
615-
),
616-
);
612+
self.queue.push(InternalEvent::ShowErrorMsg(
613+
error.to_string(),
614+
));
617615
} else {
618616
self.tags_popup.hide();
619617
flags.insert(NeedsUpdate::ALL);
@@ -677,30 +675,27 @@ impl App {
677675
Action::DeleteBranch(branch_ref) => {
678676
if let Err(e) = sync::delete_branch(CWD, &branch_ref)
679677
{
680-
self.queue.borrow_mut().push_back(
681-
InternalEvent::ShowErrorMsg(e.to_string()),
682-
);
678+
self.queue.push(InternalEvent::ShowErrorMsg(
679+
e.to_string(),
680+
));
683681
} else {
684682
flags.insert(NeedsUpdate::ALL);
685683
self.select_branch_popup.update_branches()?;
686684
}
687685
}
688686
Action::DeleteTag(tag_name) => {
689687
if let Err(error) = sync::delete_tag(CWD, &tag_name) {
690-
self.queue.borrow_mut().push_back(
691-
InternalEvent::ShowErrorMsg(
692-
error.to_string(),
693-
),
694-
);
688+
self.queue.push(InternalEvent::ShowErrorMsg(
689+
error.to_string(),
690+
));
695691
} else {
696692
flags.insert(NeedsUpdate::ALL);
697693
self.tags_popup.update_tags()?;
698694
}
699695
}
700-
Action::ForcePush(branch, force) => self
701-
.queue
702-
.borrow_mut()
703-
.push_back(InternalEvent::Push(branch, force)),
696+
Action::ForcePush(branch, force) => {
697+
self.queue.push(InternalEvent::Push(branch, force))
698+
}
704699
Action::PullMerge { rebase, .. } => {
705700
self.pull_popup.try_conflict_free_merge(rebase);
706701
flags.insert(NeedsUpdate::ALL);

src/components/blame_file.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ impl Component for BlameFileComponent {
209209
return self.selected_commit().map_or(
210210
Ok(EventState::NotConsumed),
211211
|id| {
212-
self.queue.borrow_mut().push_back(
212+
self.queue.push(
213213
InternalEvent::InspectCommit(
214214
id, None,
215215
),

src/components/branchlist.rs

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -199,36 +199,29 @@ impl Component for BranchListComponent {
199199
} else if e == self.key_config.create_branch
200200
&& self.local
201201
{
202-
self.queue
203-
.borrow_mut()
204-
.push_back(InternalEvent::CreateBranch);
202+
self.queue.push(InternalEvent::CreateBranch);
205203
} else if e == self.key_config.rename_branch
206204
&& self.valid_selection()
207205
{
208206
let cur_branch =
209207
&self.branches[self.selection as usize];
210-
self.queue.borrow_mut().push_back(
211-
InternalEvent::RenameBranch(
212-
cur_branch.reference.clone(),
213-
cur_branch.name.clone(),
214-
),
215-
);
208+
self.queue.push(InternalEvent::RenameBranch(
209+
cur_branch.reference.clone(),
210+
cur_branch.name.clone(),
211+
));
216212

217213
self.update_branches()?;
218214
} else if e == self.key_config.delete_branch
219215
&& !self.selection_is_cur_branch()
220216
&& self.valid_selection()
221217
{
222-
self.queue.borrow_mut().push_back(
223-
InternalEvent::ConfirmAction(
224-
Action::DeleteBranch(
225-
self.branches
226-
[self.selection as usize]
227-
.reference
228-
.clone(),
229-
),
218+
self.queue.push(InternalEvent::ConfirmAction(
219+
Action::DeleteBranch(
220+
self.branches[self.selection as usize]
221+
.reference
222+
.clone(),
230223
),
231-
);
224+
));
232225
} else if e == self.key_config.merge_branch
233226
&& !self.selection_is_cur_branch()
234227
&& self.valid_selection()
@@ -239,9 +232,9 @@ impl Component for BranchListComponent {
239232
self.merge_branch()
240233
);
241234
self.hide();
242-
self.queue.borrow_mut().push_back(
243-
InternalEvent::Update(NeedsUpdate::ALL),
244-
);
235+
self.queue.push(InternalEvent::Update(
236+
NeedsUpdate::ALL,
237+
));
245238
} else if e == self.key_config.tab_toggle {
246239
self.local = !self.local;
247240
self.update_branches()?;
@@ -506,9 +499,7 @@ impl BranchListComponent {
506499
self.update_branches()?;
507500
}
508501

509-
self.queue
510-
.borrow_mut()
511-
.push_back(InternalEvent::Update(NeedsUpdate::ALL));
502+
self.queue.push(InternalEvent::Update(NeedsUpdate::ALL));
512503

513504
Ok(())
514505
}

src/components/changes.rs

Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,8 @@ impl ChangesComponent {
8888
};
8989

9090
if self.is_empty() {
91-
self.queue.borrow_mut().push_back(
92-
InternalEvent::StatusLastFileMoved,
93-
);
91+
self.queue
92+
.push(InternalEvent::StatusLastFileMoved);
9493
}
9594

9695
return Ok(true);
@@ -116,19 +115,15 @@ impl ChangesComponent {
116115
fn index_add_all(&mut self) -> Result<()> {
117116
sync::stage_add_all(CWD, "*")?;
118117

119-
self.queue
120-
.borrow_mut()
121-
.push_back(InternalEvent::Update(NeedsUpdate::ALL));
118+
self.queue.push(InternalEvent::Update(NeedsUpdate::ALL));
122119

123120
Ok(())
124121
}
125122

126123
fn stage_remove_all(&mut self) -> Result<()> {
127124
sync::reset_stage(CWD, "*")?;
128125

129-
self.queue
130-
.borrow_mut()
131-
.push_back(InternalEvent::Update(NeedsUpdate::ALL));
126+
self.queue.push(InternalEvent::Update(NeedsUpdate::ALL));
132127

133128
Ok(())
134129
}
@@ -137,14 +132,12 @@ impl ChangesComponent {
137132
if let Some(tree_item) = self.selection() {
138133
let is_folder =
139134
matches!(tree_item.kind, FileTreeItemKind::Path(_));
140-
self.queue.borrow_mut().push_back(
141-
InternalEvent::ConfirmAction(Action::Reset(
142-
ResetItem {
143-
path: tree_item.info.full_path,
144-
is_folder,
145-
},
146-
)),
147-
);
135+
self.queue.push(InternalEvent::ConfirmAction(
136+
Action::Reset(ResetItem {
137+
path: tree_item.info.full_path,
138+
is_folder,
139+
}),
140+
));
148141

149142
return true;
150143
}
@@ -156,16 +149,15 @@ impl ChangesComponent {
156149
if let Err(e) =
157150
sync::add_to_ignore(CWD, &tree_item.info.full_path)
158151
{
159-
self.queue.borrow_mut().push_back(
160-
InternalEvent::ShowErrorMsg(format!(
152+
self.queue.push(InternalEvent::ShowErrorMsg(
153+
format!(
161154
"ignore error:\n{}\nfile:\n{:?}",
162155
e, tree_item.info.full_path
163-
)),
164-
);
156+
),
157+
));
165158
} else {
166-
self.queue.borrow_mut().push_back(
167-
InternalEvent::Update(NeedsUpdate::ALL),
168-
);
159+
self.queue
160+
.push(InternalEvent::Update(NeedsUpdate::ALL));
169161

170162
return true;
171163
}
@@ -253,9 +245,7 @@ impl Component for ChangesComponent {
253245
&& !self.is_working_dir
254246
&& !self.is_empty()
255247
{
256-
self.queue
257-
.borrow_mut()
258-
.push_back(InternalEvent::OpenCommit);
248+
self.queue.push(InternalEvent::OpenCommit);
259249
Ok(EventState::Consumed)
260250
} else if e == self.key_config.enter {
261251
try_or_popup!(
@@ -264,9 +254,9 @@ impl Component for ChangesComponent {
264254
self.index_add_remove()
265255
);
266256

267-
self.queue.borrow_mut().push_back(
268-
InternalEvent::Update(NeedsUpdate::ALL),
269-
);
257+
self.queue.push(InternalEvent::Update(
258+
NeedsUpdate::ALL,
259+
));
270260
Ok(EventState::Consumed)
271261
} else if e == self.key_config.status_stage_all
272262
&& !self.is_empty()
@@ -280,9 +270,8 @@ impl Component for ChangesComponent {
280270
} else {
281271
self.stage_remove_all()?;
282272
}
283-
self.queue.borrow_mut().push_back(
284-
InternalEvent::StatusLastFileMoved,
285-
);
273+
self.queue
274+
.push(InternalEvent::StatusLastFileMoved);
286275
Ok(EventState::Consumed)
287276
} else if e == self.key_config.status_reset_item
288277
&& self.is_working_dir

src/components/commit.rs

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -187,25 +187,21 @@ impl CommitComponent {
187187
fn commit_with_msg(&mut self, msg: String) -> Result<()> {
188188
if let HookResult::NotOk(e) = sync::hooks_pre_commit(CWD)? {
189189
log::error!("pre-commit hook error: {}", e);
190-
self.queue.borrow_mut().push_back(
191-
InternalEvent::ShowErrorMsg(format!(
192-
"pre-commit hook error:\n{}",
193-
e
194-
)),
195-
);
190+
self.queue.push(InternalEvent::ShowErrorMsg(format!(
191+
"pre-commit hook error:\n{}",
192+
e
193+
)));
196194
return Ok(());
197195
}
198196
let mut msg = msg;
199197
if let HookResult::NotOk(e) =
200198
sync::hooks_commit_msg(CWD, &mut msg)?
201199
{
202200
log::error!("commit-msg hook error: {}", e);
203-
self.queue.borrow_mut().push_back(
204-
InternalEvent::ShowErrorMsg(format!(
205-
"commit-msg hook error:\n{}",
206-
e
207-
)),
208-
);
201+
self.queue.push(InternalEvent::ShowErrorMsg(format!(
202+
"commit-msg hook error:\n{}",
203+
e
204+
)));
209205
return Ok(());
210206
}
211207

@@ -217,30 +213,24 @@ impl CommitComponent {
217213

218214
if let Err(e) = res {
219215
log::error!("commit error: {}", &e);
220-
self.queue.borrow_mut().push_back(
221-
InternalEvent::ShowErrorMsg(format!(
222-
"commit failed:\n{}",
223-
&e
224-
)),
225-
);
216+
self.queue.push(InternalEvent::ShowErrorMsg(format!(
217+
"commit failed:\n{}",
218+
&e
219+
)));
226220
return Ok(());
227221
}
228222

229223
if let HookResult::NotOk(e) = sync::hooks_post_commit(CWD)? {
230224
log::error!("post-commit hook error: {}", e);
231-
self.queue.borrow_mut().push_back(
232-
InternalEvent::ShowErrorMsg(format!(
233-
"post-commit hook error:\n{}",
234-
e
235-
)),
236-
);
225+
self.queue.push(InternalEvent::ShowErrorMsg(format!(
226+
"post-commit hook error:\n{}",
227+
e
228+
)));
237229
}
238230

239231
self.hide();
240232

241-
self.queue
242-
.borrow_mut()
243-
.push_back(InternalEvent::Update(NeedsUpdate::ALL));
233+
self.queue.push(InternalEvent::Update(NeedsUpdate::ALL));
244234

245235
Ok(())
246236
}
@@ -349,7 +339,7 @@ impl Component for CommitComponent {
349339
{
350340
self.amend()?;
351341
} else if e == self.key_config.open_commit_editor {
352-
self.queue.borrow_mut().push_back(
342+
self.queue.push(
353343
InternalEvent::OpenExternalEditor(None),
354344
);
355345
self.hide();

src/components/create_branch.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -122,18 +122,15 @@ impl CreateBranchComponent {
122122

123123
match res {
124124
Ok(_) => {
125-
self.queue.borrow_mut().push_back(
126-
InternalEvent::Update(NeedsUpdate::BRANCHES),
127-
);
125+
self.queue.push(InternalEvent::Update(
126+
NeedsUpdate::BRANCHES,
127+
));
128128
}
129129
Err(e) => {
130130
log::error!("create branch: {}", e,);
131-
self.queue.borrow_mut().push_back(
132-
InternalEvent::ShowErrorMsg(format!(
133-
"create branch error:\n{}",
134-
e,
135-
)),
136-
);
131+
self.queue.push(InternalEvent::ShowErrorMsg(
132+
format!("create branch error:\n{}", e,),
133+
));
137134
}
138135
}
139136
}

0 commit comments

Comments
 (0)