mirror of
https://github.com/tpope/vim-fugitive.git
synced 2025-11-14 06:13:51 -05:00
Move config getter implementation into autoload file
This commit is contained in:
@@ -621,21 +621,23 @@ endfunction
|
|||||||
|
|
||||||
let s:config = {}
|
let s:config = {}
|
||||||
function! fugitive#Config(...) abort
|
function! fugitive#Config(...) abort
|
||||||
let dir = s:Dir()
|
|
||||||
let name = ''
|
let name = ''
|
||||||
let default = get(a:, 3, '')
|
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')
|
let name = substitute(a:1, '^[^.]\+\|[^.]\+$', '\L&', 'g')
|
||||||
return len(a:1) ? get(get(a:2, name, []), 0, default) : a:2
|
return len(a:1) ? get(get(a:2, name, []), 0, default) : a:2
|
||||||
elseif a:0 >= 2
|
elseif a:0 >= 2
|
||||||
let dir = a:2
|
let dir = s:Dir(a:2)
|
||||||
let name = a:1
|
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
|
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
|
let name = a:1
|
||||||
elseif a:0 == 1
|
elseif a:0 == 1
|
||||||
let dir = a:1
|
let dir = s:Dir(a:1)
|
||||||
|
else
|
||||||
|
let dir = s:Dir()
|
||||||
endif
|
endif
|
||||||
let name = substitute(name, '^[^.]\+\|[^.]\+$', '\L&', 'g')
|
let name = substitute(name, '^[^.]\+\|[^.]\+$', '\L&', 'g')
|
||||||
let dir_key = len(dir) ? dir : '_'
|
let dir_key = len(dir) ? dir : '_'
|
||||||
@@ -664,6 +666,28 @@ function! fugitive#Config(...) abort
|
|||||||
return len(name) ? get(get(dict, name, []), 0, default) : dict
|
return len(name) ? get(get(dict, name, []), 0, default) : dict
|
||||||
endfunction
|
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 !~# '\\\@<!\%(\\\\\)*\\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! s:Remote(dir) abort
|
function! s:Remote(dir) abort
|
||||||
let head = FugitiveHead(0, a:dir)
|
let head = FugitiveHead(0, a:dir)
|
||||||
let remote = len(head) ? FugitiveConfigGet('branch.' . head . '.remote', a:dir) : ''
|
let remote = len(head) ? FugitiveConfigGet('branch.' . head . '.remote', a:dir) : ''
|
||||||
@@ -2102,7 +2126,7 @@ function! fugitive#BufReadStatus() abort
|
|||||||
if empty(s:Tree())
|
if empty(s:Tree())
|
||||||
call s:AddHeader('Bare', 'yes')
|
call s:AddHeader('Bare', 'yes')
|
||||||
endif
|
endif
|
||||||
if get(FugitiveConfigGetAll('advice.statusHints', config), 0, 'true') !~# '^\%(false\|no|off\|0\|\)$'
|
if get(fugitive#ConfigGetAll('advice.statusHints', config), 0, 'true') !~# '^\%(false\|no|off\|0\|\)$'
|
||||||
call s:AddHeader('Help', 'g?')
|
call s:AddHeader('Help', 'g?')
|
||||||
endif
|
endif
|
||||||
|
|
||||||
@@ -2473,7 +2497,7 @@ augroup END
|
|||||||
|
|
||||||
function! s:AskPassArgs(dir) abort
|
function! s:AskPassArgs(dir) abort
|
||||||
if (len($DISPLAY) || len($TERM_PROGRAM) || has('gui_running')) &&
|
if (len($DISPLAY) || len($TERM_PROGRAM) || has('gui_running')) &&
|
||||||
\ empty($GIT_ASKPASS) && empty($SSH_ASKPASS) && empty(FugitiveConfigGetAll('core.askpass', a:dir))
|
\ empty($GIT_ASKPASS) && empty($SSH_ASKPASS) && empty(fugitive#ConfigGetAll('core.askpass', a:dir))
|
||||||
if s:executable(s:ExecPath() . '/git-gui--askpass')
|
if s:executable(s:ExecPath() . '/git-gui--askpass')
|
||||||
return ['-c', 'core.askPass=' . s:ExecPath() . '/git-gui--askpass']
|
return ['-c', 'core.askPass=' . s:ExecPath() . '/git-gui--askpass']
|
||||||
elseif s:executable('ssh-askpass')
|
elseif s:executable('ssh-askpass')
|
||||||
@@ -2800,7 +2824,7 @@ function! fugitive#PagerFor(argv, ...) abort
|
|||||||
return 0
|
return 0
|
||||||
endif
|
endif
|
||||||
let config = a:0 ? a:1 : fugitive#Config()
|
let config = a:0 ? a:1 : fugitive#Config()
|
||||||
let value = get(FugitiveConfigGetAll('pager.' . args[0], config), 0, -1)
|
let value = get(fugitive#ConfigGetAll('pager.' . args[0], config), 0, -1)
|
||||||
if value =~# '^\%(true\|yes\|on\|1\)$'
|
if value =~# '^\%(true\|yes\|on\|1\)$'
|
||||||
return 1
|
return 1
|
||||||
elseif value =~# '^\%(false\|no|off\|0\|\)$'
|
elseif value =~# '^\%(false\|no|off\|0\|\)$'
|
||||||
@@ -3075,7 +3099,7 @@ function! s:CompletableSubcommands(dir) abort
|
|||||||
endif
|
endif
|
||||||
call extend(commands, s:path_subcommands[cpath])
|
call extend(commands, s:path_subcommands[cpath])
|
||||||
endfor
|
endfor
|
||||||
call extend(commands, keys(FugitiveConfigGetRegexp('^alias\.\zs[^.]\+$', a:dir)))
|
call extend(commands, keys(fugitive#ConfigGetRegexp('^alias\.\zs[^.]\+$', a:dir)))
|
||||||
let configured = split(FugitiveConfigGet('completion.commands', a:dir), '\s\+')
|
let configured = split(FugitiveConfigGet('completion.commands', a:dir), '\s\+')
|
||||||
let rejected = {}
|
let rejected = {}
|
||||||
for command in configured
|
for command in configured
|
||||||
|
|||||||
@@ -128,32 +128,20 @@ endfunction
|
|||||||
" structure of the return value as it is not guaranteed. If you want a full
|
" structure of the return value as it is not guaranteed. If you want a full
|
||||||
" dictionary of every config value, use FugitiveConfigGetRegexp('.*').
|
" 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'))
|
|
||||||
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)
|
return call('fugitive#Config', a:000)
|
||||||
endif
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" FugitiveConfigGet() retrieves a Git configuration value. An optional second
|
" FugitiveConfigGet() retrieves a Git configuration value. An optional second
|
||||||
" argument provides the Git dir as with FugitiveFind(). Pass a blank string
|
" argument provides the Git dir as with FugitiveFind(). Pass a blank string
|
||||||
" to limit to the global config.
|
" to limit to the global config.
|
||||||
function! FugitiveConfigGet(name, ...) abort
|
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
|
endfunction
|
||||||
|
|
||||||
" FugitiveConfigGetAll() is like FugitiveConfigGet() but returns a list of
|
" FugitiveConfigGetAll() is like FugitiveConfigGet() but returns a list of
|
||||||
" all values.
|
" all values.
|
||||||
function! FugitiveConfigGetAll(name, ...) abort
|
function! FugitiveConfigGetAll(name, ...) abort
|
||||||
if a:0 && type(a:1) ==# type({}) && !has_key(a:1, 'git_dir')
|
return call('fugitive#ConfigGetAll', [a:name] + a:000)
|
||||||
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, []))
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" FugitiveConfigGetRegexp() retrieves a dictionary of all configuration values
|
" FugitiveConfigGetRegexp() retrieves a dictionary of all configuration values
|
||||||
@@ -161,23 +149,7 @@ endfunction
|
|||||||
" using a Vim regexp. Second argument has same semantics as
|
" using a Vim regexp. Second argument has same semantics as
|
||||||
" FugitiveConfigGet().
|
" FugitiveConfigGet().
|
||||||
function! FugitiveConfigGetRegexp(pattern, ...) abort
|
function! FugitiveConfigGetRegexp(pattern, ...) abort
|
||||||
if a:0 && type(a:1) ==# type({}) && !has_key(a:2, 'git_dir')
|
return call('fugitive#ConfigGetRegexp', [a:pattern] + a:000)
|
||||||
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
|
endfunction
|
||||||
|
|
||||||
function! FugitiveRemoteUrl(...) abort
|
function! FugitiveRemoteUrl(...) abort
|
||||||
|
|||||||
Reference in New Issue
Block a user