Separate updating and displaying branch information
This will cause any calls that are not just head() to be delayed and cached whenever possible.
This commit is contained in:
parent
1ee057362d
commit
18da5aa699
@ -26,8 +26,9 @@ let s:vcs_config = {
|
|||||||
\ 'exe': 'git',
|
\ 'exe': 'git',
|
||||||
\ 'cmd': 'git status --porcelain -- ',
|
\ 'cmd': 'git status --porcelain -- ',
|
||||||
\ 'untracked_mark': '??',
|
\ 'untracked_mark': '??',
|
||||||
\ 'update_branch': 's:update_git_branch',
|
|
||||||
\ 'exclude': '\.git',
|
\ 'exclude': '\.git',
|
||||||
|
\ 'update_branch': 's:update_git_branch',
|
||||||
|
\ 'display_branch': 's:display_git_branch',
|
||||||
\ 'branch': '',
|
\ 'branch': '',
|
||||||
\ 'untracked': {},
|
\ 'untracked': {},
|
||||||
\ },
|
\ },
|
||||||
@ -37,6 +38,7 @@ let s:vcs_config = {
|
|||||||
\ 'untracked_mark': '?',
|
\ 'untracked_mark': '?',
|
||||||
\ 'exclude': '\.hg',
|
\ 'exclude': '\.hg',
|
||||||
\ 'update_branch': 's:update_hg_branch',
|
\ 'update_branch': 's:update_hg_branch',
|
||||||
|
\ 'display_branch': 's:display_hg_branch',
|
||||||
\ 'branch': '',
|
\ 'branch': '',
|
||||||
\ 'untracked': {},
|
\ 'untracked': {},
|
||||||
\ },
|
\ },
|
||||||
@ -92,8 +94,11 @@ function! s:update_git_branch()
|
|||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let name = fugitive#head(s:sha1size)
|
let s:vcs_config['git'].branch = fugitive#head(s:sha1size)
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:display_git_branch()
|
||||||
|
let name = b:buffer_vcs_config['git'].branch
|
||||||
try
|
try
|
||||||
let commit = fugitive#buffer().commit()
|
let commit = fugitive#buffer().commit()
|
||||||
|
|
||||||
@ -110,7 +115,7 @@ function! s:update_git_branch()
|
|||||||
catch
|
catch
|
||||||
endtry
|
endtry
|
||||||
|
|
||||||
let s:vcs_config['git'].branch = name
|
return name
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:update_hg_branch()
|
function! s:update_hg_branch()
|
||||||
@ -144,6 +149,10 @@ function! s:update_hg_branch()
|
|||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! s:display_hg_branch()
|
||||||
|
return b:buffer_vcs_config['mercurial'].branch
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! s:update_branch()
|
function! s:update_branch()
|
||||||
for vcs in keys(s:vcs_config)
|
for vcs in keys(s:vcs_config)
|
||||||
call {s:vcs_config[vcs].update_branch}()
|
call {s:vcs_config[vcs].update_branch}()
|
||||||
@ -216,18 +225,21 @@ function! airline#extensions#branch#head()
|
|||||||
let b:airline_head = ''
|
let b:airline_head = ''
|
||||||
let vcs_priority = get(g:, "airline#extensions#branch#vcs_priority", ["git", "mercurial"])
|
let vcs_priority = get(g:, "airline#extensions#branch#vcs_priority", ["git", "mercurial"])
|
||||||
|
|
||||||
let heads = {}
|
let heads = []
|
||||||
for vcs in vcs_priority
|
for vcs in vcs_priority
|
||||||
if !empty(b:buffer_vcs_config[vcs].branch)
|
if !empty(b:buffer_vcs_config[vcs].branch)
|
||||||
let heads[vcs] = b:buffer_vcs_config[vcs].branch
|
let heads += [vcs]
|
||||||
endif
|
endif
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
for vcs in keys(heads)
|
for vcs in heads
|
||||||
if !empty(b:airline_head)
|
if !empty(b:airline_head)
|
||||||
let b:airline_head .= ' | '
|
let b:airline_head .= ' | '
|
||||||
endif
|
endif
|
||||||
let b:airline_head .= (len(heads) > 1 ? s:vcs_config[vcs].exe .':' : '') . s:format_name(heads[vcs])
|
if len(heads) > 1
|
||||||
|
let b:airline_head .= s:vcs_config[vcs].exe .':'
|
||||||
|
endif
|
||||||
|
let b:airline_head .= s:format_name({s:vcs_config[vcs].display_branch}())
|
||||||
let b:airline_head .= b:buffer_vcs_config[vcs].untracked
|
let b:airline_head .= b:buffer_vcs_config[vcs].untracked
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user