mirror of
https://github.com/tpope/vim-fugitive.git
synced 2025-11-10 12:33:46 -05:00
Provide FugitiveConfigGetRegexp()
This is intended to double as way to check for the presence of any other Fugitive 3.3 feature.
This commit is contained in:
@@ -120,6 +120,11 @@ function! FugitivePrepare(...) abort
|
|||||||
return call('fugitive#Prepare', a:000)
|
return call('fugitive#Prepare', a:000)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
" FugitiveConfig() get returns an opaque structure that can be passed to other
|
||||||
|
" FugitiveConfig functions in lieu of a Git directory. This can be faster
|
||||||
|
" when performing multiple config queries. Do not rely on the internal
|
||||||
|
" 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
|
function! FugitiveConfig(...) abort
|
||||||
if a:0 == 2 && (type(a:2) != type({}) || has_key(a:2, 'git_dir'))
|
if a:0 == 2 && (type(a:2) != type({}) || has_key(a:2, 'git_dir'))
|
||||||
return fugitive#Config(a:1, FugitiveGitDir(a:2))
|
return fugitive#Config(a:1, FugitiveGitDir(a:2))
|
||||||
@@ -149,6 +154,30 @@ function! FugitiveConfigGetAll(name, ...) abort
|
|||||||
return copy(get(config, name, []))
|
return copy(get(config, name, []))
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
" FugitiveConfigGetRegexp() retrieves a dictionary of all configuration values
|
||||||
|
" with a key matching the given pattern. Like git config --get-regexp, but
|
||||||
|
" 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 !~# '\\\@<!\%(\\\\\)*\\z[se]'
|
||||||
|
return filtered
|
||||||
|
endif
|
||||||
|
let transformed = {}
|
||||||
|
for [k, v] in items(filtered)
|
||||||
|
let k = matchstr(k, a:pattern)
|
||||||
|
if len(k)
|
||||||
|
let transformed[k] = v
|
||||||
|
endif
|
||||||
|
endfor
|
||||||
|
return transformed
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! FugitiveRemoteUrl(...) abort
|
function! FugitiveRemoteUrl(...) abort
|
||||||
return fugitive#RemoteUrl(a:0 ? a:1 : '', FugitiveGitDir(a:0 > 1 ? a:2 : -1), a:0 > 2 ? a:3 : 0)
|
return fugitive#RemoteUrl(a:0 ? a:1 : '', FugitiveGitDir(a:0 > 1 ? a:2 : -1), a:0 > 2 ? a:3 : 0)
|
||||||
endfunction
|
endfunction
|
||||||
|
|||||||
Reference in New Issue
Block a user