Merge pull request #2337 from vim-airline/Functionalization_of_branch_extension

[refactor] Functionalization of branch extension
This commit is contained in:
Christian Brabandt 2021-02-15 16:12:20 +01:00 committed by GitHub
commit cb1bc19064
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 27 additions and 20 deletions

View File

@ -86,29 +86,36 @@ let s:sha1size = get(g:, 'airline#extensions#branch#sha1_len', 7)
function! s:update_git_branch()
call airline#util#ignore_next_focusgain()
if !airline#util#has_fugitive() && !airline#util#has_gina()
if airline#util#has_fugitive()
call s:config_fugitive_branch()
elseif airline#util#has_gina()
call s:config_gina_branch()
else
let s:vcs_config['git'].branch = ''
return
endif
if airline#util#has_fugitive()
let s:vcs_config['git'].branch = exists("*FugitiveHead") ?
\ FugitiveHead(s:sha1size) : fugitive#head(s:sha1size)
if s:vcs_config['git'].branch is# 'master' &&
\ airline#util#winwidth() < 81
" Shorten default a bit
let s:vcs_config['git'].branch='mas'
endif
else
try
let g:gina#component#repo#commit_length = s:sha1size
let s:vcs_config['git'].branch = gina#component#repo#branch()
catch
endtry
if s:vcs_config['git'].branch is# 'master' &&
\ airline#util#winwidth() < 81
" Shorten default a bit
let s:vcs_config['git'].branch='mas'
endif
endfunction
function! s:config_fugitive_branch() abort
let s:vcs_config['git'].branch = exists('*FugitiveHead') ?
\ FugitiveHead(s:sha1size) : fugitive#head(s:sha1size)
if s:vcs_config['git'].branch is# 'master' &&
\ airline#util#winwidth() < 81
" Shorten default a bit
let s:vcs_config['git'].branch='mas'
endif
endfunction
function! s:config_gina_branch() abort
try
let g:gina#component#repo#commit_length = s:sha1size
let s:vcs_config['git'].branch = gina#component#repo#branch()
catch
endtry
if s:vcs_config['git'].branch is# 'master' &&
\ airline#util#winwidth() < 81
" Shorten default a bit
let s:vcs_config['git'].branch='mas'
endif
endfunction