Make realtime diff use git-diff.

The only reason the realtime diff used `diff` instead of `git-diff`
previously was that I couldn't figure out how to do it in a way that
worked on Windows as well as Unix.
This commit is contained in:
Andy Stewart
2014-11-11 10:14:38 +01:00
parent 39f0119096
commit b0e9efa11c

View File

@@ -1,19 +1,23 @@
let s:grep_available = executable('grep') let s:grep_available = executable('grep')
let s:grep_command = ' | ' . (g:gitgutter_escape_grep ? '\grep' : 'grep') . ' -e ' . gitgutter#utility#shellescape('^@@ ') let s:grep_command = ' | '.(g:gitgutter_escape_grep ? '\grep' : 'grep').' -e '.gitgutter#utility#shellescape('^@@ ')
let s:hunk_re = '^@@ -\(\d\+\),\?\(\d*\) +\(\d\+\),\?\(\d*\) @@' let s:hunk_re = '^@@ -\(\d\+\),\?\(\d*\) +\(\d\+\),\?\(\d*\) @@'
function! gitgutter#diff#run_diff(realtime, use_external_grep, lines_of_context) function! gitgutter#diff#run_diff(realtime, use_external_grep, lines_of_context)
" Wrap compound command in parentheses to make Windows happy. " Wrap compound command in parentheses to make Windows happy.
let cmd = '(git ls-files --error-unmatch ' . gitgutter#utility#shellescape(gitgutter#utility#filename()) . ' && (' let cmd = '(git ls-files --error-unmatch '.gitgutter#utility#shellescape(gitgutter#utility#filename()).' && ('
if a:realtime if a:realtime
let blob_name = ':' . gitgutter#utility#shellescape(gitgutter#utility#file_relative_to_repo_root()) let blob_name = ':'.gitgutter#utility#shellescape(gitgutter#utility#file_relative_to_repo_root())
let blob_file = tempname() let blob_file = tempname()
let cmd .= 'git show ' . blob_name . ' > ' . blob_file . let cmd .= 'git show '.blob_name.' > '.blob_file.' && '
\ ' && diff -U'.a:lines_of_context.' ' . g:gitgutter_diff_args . ' ' . blob_file . ' - ' endif
let cmd .= 'git diff --no-ext-diff --no-color -U'.a:lines_of_context.' '.g:gitgutter_diff_args.' '
if a:realtime
let cmd .= '-- '.blob_file.' - '
else else
let cmd .= 'git diff --no-ext-diff --no-color -U'.a:lines_of_context.' ' . g:gitgutter_diff_args . ' ' . gitgutter#utility#shellescape(gitgutter#utility#filename()) let cmd .= gitgutter#utility#shellescape(gitgutter#utility#filename())
endif endif
if a:use_external_grep && s:grep_available if a:use_external_grep && s:grep_available