Add support for option g:gitgutter_grep_command

With this change, setting `g:gitgutter_grep_command` to ' | grep --color=never -e "^@@ "'`
greatly reduces startup time.

Before this change, `diff.vim` was a major bottleneck because it calls
`grep --help`. This is mostly unnecessary except in a few cases where
the user is running a nonstandard version of grep.

`vim --startuptime start.out large_file.sql` before:

    times in msec
     clock   self+sourced   self:  sourced script
     clock   elapsed:              other lines

    000.026  000.026: --- VIM STARTING ---
    [...]
    068.463  003.645  003.500: sourcing /home/dchurch/.vim/plugin/gitgutter.vim
    [...]
    150.957  000.208  000.208: sourcing /home/dchurch/.vim/autoload/gitgutter.vim
    151.294  000.196  000.196: sourcing /home/dchurch/.vim/autoload/gitgutter/utility.vim
    165.059  012.619  012.619: sourcing /home/dchurch/.vim/autoload/gitgutter/diff.vim
    236.901  000.188  000.188: sourcing /home/dchurch/.vim/autoload/gitgutter/hunk.vim
    237.289  000.233  000.233: sourcing /home/dchurch/.vim/autoload/gitgutter/sign.vim
    [...]
    337.673  000.004: --- VIM STARTED ---

After change, and setting `g:gitgutter_grep_command = ' | grep --color=never -e "^@@ "'`:

    000.026  000.026: --- VIM STARTING ---
    [...]
    064.873  002.713  002.591: sourcing /home/dchurch/.vim/plugin/gitgutter.vim
    [...]
    134.109  000.149  000.149: sourcing /home/dchurch/.vim/autoload/gitgutter.vim
    134.337  000.147  000.147: sourcing /home/dchurch/.vim/autoload/gitgutter/utility.vim
    135.411  000.232  000.232: sourcing /home/dchurch/.vim/autoload/gitgutter/diff.vim
    187.831  000.180  000.180: sourcing /home/dchurch/.vim/autoload/gitgutter/hunk.vim
    188.223  000.175  000.175: sourcing /home/dchurch/.vim/autoload/gitgutter/sign.vim
    [...]
    285.008  000.004: --- VIM STARTED ---
This commit is contained in:
Dan Church
2016-01-11 10:47:40 -06:00
committed by Andy Stewart
parent 4510e9b335
commit 95734c6f6b
3 changed files with 26 additions and 7 deletions

View File

@@ -271,6 +271,14 @@ If you have `grep` aliased to something which changes its output, for example `g
let g:gitgutter_escape_grep = 1
```
#### Use a custom `grep` command
If you use an alternative to grep, you can tell vim-gitgutter to use it here.
```viml
let g:gitgutter_grep_command = ' | grep --color=never -e "^@@"'
```
#### To turn off vim-gitgutter by default
Add `let g:gitgutter_enabled = 0` to your `~/.vimrc`.

View File

@@ -1,11 +1,16 @@
let s:grep_available = executable('grep')
if s:grep_available
let s:grep_command = ' | '.(g:gitgutter_escape_grep ? '\grep' : 'grep')
let s:grep_help = gitgutter#utility#system('grep --help')
if s:grep_help =~# '--color'
let s:grep_command .= ' --color=never'
if exists('g:gitgutter_grep_command')
let s:grep_available = 1
let s:grep_command = g:gitgutter_grep_command
else
let s:grep_available = executable('grep')
if s:grep_available
let s:grep_command = ' | '.(g:gitgutter_escape_grep ? '\grep' : 'grep')
let s:grep_help = gitgutter#utility#system('grep --help')
if s:grep_help =~# '--color'
let s:grep_command .= ' --color=never'
endif
let s:grep_command .= ' -e '.gitgutter#utility#shellescape('^@@ ')
endif
let s:grep_command .= ' -e '.gitgutter#utility#shellescape('^@@ ')
endif
let s:hunk_re = '^@@ -\(\d\+\),\?\(\d*\) +\(\d\+\),\?\(\d*\) @@'

View File

@@ -119,6 +119,7 @@ You can customise:
- Line highlights
- Extra arguments for git-diff
- Key mappings
- The grep executable used
- Whether or not to escape grep (defaults to no)
- Whether or not vim-gitgutter is on initially (defaults to on)
- Whether or not signs are shown (defaults to yes)
@@ -214,6 +215,11 @@ To change the hunk-staging/reverting/previewing maps (defaults shown):
TO ESCAPE GREP
To use a custom invocation for grep, use this:
>
let g:gitgutter_grep_command = ' | grep --color=never -e "^@@ "'
<
To avoid any alias you have for grep, use this:
>
let g:gitgutter_escape_grep = 1