Extract function to reduce duplication

This commit is contained in:
Andy Stewart
2023-06-05 09:50:17 +01:00
parent 3531f4eddd
commit 6ebc0fd233
4 changed files with 17 additions and 14 deletions

View File

@@ -119,6 +119,12 @@ endfunction
" }}}
function! gitgutter#git()
return g:gitgutter_git_executable.' '.g:gitgutter_git_args
endfunction
function! gitgutter#setup_maps()
if !g:gitgutter_map_keys
return
@@ -195,14 +201,14 @@ endfunction
" - it ignores unsaved changes in buffers
" - it does not change to the repo root
function! gitgutter#quickfix(current_file)
let cmd = g:gitgutter_git_executable.' '.g:gitgutter_git_args.' rev-parse --show-cdup'
let cmd = gitgutter#git().' rev-parse --show-cdup'
let path_to_repo = get(systemlist(cmd), 0, '')
if !empty(path_to_repo) && path_to_repo[-1:] != '/'
let path_to_repo .= '/'
endif
let locations = []
let cmd = g:gitgutter_git_executable.' '.g:gitgutter_git_args.' --no-pager'.
let cmd = gitgutter#git().' --no-pager'.
\ ' diff --no-ext-diff --no-color -U0'.
\ ' --src-prefix=a/'.path_to_repo.' --dst-prefix=b/'.path_to_repo.' '.
\ g:gitgutter_diff_args. ' '. g:gitgutter_diff_base
@@ -251,7 +257,7 @@ function! gitgutter#difforig()
if g:gitgutter_diff_relative_to ==# 'index'
let index_name = gitgutter#utility#get_diff_base(bufnr).':'.path
let cmd = gitgutter#utility#cd_cmd(bufnr,
\ g:gitgutter_git_executable.' '.g:gitgutter_git_args.' --no-pager show '.index_name
\ gitgutter#git().' --no-pager show '.index_name
\ )
" NOTE: this uses &shell to execute cmd. Perhaps we should use instead
" gitgutter#utility's use_known_shell() / restore_shell() functions.