From e0dd3d81258eb38204aea48a71af4a18dac6aa30 Mon Sep 17 00:00:00 2001 From: Cimbali Date: Sat, 23 Dec 2017 15:05:59 +0100 Subject: [PATCH 1/3] Rename merge file names Clearer names that reference the HEADs of git: FETCH_HEAD, ORIG_HEAD and MERGE_HEAD, rather than the names that fugitive uses for them. --- autoload/airline/extensions/branch.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload/airline/extensions/branch.vim b/autoload/airline/extensions/branch.vim index b85c155f..9a961972 100644 --- a/autoload/airline/extensions/branch.vim +++ b/autoload/airline/extensions/branch.vim @@ -83,7 +83,7 @@ endif " 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) function! s:update_git_branch() From 1ee057362dde1ff93d7f36ea8bc6dc71ccb448e4 Mon Sep 17 00:00:00 2001 From: Cimbali Date: Sat, 23 Dec 2017 15:18:39 +0100 Subject: [PATCH 2/3] Caching path simplified using fugitive --- autoload/airline/extensions/fugitiveline.vim | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/autoload/airline/extensions/fugitiveline.vim b/autoload/airline/extensions/fugitiveline.vim index e2fcad72..831f9310 100644 --- a/autoload/airline/extensions/fugitiveline.vim +++ b/autoload/airline/extensions/fugitiveline.vim @@ -15,15 +15,21 @@ else endif function! airline#extensions#fugitiveline#bufname() + if exists('b:fugitive_name') + return b:fugitive_name + endif + + let b:fugitive_name = fnamemodify(bufname('%'), s:fmod) + try let buffer = fugitive#buffer() 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 catch endtry - return fnamemodify(bufname('%'), s:fmod) + return b:fugitive_name endfunction function! airline#extensions#fugitiveline#init(ext) @@ -33,5 +39,7 @@ function! airline#extensions#fugitiveline#init(ext) else call airline#parts#define_raw('file', '%<%{airline#extensions#fugitiveline#bufname()}%m') endif + autocmd ShellCmdPost,CmdwinLeave * unlet! b:fugitive_name + autocmd User AirlineBeforeRefresh unlet! b:fugitive_name endfunction From 18da5aa699526d14e3a2e0678a513be8a6a97aa6 Mon Sep 17 00:00:00 2001 From: Cimbali Date: Tue, 26 Dec 2017 13:10:41 +0100 Subject: [PATCH 3/3] Separate updating and displaying branch information This will cause any calls that are not just head() to be delayed and cached whenever possible. --- autoload/airline/extensions/branch.vim | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/autoload/airline/extensions/branch.vim b/autoload/airline/extensions/branch.vim index 9a961972..25ebe0aa 100644 --- a/autoload/airline/extensions/branch.vim +++ b/autoload/airline/extensions/branch.vim @@ -26,8 +26,9 @@ let s:vcs_config = { \ 'exe': 'git', \ 'cmd': 'git status --porcelain -- ', \ 'untracked_mark': '??', -\ 'update_branch': 's:update_git_branch', \ 'exclude': '\.git', +\ 'update_branch': 's:update_git_branch', +\ 'display_branch': 's:display_git_branch', \ 'branch': '', \ 'untracked': {}, \ }, @@ -37,6 +38,7 @@ let s:vcs_config = { \ 'untracked_mark': '?', \ 'exclude': '\.hg', \ 'update_branch': 's:update_hg_branch', +\ 'display_branch': 's:display_hg_branch', \ 'branch': '', \ 'untracked': {}, \ }, @@ -92,8 +94,11 @@ function! s:update_git_branch() return 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 let commit = fugitive#buffer().commit() @@ -110,7 +115,7 @@ function! s:update_git_branch() catch endtry - let s:vcs_config['git'].branch = name + return name endfunction function! s:update_hg_branch() @@ -144,6 +149,10 @@ function! s:update_hg_branch() endif endfunction +function! s:display_hg_branch() + return b:buffer_vcs_config['mercurial'].branch +endfunction + function! s:update_branch() for vcs in keys(s:vcs_config) call {s:vcs_config[vcs].update_branch}() @@ -216,18 +225,21 @@ function! airline#extensions#branch#head() let b:airline_head = '' let vcs_priority = get(g:, "airline#extensions#branch#vcs_priority", ["git", "mercurial"]) - let heads = {} + let heads = [] for vcs in vcs_priority if !empty(b:buffer_vcs_config[vcs].branch) - let heads[vcs] = b:buffer_vcs_config[vcs].branch + let heads += [vcs] endif endfor - for vcs in keys(heads) + for vcs in heads if !empty(b:airline_head) let b:airline_head .= ' | ' 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 endfor