mirror of
https://github.com/tpope/vim-rhubarb.git
synced 2025-12-07 04:34:27 +08:00
Eliminate hard coded a:opts parameter
This is a bit preemptive refactoring to enable passing a second parameter to force plain http.
This commit is contained in:
@@ -243,15 +243,17 @@ endfunction
|
|||||||
|
|
||||||
" Section: Fugitive :Gbrowse support
|
" Section: Fugitive :Gbrowse support
|
||||||
|
|
||||||
function! rhubarb#FugitiveUrl(opts, ...) abort
|
function! rhubarb#FugitiveUrl(...) abort
|
||||||
if a:0 || type(a:opts) != type({})
|
if a:0 == 1 || type(a:1) == type({})
|
||||||
|
let opts = a:1
|
||||||
|
let root = rhubarb#HomepageForUrl(get(opts, 'remote', ''))
|
||||||
|
else
|
||||||
return ''
|
return ''
|
||||||
endif
|
endif
|
||||||
let root = rhubarb#homepage_for_url(get(a:opts, 'remote'))
|
|
||||||
if empty(root)
|
if empty(root)
|
||||||
return ''
|
return ''
|
||||||
endif
|
endif
|
||||||
let path = substitute(a:opts.path, '^/', '', '')
|
let path = substitute(opts.path, '^/', '', '')
|
||||||
if path =~# '^\.git/refs/heads/'
|
if path =~# '^\.git/refs/heads/'
|
||||||
return root . '/commits/' . path[16:-1]
|
return root . '/commits/' . path[16:-1]
|
||||||
elseif path =~# '^\.git/refs/tags/'
|
elseif path =~# '^\.git/refs/tags/'
|
||||||
@@ -263,20 +265,20 @@ function! rhubarb#FugitiveUrl(opts, ...) abort
|
|||||||
elseif path =~# '^\.git\>'
|
elseif path =~# '^\.git\>'
|
||||||
return root
|
return root
|
||||||
endif
|
endif
|
||||||
if a:opts.commit =~# '^\d\=$'
|
if opts.commit =~# '^\d\=$'
|
||||||
return ''
|
return ''
|
||||||
else
|
else
|
||||||
let commit = a:opts.commit
|
let commit = opts.commit
|
||||||
endif
|
endif
|
||||||
if get(a:opts, 'type', '') ==# 'tree' || a:opts.path =~# '/$'
|
if get(opts, 'type', '') ==# 'tree' || opts.path =~# '/$'
|
||||||
let url = substitute(root . '/tree/' . commit . '/' . path, '/$', '', 'g')
|
let url = substitute(root . '/tree/' . commit . '/' . path, '/$', '', 'g')
|
||||||
elseif get(a:opts, 'type', '') ==# 'blob' || a:opts.path =~# '[^/]$'
|
elseif get(opts, 'type', '') ==# 'blob' || opts.path =~# '[^/]$'
|
||||||
let escaped_commit = substitute(commit, '#', '%23', 'g')
|
let escaped_commit = substitute(commit, '#', '%23', 'g')
|
||||||
let url = root . '/blob/' . escaped_commit . '/' . path
|
let url = root . '/blob/' . escaped_commit . '/' . path
|
||||||
if get(a:opts, 'line2') && a:opts.line1 == a:opts.line2
|
if get(opts, 'line2') && opts.line1 == opts.line2
|
||||||
let url .= '#L' . a:opts.line1
|
let url .= '#L' . opts.line1
|
||||||
elseif get(a:opts, 'line2')
|
elseif get(opts, 'line2')
|
||||||
let url .= '#L' . a:opts.line1 . '-L' . a:opts.line2
|
let url .= '#L' . opts.line1 . '-L' . opts.line2
|
||||||
endif
|
endif
|
||||||
else
|
else
|
||||||
let url = root . '/commit/' . commit
|
let url = root . '/commit/' . commit
|
||||||
|
|||||||
Reference in New Issue
Block a user