mirror of
https://github.com/tpope/vim-fugitive.git
synced 2025-11-12 13:23:52 -05:00
Provide for retrieving parsed remote URL
The plan is to expose this as FugitiveRemote(), but let's give it some bake time before making it official.
This commit is contained in:
@@ -1272,15 +1272,15 @@ function! s:UrlParse(url) abort
|
|||||||
return url
|
return url
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:ResolveRemote(url) abort
|
function! s:RemoteResolve(url, flags) abort
|
||||||
let remote = s:UrlParse(a:url)
|
let remote = s:UrlParse(a:url)
|
||||||
if remote.scheme =~# '^https\=$'
|
if remote.scheme =~# '^https\=$' && index(a:flags, ':nohttp') < 0
|
||||||
let headers = fugitive#RemoteHttpHeaders(remote.scheme . '://' . remote.authority . remote.path)
|
let headers = fugitive#RemoteHttpHeaders(remote.scheme . '://' . remote.authority . remote.path)
|
||||||
let loc = matchstr(get(headers, 'location', ''), '^https\=://.\{-\}\ze/info/refs?')
|
let loc = matchstr(get(headers, 'location', ''), '^https\=://.\{-\}\ze/info/refs?')
|
||||||
if len(loc)
|
if len(loc)
|
||||||
let remote = s:UrlParse(loc)
|
let remote = s:UrlParse(loc)
|
||||||
else
|
else
|
||||||
let remote.http_headers = headers
|
let remote.headers = headers
|
||||||
endif
|
endif
|
||||||
elseif remote.scheme ==# 'ssh'
|
elseif remote.scheme ==# 'ssh'
|
||||||
let remote.authority = fugitive#SshHostAlias(remote.authority)
|
let remote.authority = fugitive#SshHostAlias(remote.authority)
|
||||||
@@ -1288,23 +1288,66 @@ function! s:ResolveRemote(url) abort
|
|||||||
return remote
|
return remote
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! fugitive#ResolveRemote(url) abort
|
function! s:ConfigLengthSort(i1, i2) abort
|
||||||
let remote = s:ResolveRemote(a:url)
|
return len(a:i2[0]) - len(a:i1[0])
|
||||||
if remote.scheme ==# 'file' || remote.scheme ==# ''
|
endfunction
|
||||||
return remote.path
|
|
||||||
elseif remote.path =~# '^/'
|
function! s:RemoteCallback(config, into, flags, cb) abort
|
||||||
return remote.scheme . '://' . remote.authority . remote.path
|
if a:into.remote_name =~# '^\.\=$'
|
||||||
elseif remote.path =~# '^\~'
|
let a:into.remote_name = s:RemoteDefault(a:config)
|
||||||
return remote.scheme . '://' . remote.authority . '/' . remote.path
|
endif
|
||||||
elseif remote.scheme ==# 'ssh' && remote.authority !~# ':'
|
let url = a:into.remote_name
|
||||||
return remote.authority . ':' . remote.path
|
|
||||||
|
if url ==# '.git'
|
||||||
|
let url = s:GitDir(a:config)
|
||||||
|
elseif url !~# ':\|^/\|^\a:[\/]\|^\.\.\=/'
|
||||||
|
let url = FugitiveConfigGet('remote.' . url . '.url', a:config)
|
||||||
|
endif
|
||||||
|
let instead_of = []
|
||||||
|
for [k, vs] in items(fugitive#ConfigGetRegexp('^url\.\zs.\{-\}\ze\.insteadof$', a:config))
|
||||||
|
for v in vs
|
||||||
|
call add(instead_of, [v, k])
|
||||||
|
endfor
|
||||||
|
endfor
|
||||||
|
call sort(instead_of, 's:ConfigLengthSort')
|
||||||
|
for [orig, replacement] in instead_of
|
||||||
|
if strpart(url, 0, len(orig)) ==# orig
|
||||||
|
let url = replacement . strpart(url, len(orig))
|
||||||
|
break
|
||||||
|
endif
|
||||||
|
endfor
|
||||||
|
if index(a:flags, ':noresolve') < 0
|
||||||
|
call extend(a:into, s:RemoteResolve(url, a:flags))
|
||||||
else
|
else
|
||||||
return a:url
|
call extend(a:into, s:UrlParse(url))
|
||||||
|
endif
|
||||||
|
let a:into.user = matchstr(a:into.authority, '.\{-\}\ze@', '', '')
|
||||||
|
let a:into.host = substitute(a:into.authority, '.\{-\}@', '', '')
|
||||||
|
let a:into.hostname = substitute(a:into.host, ':\d\+$', '', '')
|
||||||
|
let a:into.port = matchstr(a:into.host, ':\zs\d\+$', '', '')
|
||||||
|
if a:into.path =~# '^/'
|
||||||
|
let a:into.url = a:into.scheme . '://' . a:into.authority . a:into.path
|
||||||
|
elseif a:into.path =~# '^\~'
|
||||||
|
let a:into.url = a:into.scheme . '://' . a:into.authority . '/' . a:into.path
|
||||||
|
elseif a:into.scheme ==# 'ssh' && a:into.authority !~# ':'
|
||||||
|
let a:into.url = a:into.authority . ':' . a:into.path
|
||||||
|
else
|
||||||
|
let a:into.url = url
|
||||||
|
endif
|
||||||
|
if len(a:cb)
|
||||||
|
call call(a:cb[0], [a:into] + a:cb[1:-1])
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:ConfigLengthSort(i1, i2) abort
|
function! s:Remote(dir, remote, flags, cb) abort
|
||||||
return len(a:i2[0]) - len(a:i1[0])
|
let into = {'remote_name': a:remote, 'git_dir': s:GitDir(a:dir)}
|
||||||
|
let config = fugitive#Config(a:dir, function('s:RemoteCallback'), into, a:flags, a:cb)
|
||||||
|
if len(a:cb)
|
||||||
|
return config
|
||||||
|
else
|
||||||
|
call fugitive#Wait(config)
|
||||||
|
return into
|
||||||
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:RemoteParseArgs(args) abort
|
function! s:RemoteParseArgs(args) abort
|
||||||
@@ -1344,34 +1387,22 @@ function! s:RemoteParseArgs(args) abort
|
|||||||
return [dir_or_config, remote, flags, cb]
|
return [dir_or_config, remote, flags, cb]
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! fugitive#Remote(...) abort
|
||||||
|
let [dir_or_config, remote, flags, cb] = s:RemoteParseArgs(a:000)
|
||||||
|
return s:Remote(dir_or_config, remote, flags, cb)
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:RemoteUrlCallback(remote, callback) abort
|
||||||
|
return call(a:callback[0], [a:remote.url] + a:callback[1:-1])
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! fugitive#RemoteUrl(...) abort
|
function! fugitive#RemoteUrl(...) abort
|
||||||
let [dir_or_config, url, flags, cb] = s:RemoteParseArgs(a:000)
|
let [dir_or_config, remote, flags, cb] = s:RemoteParseArgs(a:000)
|
||||||
let config = fugitive#Config(dir_or_config)
|
if len(cb)
|
||||||
if url =~# '^\.\=$'
|
let cb = [function('s:RemoteUrlCallback'), cb]
|
||||||
let url = s:RemoteDefault(config)
|
|
||||||
endif
|
endif
|
||||||
if url ==# '.git'
|
let remote = s:Remote(dir_or_config, remote, flags, cb)
|
||||||
let url = s:GitDir(config)
|
return get(remote, 'url', remote)
|
||||||
elseif url !~# ':\|^/\|^\.\.\=/'
|
|
||||||
let url = FugitiveConfigGet('remote.' . url . '.url', config)
|
|
||||||
endif
|
|
||||||
let instead_of = []
|
|
||||||
for [k, vs] in items(fugitive#ConfigGetRegexp('^url\.\zs.\{-\}\ze\.insteadof$', config))
|
|
||||||
for v in vs
|
|
||||||
call add(instead_of, [v, k])
|
|
||||||
endfor
|
|
||||||
endfor
|
|
||||||
call sort(instead_of, 's:ConfigLengthSort')
|
|
||||||
for [orig, replacement] in instead_of
|
|
||||||
if strpart(url, 0, len(orig)) ==# orig
|
|
||||||
let url = replacement . strpart(url, len(orig))
|
|
||||||
break
|
|
||||||
endif
|
|
||||||
endfor
|
|
||||||
if index(flags, 1) < 0 && index(flags, get(v:, 'true', 1)) < 0 && index(flags, ':noresolve') < 0
|
|
||||||
let url = fugitive#ResolveRemote(url)
|
|
||||||
endif
|
|
||||||
return url
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" Section: Quickfix
|
" Section: Quickfix
|
||||||
|
|||||||
Reference in New Issue
Block a user