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

@@ -6,7 +6,7 @@ let s:hunk_re = '^@@ -\(\d\+\),\?\(\d*\) +\(\d\+\),\?\(\d*\) @@'
" True for git v1.7.2+.
function! s:git_supports_command_line_config_override() abort
call gitgutter#utility#system(g:gitgutter_git_executable.' '.g:gitgutter_git_args.' -c foo.bar=baz --version')
call gitgutter#utility#system(gitgutter#git().' -c foo.bar=baz --version')
return !v:shell_error
endfunction
@@ -87,7 +87,7 @@ function! gitgutter#diff#run_diff(bufnr, from, preserve_full_diff) abort
" doesn't work for this case.
if !empty(g:gitgutter_diff_base)
let index_name = gitgutter#utility#get_diff_base(a:bufnr).':'.gitgutter#utility#repo_path(a:bufnr, 1)
let cmd = g:gitgutter_git_executable.' '.g:gitgutter_git_args.' --no-pager show '.index_name
let cmd = gitgutter#git().' --no-pager show '.index_name
let cmd = gitgutter#utility#cd_cmd(a:bufnr, cmd)
call gitgutter#utility#system(cmd)
if v:shell_error
@@ -138,14 +138,14 @@ function! gitgutter#diff#run_diff(bufnr, from, preserve_full_diff) abort
" Write file from index to temporary file.
let index_name = gitgutter#utility#get_diff_base(a:bufnr).':'.gitgutter#utility#repo_path(a:bufnr, 1)
let cmd .= g:gitgutter_git_executable.' '.g:gitgutter_git_args.' --no-pager show --textconv '.index_name.' > '.from_file.' && '
let cmd .= gitgutter#git().' --no-pager show --textconv '.index_name.' > '.from_file.' && '
elseif a:from ==# 'working_tree'
let from_file = gitgutter#utility#repo_path(a:bufnr, 1)
endif
" Call git-diff.
let cmd .= g:gitgutter_git_executable.' '.g:gitgutter_git_args.' --no-pager'
let cmd .= gitgutter#git().' --no-pager'
if s:c_flag
let cmd .= ' -c "diff.autorefreshindex=0"'
let cmd .= ' -c "diff.noprefix=false"'

View File

@@ -302,8 +302,7 @@ function! s:stage(hunk_diff)
let path = gitgutter#utility#repo_path(bufnr, 1)
" Add file to index.
let cmd = gitgutter#utility#cd_cmd(bufnr,
\ g:gitgutter_git_executable.' '.g:gitgutter_git_args.
\ ' add '.
\ gitgutter#git().' add '.
\ gitgutter#utility#shellescape(gitgutter#utility#filename(bufnr)))
call gitgutter#utility#system(cmd)
else
@@ -314,7 +313,7 @@ function! s:stage(hunk_diff)
let diff = s:adjust_header(bufnr, a:hunk_diff)
" Apply patch to index.
call gitgutter#utility#system(
\ gitgutter#utility#cd_cmd(bufnr, g:gitgutter_git_executable.' '.g:gitgutter_git_args.' apply --cached --unidiff-zero - '),
\ gitgutter#utility#cd_cmd(bufnr, gitgutter#git().' apply --cached --unidiff-zero - '),
\ diff)
endif

View File

@@ -150,8 +150,7 @@ function! gitgutter#utility#set_repo_path(bufnr, continuation) abort
call gitgutter#utility#setbufvar(a:bufnr, 'path', -1)
let cmd = gitgutter#utility#cd_cmd(a:bufnr,
\ g:gitgutter_git_executable.' '.g:gitgutter_git_args.
\ ' ls-files -v --error-unmatch --full-name -z -- '.
\ gitgutter#git().' ls-files -v --error-unmatch --full-name -z -- '.
\ gitgutter#utility#shellescape(gitgutter#utility#filename(a:bufnr)))
if g:gitgutter_async && gitgutter#async#available() && !has('vim_starting')
@@ -182,8 +181,7 @@ function! gitgutter#utility#clean_smudge_filter_applies(bufnr)
let filtered = gitgutter#utility#getbufvar(a:bufnr, 'filter', -1)
if filtered == -1
let cmd = gitgutter#utility#cd_cmd(a:bufnr,
\ g:gitgutter_git_executable.' '.g:gitgutter_git_args.
\ ' check-attr filter -- '.
\ gitgutter#git().' check-attr filter -- '.
\ gitgutter#utility#shellescape(gitgutter#utility#filename(a:bufnr)))
let out = gitgutter#utility#system(cmd)
let filtered = out !~ 'unspecified'