mirror of
https://github.com/airblade/vim-gitgutter.git
synced 2025-11-08 11:33:48 -05:00
Extract function to reduce duplication
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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"'
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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'
|
||||
|
||||
Reference in New Issue
Block a user