Skip to content

Commit 4c17660

Browse files
author
Mehran Kordi
authored
anyhow integration (closes #77)
1 parent fc88452 commit 4c17660

File tree

24 files changed

+597
-393
lines changed

24 files changed

+597
-393
lines changed

Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ chrono = "0.4"
3535
backtrace = "0.3"
3636
ron = "0.6"
3737
serde = "1.0"
38+
anyhow = "1.0.31"
3839

3940
[features]
4041
default=[]

asyncgit/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#![forbid(unsafe_code)]
44
#![forbid(missing_docs)]
55
#![deny(clippy::all)]
6+
#![deny(clippy::result_unwrap_used)]
67

78
mod diff;
89
mod error;

asyncgit/src/status.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use sync::status::StatusType;
1616
fn current_tick() -> u64 {
1717
SystemTime::now()
1818
.duration_since(UNIX_EPOCH)
19-
.unwrap()
19+
.expect("time before unix epoch!")
2020
.as_millis() as u64
2121
}
2222

scopetime/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
#![forbid(unsafe_code)]
44
#![forbid(missing_docs)]
5+
#![deny(clippy::result_unwrap_used)]
56

67
use log::trace;
78
use std::time::Instant;

src/app.rs

Lines changed: 60 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use crate::{
1111
tabs::{Revlog, Stashing, Status},
1212
ui::style::Theme,
1313
};
14+
use anyhow::Result;
1415
use asyncgit::{sync, AsyncNotification, CWD};
1516
use crossbeam_channel::Sender;
1617
use crossterm::event::Event;
@@ -26,7 +27,6 @@ use tui::{
2627
widgets::{Block, Borders, Paragraph, Tabs, Text},
2728
Frame,
2829
};
29-
3030
///
3131
pub struct App {
3232
do_quit: bool,
@@ -73,7 +73,10 @@ impl App {
7373
}
7474

7575
///
76-
pub fn draw<B: Backend>(&mut self, f: &mut Frame<B>) {
76+
pub fn draw<B: Backend>(
77+
&mut self,
78+
f: &mut Frame<B>,
79+
) -> Result<()> {
7780
let chunks_main = Layout::default()
7881
.direction(Direction::Vertical)
7982
.constraints(
@@ -90,9 +93,9 @@ impl App {
9093

9194
//TODO: macro because of generic draw call
9295
match self.tab {
93-
0 => self.status_tab.draw(f, chunks_main[1]),
94-
1 => self.revlog.draw(f, chunks_main[1]),
95-
2 => self.stashing_tab.draw(f, chunks_main[1]),
96+
0 => self.status_tab.draw(f, chunks_main[1])?,
97+
1 => self.revlog.draw(f, chunks_main[1])?,
98+
2 => self.stashing_tab.draw(f, chunks_main[1])?,
9699
_ => panic!("unknown tab"),
97100
};
98101

@@ -103,25 +106,27 @@ impl App {
103106
self.theme,
104107
);
105108

106-
self.draw_popups(f);
109+
self.draw_popups(f)?;
110+
111+
Ok(())
107112
}
108113

109114
///
110-
pub fn event(&mut self, ev: Event) {
115+
pub fn event(&mut self, ev: Event) -> Result<()> {
111116
trace!("event: {:?}", ev);
112117

113118
if self.check_quit(ev) {
114-
return;
119+
return Ok(());
115120
}
116121

117122
let mut flags = NeedsUpdate::empty();
118123

119-
if event_pump(ev, self.components_mut().as_mut_slice()) {
124+
if event_pump(ev, self.components_mut().as_mut_slice())? {
120125
flags.insert(NeedsUpdate::COMMANDS);
121126
} else if let Event::Key(k) = ev {
122127
let new_flags = match k {
123128
keys::TAB_TOGGLE => {
124-
self.toggle_tabs();
129+
self.toggle_tabs()?;
125130
NeedsUpdate::COMMANDS
126131
}
127132

@@ -131,42 +136,51 @@ impl App {
131136
flags.insert(new_flags);
132137
}
133138

134-
let new_flags = self.process_queue();
139+
let new_flags = self.process_queue()?;
135140
flags.insert(new_flags);
136141

137142
if flags.contains(NeedsUpdate::ALL) {
138-
self.update();
143+
self.update()?;
139144
}
140145
if flags.contains(NeedsUpdate::DIFF) {
141-
self.status_tab.update_diff();
146+
self.status_tab.update_diff()?;
142147
}
143148
if flags.contains(NeedsUpdate::COMMANDS) {
144149
self.update_commands();
145150
}
151+
152+
Ok(())
146153
}
147154

148155
//TODO: do we need this?
149156
/// forward ticking to components that require it
150-
pub fn update(&mut self) {
157+
pub fn update(&mut self) -> Result<()> {
151158
trace!("update");
152-
self.status_tab.update();
153-
self.revlog.update();
154-
self.stashing_tab.update();
159+
self.status_tab.update()?;
160+
self.revlog.update()?;
161+
self.stashing_tab.update()?;
162+
163+
Ok(())
155164
}
156165

157166
///
158-
pub fn update_git(&mut self, ev: AsyncNotification) {
167+
pub fn update_git(
168+
&mut self,
169+
ev: AsyncNotification,
170+
) -> Result<()> {
159171
trace!("update_git: {:?}", ev);
160172

161-
self.status_tab.update_git(ev);
162-
self.stashing_tab.update_git(ev);
173+
self.status_tab.update_git(ev)?;
174+
self.stashing_tab.update_git(ev)?;
163175

164176
match ev {
165177
AsyncNotification::Diff => (),
166-
AsyncNotification::Log => self.revlog.update(),
178+
AsyncNotification::Log => self.revlog.update()?,
167179
//TODO: is that needed?
168180
AsyncNotification::Status => self.update_commands(),
169181
}
182+
183+
Ok(())
170184
}
171185

172186
///
@@ -216,21 +230,23 @@ impl App {
216230
]
217231
}
218232

219-
fn toggle_tabs(&mut self) {
233+
fn toggle_tabs(&mut self) -> Result<()> {
220234
let mut new_tab = self.tab + 1;
221235
{
222236
let tabs = self.get_tabs();
223237
new_tab %= tabs.len();
224238

225239
for (i, t) in tabs.into_iter().enumerate() {
226240
if new_tab == i {
227-
t.show();
241+
t.show()?;
228242
} else {
229243
t.hide();
230244
}
231245
}
232246
}
233247
self.tab = new_tab;
248+
249+
Ok(())
234250
}
235251

236252
fn update_commands(&mut self) {
@@ -239,25 +255,25 @@ impl App {
239255
self.current_commands.sort_by_key(|e| e.order);
240256
}
241257

242-
fn process_queue(&mut self) -> NeedsUpdate {
258+
fn process_queue(&mut self) -> Result<NeedsUpdate> {
243259
let mut flags = NeedsUpdate::empty();
244260
loop {
245261
let front = self.queue.borrow_mut().pop_front();
246262
if let Some(e) = front {
247-
flags.insert(self.process_internal_event(e));
263+
flags.insert(self.process_internal_event(e)?);
248264
} else {
249265
break;
250266
}
251267
}
252268
self.queue.borrow_mut().clear();
253269

254-
flags
270+
Ok(flags)
255271
}
256272

257273
fn process_internal_event(
258274
&mut self,
259275
ev: InternalEvent,
260-
) -> NeedsUpdate {
276+
) -> Result<NeedsUpdate> {
261277
let mut flags = NeedsUpdate::empty();
262278
match ev {
263279
InternalEvent::ResetItem(reset_item) => {
@@ -280,17 +296,15 @@ impl App {
280296
}
281297
}
282298
InternalEvent::ConfirmResetItem(reset_item) => {
283-
self.reset.open_for_path(reset_item);
299+
self.reset.open_for_path(reset_item)?;
284300
flags.insert(NeedsUpdate::COMMANDS);
285301
}
286302
InternalEvent::AddHunk(hash) => {
287303
if let Some((path, is_stage)) =
288304
self.status_tab.selected_path()
289305
{
290306
if is_stage {
291-
if sync::unstage_hunk(CWD, path, hash)
292-
.unwrap()
293-
{
307+
if sync::unstage_hunk(CWD, path, hash)? {
294308
flags.insert(NeedsUpdate::ALL);
295309
}
296310
} else if sync::stage_hunk(CWD, path, hash)
@@ -301,17 +315,17 @@ impl App {
301315
}
302316
}
303317
InternalEvent::ShowErrorMsg(msg) => {
304-
self.msg.show_msg(msg.as_str());
318+
self.msg.show_msg(msg.as_str())?;
305319
flags.insert(NeedsUpdate::ALL);
306320
}
307321
InternalEvent::Update(u) => flags.insert(u),
308-
InternalEvent::OpenCommit => self.commit.show(),
322+
InternalEvent::OpenCommit => self.commit.show()?,
309323
InternalEvent::PopupStashing(_opts) => {
310-
self.stashmsg_popup.show()
324+
self.stashmsg_popup.show()?
311325
}
312326
};
313327

314-
flags
328+
Ok(flags)
315329
}
316330

317331
fn commands(&self, force_all: bool) -> Vec<CommandInfo> {
@@ -354,14 +368,19 @@ impl App {
354368
|| self.msg.is_visible()
355369
}
356370

357-
fn draw_popups<B: Backend>(&mut self, f: &mut Frame<B>) {
371+
fn draw_popups<B: Backend>(
372+
&mut self,
373+
f: &mut Frame<B>,
374+
) -> Result<()> {
358375
let size = f.size();
359376

360-
self.commit.draw(f, size);
361-
self.stashmsg_popup.draw(f, size);
362-
self.reset.draw(f, size);
363-
self.help.draw(f, size);
364-
self.msg.draw(f, size);
377+
self.commit.draw(f, size)?;
378+
self.stashmsg_popup.draw(f, size)?;
379+
self.reset.draw(f, size)?;
380+
self.help.draw(f, size)?;
381+
self.msg.draw(f, size)?;
382+
383+
Ok(())
365384
}
366385

367386
fn draw_tabs<B: Backend>(&self, f: &mut Frame<B>, r: Rect) {

0 commit comments

Comments
 (0)