From 75ad917e4978b4620c3b0eff1722880d2d53a9f4 Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Mon, 2 Sep 2019 16:30:05 -0400 Subject: [PATCH] Eliminate hard coded a:opts parameter This is a bit preemptive refactoring to enable passing a second parameter to force plain http. --- autoload/rhubarb.vim | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/autoload/rhubarb.vim b/autoload/rhubarb.vim index 588ce34..78c8407 100644 --- a/autoload/rhubarb.vim +++ b/autoload/rhubarb.vim @@ -243,15 +243,17 @@ endfunction " Section: Fugitive :Gbrowse support -function! rhubarb#FugitiveUrl(opts, ...) abort - if a:0 || type(a:opts) != type({}) +function! rhubarb#FugitiveUrl(...) abort + if a:0 == 1 || type(a:1) == type({}) + let opts = a:1 + let root = rhubarb#HomepageForUrl(get(opts, 'remote', '')) + else return '' endif - let root = rhubarb#homepage_for_url(get(a:opts, 'remote')) if empty(root) return '' endif - let path = substitute(a:opts.path, '^/', '', '') + let path = substitute(opts.path, '^/', '', '') if path =~# '^\.git/refs/heads/' return root . '/commits/' . path[16:-1] elseif path =~# '^\.git/refs/tags/' @@ -263,20 +265,20 @@ function! rhubarb#FugitiveUrl(opts, ...) abort elseif path =~# '^\.git\>' return root endif - if a:opts.commit =~# '^\d\=$' + if opts.commit =~# '^\d\=$' return '' else - let commit = a:opts.commit + let commit = opts.commit 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') - elseif get(a:opts, 'type', '') ==# 'blob' || a:opts.path =~# '[^/]$' + elseif get(opts, 'type', '') ==# 'blob' || opts.path =~# '[^/]$' let escaped_commit = substitute(commit, '#', '%23', 'g') let url = root . '/blob/' . escaped_commit . '/' . path - if get(a:opts, 'line2') && a:opts.line1 == a:opts.line2 - let url .= '#L' . a:opts.line1 - elseif get(a:opts, 'line2') - let url .= '#L' . a:opts.line1 . '-L' . a:opts.line2 + if get(opts, 'line2') && opts.line1 == opts.line2 + let url .= '#L' . opts.line1 + elseif get(opts, 'line2') + let url .= '#L' . opts.line1 . '-L' . opts.line2 endif else let url = root . '/commit/' . commit