diff --git a/autoload/fugitive.vim b/autoload/fugitive.vim index b998b7c..6c454d8 100644 --- a/autoload/fugitive.vim +++ b/autoload/fugitive.vim @@ -621,21 +621,23 @@ endfunction 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({}) + if a:0 >= 2 && type(a:2) == type({}) && !has_key(a:2, 'git_dir') let name = substitute(a:1, '^[^.]\+\|[^.]\+$', '\L&', 'g') return len(a:1) ? get(get(a:2, name, []), 0, default) : a:2 elseif a:0 >= 2 - let dir = a:2 + let dir = s:Dir(a:2) let name = a:1 - elseif a:0 == 1 && type(a:1) == type({}) + elseif a:0 == 1 && type(a:1) == type({}) && !has_key(a:1, 'git_dir') return a:1 - elseif a:0 == 1 && a:1 =~# '^[[:alnum:]-]\+\.' + elseif a:0 == 1 && type(a:1) == type('') && a:1 =~# '^[[:alnum:]-]\+\.' + let dir = s:Dir() let name = a:1 elseif a:0 == 1 - let dir = a:1 + let dir = s:Dir(a:1) + else + let dir = s:Dir() endif let name = substitute(name, '^[^.]\+\|[^.]\+$', '\L&', 'g') let dir_key = len(dir) ? dir : '_' @@ -664,6 +666,28 @@ function! fugitive#Config(...) abort return len(name) ? get(get(dict, name, []), 0, default) : dict endfunction +function! fugitive#ConfigGetAll(name, ...) abort + let config = fugitive#Config(a:0 ? a:1 : s:Dir()) + let name = substitute(a:name, '^[^.]\+\|[^.]\+$', '\L&', 'g') + return copy(get(config, name, [])) +endfunction + +function! fugitive#ConfigGetRegexp(pattern, ...) abort + let config = fugitive#Config(a:0 ? a:1 : s:Dir()) + let filtered = map(filter(copy(config), 'v:key =~# "\\." && v:key =~# a:pattern'), 'copy(v:val)') + if a:pattern !~# '\\\@= 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 - return call('fugitive#Config', a:000) - endif + return call('fugitive#Config', a:000) endfunction " FugitiveConfigGet() retrieves a Git configuration value. An optional second " argument provides the Git dir as with FugitiveFind(). Pass a blank string " to limit to the global config. function! FugitiveConfigGet(name, ...) abort - return call('FugitiveConfig', [a:name] + a:000) + return get(call('FugitiveConfigGetAll', [a:name] + (a:0 ? [a:1] : [])), 0, get(a:, 2, '')) endfunction " FugitiveConfigGetAll() is like FugitiveConfigGet() but returns a list of " all values. function! FugitiveConfigGetAll(name, ...) abort - if a:0 && type(a:1) ==# type({}) && !has_key(a:1, 'git_dir') - let config = a:1 - else - let config = fugitive#Config(FugitiveGitDir(a:0 ? a:1 : -1)) - endif - let name = substitute(a:name, '^[^.]\+\|[^.]\+$', '\L&', 'g') - return copy(get(config, name, [])) + return call('fugitive#ConfigGetAll', [a:name] + a:000) endfunction " FugitiveConfigGetRegexp() retrieves a dictionary of all configuration values @@ -161,23 +149,7 @@ endfunction " using a Vim regexp. Second argument has same semantics as " FugitiveConfigGet(). function! FugitiveConfigGetRegexp(pattern, ...) abort - if a:0 && type(a:1) ==# type({}) && !has_key(a:2, 'git_dir') - let config = a:1 - else - let config = fugitive#Config(FugitiveGitDir(a:0 ? a:1 : -1)) - endif - let filtered = map(filter(copy(config), 'v:key =~# "\\." && v:key =~# a:pattern'), 'copy(v:val)') - if a:pattern !~# '\\\@