Save branch head to a buffer variable

Save branch head to a buffer-local variable to prevent looking up the VCS head for every status line refresh.
This commit is contained in:
Russell Hancox 2014-03-24 14:01:31 -04:00
parent 5a2daf6dfb
commit 25059d43b1
1 changed files with 17 additions and 12 deletions

View File

@ -11,35 +11,41 @@ if !s:has_fugitive && !s:has_lawrencium && !s:has_vcscommand
endif endif
function! airline#extensions#branch#head() function! airline#extensions#branch#head()
let head = '' if exists('b:airline_head')
return b:airline_head
endif
let b:airline_head = ''
if s:has_fugitive && !exists('b:mercurial_dir') if s:has_fugitive && !exists('b:mercurial_dir')
let head = fugitive#head() let b:airline_head = fugitive#head()
if empty(head) && s:has_fugitive_detect && !exists('b:git_dir') if empty(b:airline_head) && s:has_fugitive_detect && !exists('b:git_dir')
call fugitive#detect(getcwd()) call fugitive#detect(getcwd())
let head = fugitive#head() let b:airline_head = fugitive#head()
endif endif
endif endif
if empty(head) if empty(b:airline_head)
if s:has_lawrencium if s:has_lawrencium
let head = lawrencium#statusline() let b:airline_head = lawrencium#statusline()
endif endif
endif endif
if empty(head) if empty(b:airline_head)
if s:has_vcscommand if s:has_vcscommand
call VCSCommandEnableBufferSetup() call VCSCommandEnableBufferSetup()
if exists('b:VCSCommandBufferInfo') if exists('b:VCSCommandBufferInfo')
let head = get(b:VCSCommandBufferInfo, 0, '') let b:airline_head = get(b:VCSCommandBufferInfo, 0, '')
endif endif
endif endif
endif endif
return empty(head) || !s:check_in_path() if empty(b:airline_head) || !s:check_in_path()
\ ? '' let b:airline_head = ''
\ : head endif
return b:airline_head
endfunction endfunction
function! airline#extensions#branch#get_head() function! airline#extensions#branch#get_head()
@ -79,4 +85,3 @@ function! airline#extensions#branch#init(ext)
autocmd BufReadPost * unlet! b:airline_file_in_root autocmd BufReadPost * unlet! b:airline_file_in_root
endfunction endfunction