Support default value as third FugitiveConfigGet() argument

This commit is contained in:
Tim Pope
2021-05-26 09:22:37 -04:00
parent bee78a418f
commit da8d532b1a
2 changed files with 5 additions and 4 deletions

View File

@@ -623,9 +623,10 @@ let s:config = {}
function! fugitive#Config(...) abort
let dir = s:Dir()
let name = ''
let default = get(a:, 3, '')
if a:0 >= 2 && type(a:2) == type({})
let name = substitute(a:1, '^[^.]\+\|[^.]\+$', '\L&', 'g')
return len(a:1) ? get(get(a:2, name, []), 0, '') : a:2
return len(a:1) ? get(get(a:2, name, []), 0, default) : a:2
elseif a:0 >= 2
let dir = a:2
let name = a:1
@@ -660,7 +661,7 @@ function! fugitive#Config(...) abort
let s:config[dir_key] = [s:ConfigTimestamps(dir, dict), dict]
lockvar! dict
endif
return len(name) ? get(get(dict, name, []), 0, '') : dict
return len(name) ? get(get(dict, name, []), 0, default) : dict
endfunction
function! s:Remote(dir) abort

View File

@@ -128,8 +128,8 @@ endfunction
" structure of the return value as it is not guaranteed. If you want a full
" dictionary of every config value, use FugitiveConfigGetRegexp('.*').
function! FugitiveConfig(...) abort
if a:0 == 2 && (type(a:2) != type({}) || has_key(a:2, 'git_dir'))
return fugitive#Config(a:1, FugitiveGitDir(a:2))
if a:0 >= 2 && (type(a:2) != type({}) || has_key(a:2, 'git_dir'))
return call('fugitive#Config', [a:1, FugitiveGitDir(a:2)] + a:000[2:-1])
elseif a:0 == 1 && (type(a:1) !=# type('') || a:1 !~# '^[[:alnum:]-]\+\.')
return fugitive#Config(FugitiveGitDir(a:1))
else