mirror of
https://github.com/tpope/vim-fugitive.git
synced 2025-11-12 13:23:52 -05:00
Add methods to config object
Do not rely on these. The FugitiveConfigGet() family of functions remains official, for now.
This commit is contained in:
@@ -233,6 +233,12 @@ function! fugitive#Autowrite() abort
|
|||||||
return ''
|
return ''
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! s:add_methods(namespace, method_names) abort
|
||||||
|
for name in a:method_names
|
||||||
|
let s:{a:namespace}_prototype[name] = s:function('s:'.a:namespace.'_'.name)
|
||||||
|
endfor
|
||||||
|
endfunction
|
||||||
|
|
||||||
" Section: Git
|
" Section: Git
|
||||||
|
|
||||||
function! s:GitCmd() abort
|
function! s:GitCmd() abort
|
||||||
@@ -633,13 +639,14 @@ function! s:ConfigTimestamps(dir, dict) abort
|
|||||||
return join(map(files, 'getftime(expand(v:val))'), ',')
|
return join(map(files, 'getftime(expand(v:val))'), ',')
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
let s:config_prototype = {}
|
||||||
|
|
||||||
let s:config = {}
|
let s:config = {}
|
||||||
function! fugitive#Config(...) abort
|
function! fugitive#Config(...) abort
|
||||||
let name = ''
|
let name = ''
|
||||||
let default = get(a:, 3, '')
|
let default = get(a:, 3, '')
|
||||||
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, 'GetAll')
|
||||||
let name = substitute(a:1, '^[^.]\+\|[^.]\+$', '\L&', 'g')
|
return fugitive#ConfigGetAll(a:1, 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 = s:Dir(a:2)
|
let dir = s:Dir(a:2)
|
||||||
let name = a:1
|
let name = a:1
|
||||||
@@ -658,7 +665,8 @@ function! fugitive#Config(...) abort
|
|||||||
if has_key(s:config, dir_key) && s:config[dir_key][0] ==# s:ConfigTimestamps(dir, s:config[dir_key][1])
|
if has_key(s:config, dir_key) && s:config[dir_key][0] ==# s:ConfigTimestamps(dir, s:config[dir_key][1])
|
||||||
let dict = s:config[dir_key][1]
|
let dict = s:config[dir_key][1]
|
||||||
else
|
else
|
||||||
let dict = {}
|
let dict = copy(s:config_prototype)
|
||||||
|
let dict.git_dir = dir
|
||||||
let [lines, message, exec_error] = s:NullError([dir, 'config', '--list', '-z'])
|
let [lines, message, exec_error] = s:NullError([dir, 'config', '--list', '-z'])
|
||||||
if exec_error
|
if exec_error
|
||||||
return {}
|
return {}
|
||||||
@@ -702,6 +710,25 @@ function! fugitive#ConfigGetRegexp(pattern, ...) abort
|
|||||||
return transformed
|
return transformed
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! s:config_GetAll(name) dict abort
|
||||||
|
let name = substitute(a:name, '^[^.]\+\|[^.]\+$', '\L&', 'g')
|
||||||
|
if name =~# '\.'
|
||||||
|
return get(self, name, [])
|
||||||
|
else
|
||||||
|
return []
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:config_Get(name, ...) dict abort
|
||||||
|
return get(self.GetAll(a:name), 0, a:0 ? a:1 : '')
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:config_GetRegexp(pattern) dict abort
|
||||||
|
return fugitive#ConfigGetRegexp(self, a:pattern)
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
call s:add_methods('config', ['GetAll', 'Get', 'GetRegexp'])
|
||||||
|
|
||||||
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) : ''
|
||||||
@@ -826,7 +853,7 @@ function! fugitive#ResolveRemote(remote) abort
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! fugitive#RemoteUrl(...) abort
|
function! fugitive#RemoteUrl(...) abort
|
||||||
let dir = a:0 > 1 ? a:2 : s:Dir()
|
let dir = a:0 > 1 ? s:Dir(a:2) : s:Dir()
|
||||||
let url = !a:0 || a:1 =~# '^\.\=$' ? s:Remote(dir) : a:1
|
let url = !a:0 || a:1 =~# '^\.\=$' ? s:Remote(dir) : a:1
|
||||||
if url !~# ':\|^/\|^\.\.\=/'
|
if url !~# ':\|^/\|^\.\.\=/'
|
||||||
if !fugitive#GitVersion(2, 7)
|
if !fugitive#GitVersion(2, 7)
|
||||||
@@ -921,12 +948,6 @@ endfunction
|
|||||||
|
|
||||||
" Section: Repository Object
|
" Section: Repository Object
|
||||||
|
|
||||||
function! s:add_methods(namespace, method_names) abort
|
|
||||||
for name in a:method_names
|
|
||||||
let s:{a:namespace}_prototype[name] = s:function('s:'.a:namespace.'_'.name)
|
|
||||||
endfor
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
let s:repo_prototype = {}
|
let s:repo_prototype = {}
|
||||||
let s:repos = {}
|
let s:repos = {}
|
||||||
|
|
||||||
|
|||||||
@@ -170,7 +170,7 @@ endfunction
|
|||||||
" An optional second argument provides the Git dir, or the buffer number of a
|
" An optional second argument provides the Git dir, or the buffer number of a
|
||||||
" buffer with a Git dir. The default is the current buffer.
|
" buffer with a Git dir. The default is the current buffer.
|
||||||
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 : '', a:0 > 1 ? a:2 : -1, a:0 > 2 ? a:3 : 0)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" FugitiveHead() retrieves the name of the current branch. If the current HEAD
|
" FugitiveHead() retrieves the name of the current branch. If the current HEAD
|
||||||
|
|||||||
Reference in New Issue
Block a user