Skip to content

Commit 67e0e26

Browse files
Erwin Jansenakinomyoga
andcommitted
lib/omb-prompt-base: Set a timeout on the git command
The calculate of git_summary_status can be extremely expensive for large repos. This results in the shell becoming unresponsive. We now set a timeout of 0.2 seconds to make sure we always have a responsive shell. * lib/omb-prompt-base: Set a timeout on git commands * lib/omb-prompt-base: Fix timeout bug * lib/omb-prompt-base: Rename function "{run_with => _omb_prompt}_timeout" * lib/omb-prompt-base(_omb_prompt_timeout): Fix coding style * lib/omb-prompt-base(_omb_prompt_timeout): Check timeout commands on startup Fixes #172 Co-authored-by: Koichi Murase <[email protected]>
1 parent 07d9382 commit 67e0e26

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

lib/omb-prompt-base.sh

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ SCM_GIT_BEHIND_CHAR="↓"
4343
SCM_GIT_UNTRACKED_CHAR="?:"
4444
SCM_GIT_UNSTAGED_CHAR="U:"
4545
SCM_GIT_STAGED_CHAR="S:"
46+
SCM_GIT_TIMEOUT="0.2"
4647

4748
SCM_HG='hg'
4849
SCM_HG_CHAR=''
@@ -105,9 +106,27 @@ function _omb_prompt_format {
105106
}
106107

107108
function _omb_prompt_git {
108-
command git "$@"
109+
_omb_prompt_timeout "$SCM_GIT_TIMEOUT" command git "$@"
109110
}
110111

112+
## @fn _omb_prompt_timeout
113+
## Runs the given command with the given timeout
114+
## @param $1 Timeout in seconds
115+
## @param $@ Command to be executed.
116+
if _omb_util_command_exists timeout; then
117+
function _omb_prompt_timeout {
118+
timeout "$@"
119+
}
120+
elif _omb_util_command_exists gtimeout; then
121+
function _omb_prompt_timeout {
122+
gtimeout "$@"
123+
}
124+
else
125+
function _omb_prompt_timeout {
126+
"${@:2}"
127+
}
128+
fi
129+
111130
function scm {
112131
if [[ "$SCM_CHECK" = false ]]; then SCM=$SCM_NONE
113132
elif [[ -f .git/HEAD ]]; then SCM=$SCM_GIT

0 commit comments

Comments
 (0)