Always use bash on unix.

Vim is single-threaded so we can make life easier by using a known shell
and restoring the original one afterwards.
This commit is contained in:
Andy Stewart
2016-05-16 12:00:06 +01:00
parent 1937f06498
commit ba6e104848
3 changed files with 30 additions and 18 deletions

View File

@@ -14,6 +14,8 @@ endfunction
" bufnr: (integer) the buffer to process.
" realtime: (boolean) when truthy, do a realtime diff; otherwise do a disk-based diff.
function! gitgutter#process_buffer(bufnr, realtime) abort
call gitgutter#utility#use_known_shell()
call gitgutter#utility#set_buffer(a:bufnr)
if gitgutter#utility#is_active()
if g:gitgutter_sign_column_always
@@ -34,6 +36,8 @@ function! gitgutter#process_buffer(bufnr, realtime) abort
else
call gitgutter#hunk#reset()
endif
call gitgutter#utility#restore_shell()
endfunction

View File

@@ -9,8 +9,6 @@ else
endif
let s:hunk_re = '^@@ -\(\d\+\),\?\(\d*\) +\(\d\+\),\?\(\d*\) @@'
let s:fish = &shell =~# 'fish'
let s:c_flag = gitgutter#utility#git_supports_command_line_config_override()
let s:temp_index = tempname()
@@ -54,14 +52,13 @@ let s:temp_buffer = tempname()
" does the filtering instead.
function! gitgutter#diff#run_diff(realtime, preserve_full_diff) abort
" Wrap compound commands in parentheses to make Windows happy.
" bash doesn't mind the parentheses; fish doesn't want them.
let cmd = s:fish ? '' : '('
" bash doesn't mind the parentheses.
let cmd = '('
let bufnr = gitgutter#utility#bufnr()
let tracked = getbufvar(bufnr, 'gitgutter_tracked') " i.e. tracked by git
if !tracked
let cmd .= 'git ls-files --error-unmatch '.gitgutter#utility#shellescape(gitgutter#utility#filename())
let cmd .= s:fish ? '; and ' : ' && ('
let cmd .= 'git ls-files --error-unmatch '.gitgutter#utility#shellescape(gitgutter#utility#filename()).' && ('
endif
if a:realtime
@@ -73,8 +70,7 @@ function! gitgutter#diff#run_diff(realtime, preserve_full_diff) abort
let blob_file .= '.'.extension
let buff_file .= '.'.extension
endif
let cmd .= 'git show '.blob_name.' > '.blob_file
let cmd .= s:fish ? '; and ' : ' && '
let cmd .= 'git show '.blob_name.' > '.blob_file.' && '
" Writing the whole buffer resets the '[ and '] marks and also the
" 'modified' flag (if &cpoptions includes '+'). These are unwanted
@@ -111,17 +107,14 @@ function! gitgutter#diff#run_diff(realtime, preserve_full_diff) abort
" differences are found. However we want to treat non-matches and
" differences as non-erroneous behaviour; so we OR the command with one
" which always exits with success (0).
let cmd .= s:fish ? '; or ' : ' || '
let cmd .= 'exit 0'
let cmd .= ' || exit 0'
endif
if !s:fish
let cmd .= ')'
if !tracked
let cmd .= ')'
endif
end
let cmd = gitgutter#utility#command_in_directory_of_file(cmd)

View File

@@ -1,7 +1,6 @@
let s:file = ''
let s:using_xolox_shell = -1
let s:exit_code = 0
let s:fish = &shell =~# 'fish'
function! gitgutter#utility#warn(message) abort
echohl WarningMsg
@@ -148,7 +147,7 @@ function! gitgutter#utility#file_relative_to_repo_root() abort
endfunction
function! gitgutter#utility#command_in_directory_of_file(cmd) abort
return 'cd '.gitgutter#utility#shellescape(gitgutter#utility#directory_of_file()) . (s:fish ? '; and ' : ' && ') . a:cmd
return 'cd '.gitgutter#utility#shellescape(gitgutter#utility#directory_of_file()).' && '.a:cmd
endfunction
function! gitgutter#utility#highlight_name_for_change(text) abort
@@ -182,3 +181,19 @@ endfunction
function! gitgutter#utility#stringify(list) abort
return join(a:list, "\n")."\n"
endfunction
function! gitgutter#utility#use_known_shell() abort
if has('unix')
let s:shell = &shell
let s:shellcmdflag = &shellcmdflag
set shell=/bin/bash
set shellcmdflag=-c
endif
endfunction
function! gitgutter#utility#restore_shell() abort
if has('unix')
let &shell = s:shell
let &shellcmdflag = s:shellcmdflag
endif
endfunction