mirror of
https://github.com/airblade/vim-gitgutter.git
synced 2025-11-08 11:33:48 -05:00
Cache the fact that a file is known to git.
This allows us to avoid checking whether a file known to git is known to git every time we run a diff.
This commit is contained in:
@@ -4,8 +4,14 @@ let s:hunk_re = '^@@ -\(\d\+\),\?\(\d*\) +\(\d\+\),\?\(\d*\) @@'
|
||||
|
||||
|
||||
function! gitgutter#diff#run_diff(realtime, use_external_grep, lines_of_context)
|
||||
" Wrap compound command in parentheses to make Windows happy.
|
||||
let cmd = '(git ls-files --error-unmatch '.gitgutter#utility#shellescape(gitgutter#utility#filename()).' && ('
|
||||
" Wrap compound commands in parentheses to make Windows happy.
|
||||
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()).' && ('
|
||||
endif
|
||||
|
||||
if a:realtime
|
||||
let blob_name = ':'.gitgutter#utility#shellescape(gitgutter#utility#file_relative_to_repo_root())
|
||||
@@ -32,7 +38,11 @@ function! gitgutter#diff#run_diff(realtime, use_external_grep, lines_of_context)
|
||||
let cmd.= ' || exit 0'
|
||||
endif
|
||||
|
||||
let cmd .= '))'
|
||||
let cmd .= ')'
|
||||
|
||||
if !tracked
|
||||
let cmd .= ')'
|
||||
endif
|
||||
|
||||
if a:realtime
|
||||
let diff = gitgutter#utility#system(gitgutter#utility#command_in_directory_of_file(cmd), gitgutter#utility#buffer_contents())
|
||||
@@ -41,11 +51,14 @@ function! gitgutter#diff#run_diff(realtime, use_external_grep, lines_of_context)
|
||||
endif
|
||||
|
||||
if gitgutter#utility#shell_error()
|
||||
" A shell error indicates the file is not tracked by git (unless something
|
||||
" bizarre is going on).
|
||||
" A shell error indicates the file is not tracked by git (unless something bizarre is going on).
|
||||
throw 'diff failed'
|
||||
endif
|
||||
|
||||
if !tracked
|
||||
call setbufvar(bufnr, 'gitgutter_tracked', 1)
|
||||
endif
|
||||
|
||||
return diff
|
||||
endfunction
|
||||
|
||||
|
||||
Reference in New Issue
Block a user