Merge pull request #1620 from Cimbali/master
Cache file names in fugitiveline extension
This commit is contained in:
commit
125d3443e4
@ -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': {},
|
||||||
\ },
|
\ },
|
||||||
@ -83,7 +85,7 @@ endif
|
|||||||
|
|
||||||
|
|
||||||
" Fugitive special revisions. call '0' "staging" ?
|
" Fugitive special revisions. call '0' "staging" ?
|
||||||
let s:names = {'0': 'index', '1': 'ancestor', '2':'target', '3':'merged'}
|
let s:names = {'0': 'index', '1': 'orig', '2':'fetch', '3':'merge'}
|
||||||
let s:sha1size = get(g:, 'airline#extensions#branch#sha1_len', 7)
|
let s:sha1size = get(g:, 'airline#extensions#branch#sha1_len', 7)
|
||||||
|
|
||||||
function! s:update_git_branch()
|
function! s:update_git_branch()
|
||||||
@ -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
|
||||||
|
|
||||||
|
@ -15,15 +15,21 @@ else
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
function! airline#extensions#fugitiveline#bufname()
|
function! airline#extensions#fugitiveline#bufname()
|
||||||
|
if exists('b:fugitive_name')
|
||||||
|
return b:fugitive_name
|
||||||
|
endif
|
||||||
|
|
||||||
|
let b:fugitive_name = fnamemodify(bufname('%'), s:fmod)
|
||||||
|
|
||||||
try
|
try
|
||||||
let buffer = fugitive#buffer()
|
let buffer = fugitive#buffer()
|
||||||
if buffer.type('blob')
|
if buffer.type('blob')
|
||||||
return fnamemodify(buffer.repo().translate(buffer.path()), s:fmod)
|
let b:fugitive_name = fnamemodify(buffer.repo().translate(buffer.path()), s:fmod)
|
||||||
endif
|
endif
|
||||||
catch
|
catch
|
||||||
endtry
|
endtry
|
||||||
|
|
||||||
return fnamemodify(bufname('%'), s:fmod)
|
return b:fugitive_name
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! airline#extensions#fugitiveline#init(ext)
|
function! airline#extensions#fugitiveline#init(ext)
|
||||||
@ -33,5 +39,7 @@ function! airline#extensions#fugitiveline#init(ext)
|
|||||||
else
|
else
|
||||||
call airline#parts#define_raw('file', '%<%{airline#extensions#fugitiveline#bufname()}%m')
|
call airline#parts#define_raw('file', '%<%{airline#extensions#fugitiveline#bufname()}%m')
|
||||||
endif
|
endif
|
||||||
|
autocmd ShellCmdPost,CmdwinLeave * unlet! b:fugitive_name
|
||||||
|
autocmd User AirlineBeforeRefresh unlet! b:fugitive_name
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user