Skip to content

Commit

Permalink
Push diff filtering down to shell.
Browse files Browse the repository at this point in the history
This should make things a little more efficient on the basis of
minimising the amount of data flowing up.
  • Loading branch information
airblade committed Feb 22, 2013
1 parent 4bd9640 commit 79fa8ca
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions plugin/gitgutter.vim
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ endfunction
" Diff processing {{{

function! s:run_diff()
let cmd = 'git diff --no-ext-diff -U0 ' . shellescape(s:current_file())
let cmd = 'git diff --no-ext-diff -U0 ' . shellescape(s:current_file()) .
\ ' | grep -e "^@@ "'
let diff = system(s:command_in_directory_of_current_file(cmd))
return diff
endfunction
Expand All @@ -77,14 +78,12 @@ function! s:parse_diff(diff)
let hunk_re = '^@@ -\(\d\+\),\?\(\d*\) +\(\d\+\),\?\(\d*\) @@'
let hunks = []
for line in split(a:diff, '\n')
if line =~ '^@@\s'
let matches = matchlist(line, hunk_re)
let from_line = str2nr(matches[1])
let from_count = (matches[2] == '') ? 1 : str2nr(matches[2])
let to_line = str2nr(matches[3])
let to_count = (matches[4] == '') ? 1 : str2nr(matches[4])
call add(hunks, [from_line, from_count, to_line, to_count])
endif
let matches = matchlist(line, hunk_re)
let from_line = str2nr(matches[1])
let from_count = (matches[2] == '') ? 1 : str2nr(matches[2])
let to_line = str2nr(matches[3])
let to_count = (matches[4] == '') ? 1 : str2nr(matches[4])
call add(hunks, [from_line, from_count, to_line, to_count])
endfor
return hunks
endfunction
Expand Down

0 comments on commit 79fa8ca

Please sign in to comment.