Allow reusing dictionary for config queries

This commit is contained in:
Tim Pope 2018-12-21 13:23:30 -05:00
parent 73220820b5
commit 4ecd7e8932
2 changed files with 15 additions and 11 deletions

View File

@ -341,13 +341,17 @@ let s:config = {}
function! fugitive#Config(...) abort function! fugitive#Config(...) abort
let dir = get(b:, 'git_dir', '') let dir = get(b:, 'git_dir', '')
let name = '' let name = ''
if len(a:000) >= 2 if a:0 >= 2 && type(a:2) == type({})
let dir = a:000[1] return len(a:1) ? get(get(a:2, a:1, []), 0, '') : a:2
let name = a:000[0] elseif a:0 >= 2
elseif len(a:000) == 1 && a:000[0] =~# '^[[:alnum:]-]\+\.' let dir = a:2
let name = a:000[0] let name = a:1
elseif len(a:000) == 1 elseif a:0 == 1 && type(a:1) == type({})
let dir = a:000[0] return a:1
elseif a:0 == 1 && a:1 =~# '^[[:alnum:]-]\+\.'
let name = a:1
elseif a:0 == 1
let dir = a:1
endif endif
let key = len(dir) ? dir : '_' let key = len(dir) ? dir : '_'
if has_key(s:config, key) && s:config[key][0] ==# s:ConfigTimestamps(dir, s:config[key][1]) if has_key(s:config, key) && s:config[key][0] ==# s:ConfigTimestamps(dir, s:config[key][1])

View File

@ -73,10 +73,10 @@ function! FugitivePrepare(...) abort
endfunction endfunction
function! FugitiveConfig(...) abort function! FugitiveConfig(...) abort
if len(a:000) == 2 if a:0 == 2 && type(a:2) != type({})
return fugitive#Config(a:000[1], FugitiveGitDir(a:000[2])) return fugitive#Config(a:1, FugitiveGitDir(a:2))
elseif len(a:000) == 1 && a:000[0] !~# '^[[:alnum:]-]\+\.' elseif a:0 == 1 && a:1 !~# '^[[:alnum:]-]\+\.'
return fugitive#Config(FugitiveGitDir(a:000[0])) return fugitive#Config(FugitiveGitDir(a:1))
else else
return call('fugitive#Config', a:000) return call('fugitive#Config', a:000)
endif endif