- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 627
Add timeouts for commit hooks #2547
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
use std::time::Duration; | ||
|
||
use crate::{ | ||
app::Environment, | ||
components::{ | ||
|
@@ -27,6 +29,7 @@ pub enum AppOption { | |
DiffIgnoreWhitespaces, | ||
DiffContextLines, | ||
DiffInterhunkLines, | ||
HookTimeout, | ||
} | ||
|
||
pub struct OptionsPopup { | ||
|
@@ -99,6 +102,19 @@ impl OptionsPopup { | |
&diff.interhunk_lines.to_string(), | ||
self.is_select(AppOption::DiffInterhunkLines), | ||
); | ||
Self::add_header(txt, ""); | ||
|
||
Self::add_header(txt, "Hooks"); | ||
self.add_entry( | ||
txt, | ||
width, | ||
"Timeout", | ||
&self.options.borrow().hook_timeout().map_or_else( | ||
|| "None".to_string(), | ||
|d| format!("{d:?}"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was thinking the same thing originally but writing some redundant code or adding a new library to handle it seems like overkill for a single use. |
||
), | ||
self.is_select(AppOption::HookTimeout), | ||
); | ||
} | ||
|
||
fn is_select(&self, kind: AppOption) -> bool { | ||
|
@@ -138,7 +154,7 @@ impl OptionsPopup { | |
if up { | ||
self.selection = match self.selection { | ||
AppOption::StatusShowUntracked => { | ||
AppOption::DiffInterhunkLines | ||
AppOption::HookTimeout | ||
} | ||
AppOption::DiffIgnoreWhitespaces => { | ||
AppOption::StatusShowUntracked | ||
|
@@ -149,6 +165,9 @@ impl OptionsPopup { | |
AppOption::DiffInterhunkLines => { | ||
AppOption::DiffContextLines | ||
} | ||
AppOption::HookTimeout => { | ||
AppOption::DiffInterhunkLines | ||
} | ||
}; | ||
} else { | ||
self.selection = match self.selection { | ||
|
@@ -162,6 +181,9 @@ impl OptionsPopup { | |
AppOption::DiffInterhunkLines | ||
} | ||
AppOption::DiffInterhunkLines => { | ||
AppOption::HookTimeout | ||
} | ||
AppOption::HookTimeout => { | ||
AppOption::StatusShowUntracked | ||
} | ||
}; | ||
|
@@ -207,6 +229,14 @@ impl OptionsPopup { | |
.borrow_mut() | ||
.diff_hunk_lines_change(true); | ||
} | ||
AppOption::HookTimeout => { | ||
let current = | ||
self.options.borrow().hook_timeout(); | ||
let inc = Duration::from_secs(1); | ||
let new = current.map(|d| d + inc).or(Some(inc)); | ||
|
||
self.options.borrow_mut().set_hook_timeout(new); | ||
} | ||
} | ||
} else { | ||
match self.selection { | ||
|
@@ -246,6 +276,21 @@ impl OptionsPopup { | |
.borrow_mut() | ||
.diff_hunk_lines_change(false); | ||
} | ||
AppOption::HookTimeout => { | ||
let current = | ||
self.options.borrow().hook_timeout(); | ||
let dec = Duration::from_secs(1); | ||
|
||
let new = current.and_then(|d| { | ||
if d > dec { | ||
Some(d - dec) | ||
} else { | ||
None | ||
} | ||
}); | ||
|
||
self.options.borrow_mut().set_hook_timeout(new); | ||
} | ||
} | ||
} | ||
|
||
|
@@ -257,7 +302,7 @@ impl OptionsPopup { | |
impl DrawableComponent for OptionsPopup { | ||
fn draw(&self, f: &mut Frame, area: Rect) -> Result<()> { | ||
if self.is_visible() { | ||
const SIZE: (u16, u16) = (50, 10); | ||
const SIZE: (u16, u16) = (50, 12); | ||
let area = | ||
ui::centered_rect_absolute(SIZE.0, SIZE.1, area); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Docs are missing.
Probably the crate could use a
deny(missing_docs)
as well.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked at adding
deny(missing_docs)
to the crate but there are a number of errors that are outside the scope of this PR.