diff --git a/autoload/airline/extensions/branch.vim b/autoload/airline/extensions/branch.vim index e747ca61..88d8fe33 100644 --- a/autoload/airline/extensions/branch.vim +++ b/autoload/airline/extensions/branch.vim @@ -30,69 +30,85 @@ endif let s:git_dirs = {} function! s:get_git_branch(path) - if has_key(s:git_dirs, a:path) - return s:git_dirs[a:path] + if !s:has_fugitive + return '' endif - let dir = fugitive#extract_git_dir(a:path) - if empty(dir) - let name = '' - else - try - let line = join(readfile(dir . '/HEAD')) - if strpart(line, 0, 16) == 'ref: refs/heads/' - let name = strpart(line, 16) - else - " raw commit hash - let name = strpart(line, 0, 7) - endif - catch + let name = fugitive#head(7) + if empty(name) + if has_key(s:git_dirs, a:path) + return s:git_dirs[a:path] + endif + + let dir = fugitive#extract_git_dir(a:path) + if empty(dir) let name = '' - endtry + else + try + let line = join(readfile(dir . '/HEAD')) + if strpart(line, 0, 16) == 'ref: refs/heads/' + let name = strpart(line, 16) + else + " raw commit hash + let name = strpart(line, 0, 7) + endif + catch + let name = '' + endtry + endif endif let s:git_dirs[a:path] = name return name endfunction +function! s:get_hg_branch() + if s:has_lawrencium + return lawrencium#statusline() + endif + return '' +endfunction + function! airline#extensions#branch#head() if exists('b:airline_head') && !empty(b:airline_head) return b:airline_head endif let b:airline_head = '' + let l:heads = {} + let l:vcs_priority = get(g:, "airline#extensions#branch#vcs_priority", ["git", "mercurial"]) let found_fugitive_head = 0 - if s:has_fugitive && !exists('b:mercurial_dir') - let b:airline_head = fugitive#head(7) + let l:git_head = s:get_git_branch(expand("%:p:h")) + let l:hg_head = s:get_hg_branch() + + if !empty(l:git_head) let found_fugitive_head = 1 - - if empty(b:airline_head) && !exists('b:git_dir') - let b:airline_head = s:get_git_branch(expand("%:p:h")) - endif + let l:heads.git = (!empty(l:hg_head) ? "git:" : '') . s:format_name(l:git_head) endif - if empty(b:airline_head) - if s:has_lawrencium - let b:airline_head = lawrencium#statusline() - endif + if !empty(l:hg_head) + let l:heads.mercurial = (!empty(l:git_head) ? "hg:" : '') . s:format_name(l:hg_head) endif - if empty(b:airline_head) + if empty(l:heads) if s:has_vcscommand call VCSCommandEnableBufferSetup() if exists('b:VCSCommandBufferInfo') - let b:airline_head = get(b:VCSCommandBufferInfo, 0, '') + let b:airline_head = s:format_name(get(b:VCSCommandBufferInfo, 0, '')) endif endif + else + for vcs in l:vcs_priority + if has_key(l:heads, vcs) + if !empty(b:airline_head) + let b:airline_head = b:airline_head . " | " + endif + let b:airline_head = b:airline_head . l:heads[vcs] + endif + endfor endif - if empty(b:airline_head) || !found_fugitive_head && !s:check_in_path() - let b:airline_head = '' - endif - - let b:airline_head = s:format_name(b:airline_head) - if exists("g:airline#extensions#branch#displayed_head_limit") let w:displayed_head_limit = g:airline#extensions#branch#displayed_head_limit if len(b:airline_head) > w:displayed_head_limit - 1 @@ -100,6 +116,9 @@ function! airline#extensions#branch#head() endif endif + if empty(b:airline_head) || !found_fugitive_head && !s:check_in_path() + let b:airline_head = '' + endif return b:airline_head endfunction diff --git a/doc/airline.txt b/doc/airline.txt index 5f5f5cbf..63f27969 100644 --- a/doc/airline.txt +++ b/doc/airline.txt @@ -317,6 +317,10 @@ vcscommand * change the text for when no branch is detected > let g:airline#extensions#branch#empty_message = '' < +* define the order in which the branches of different vcs systems will be + displayed on the statusline (currently only for fugitive and lawrencium) > + let g:airline#extensions#branch#vcs_priority = ["git", "mercurial"] +< * use vcscommand.vim if available > let g:airline#extensions#branch#use_vcscommand = 0 <