-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
58 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
function! fugitive#bitbucketserver#browse_handler(opts, ...) abort | ||
if a:0 || type(a:opts) != type({}) | ||
return '' | ||
endif | ||
|
||
|
||
let domains = g:fugitive_bitbucketservers_domains | ||
let domain_patterns = [] | ||
|
||
for domain in domains | ||
call add(domain_patterns, escape(split(domain, '://')[-1], '.')) | ||
endfor | ||
|
||
let domain_pattern = join(domain_patterns, '\|') | ||
let repo = matchstr(a:opts.remote,'^\%(https\=://\|git://\|\(ssh://\)\=git@\)\%(.\{-\}@\)\=\zs\('.domain_pattern.'\)[/:].\{-\}\ze\%(\.git\)\=$') | ||
if repo ==# '' | ||
return '' | ||
endif | ||
|
||
let url_split = split(repo,'/') | ||
|
||
if index(domains, 'http://' . matchstr(repo, '^[^:/]*')) >= 0 | ||
let root = 'http://'.url_split[-4] .'/projects/'.toupper(url_split[-2]).'/repos/'.url_split[-1] | ||
else | ||
let root = 'https://'.url_split[-4] .'/projects/'.toupper(url_split[-2]).'/repos/'.url_split[-1] | ||
endif | ||
|
||
let path = substitute(a:opts.path, '^/', '', '') | ||
if path =~# '^\.git/refs/heads/' | ||
return root . '/commits/'.path[16:-1] | ||
elseif path =~# '^\.git/refs/tags/' | ||
return root . '/browse/'.path[15:-1] | ||
elseif path =~# '.git/\%(config$\|hooks\>\)' | ||
return root . '/admin' | ||
elseif path =~# '^\.git\>' | ||
return root | ||
endif | ||
if a:opts.commit =~# '^\d\=$' | ||
let commit = a:opts.repo.rev_parse('HEAD') | ||
else | ||
let commit = a:opts.commit | ||
endif | ||
if get(a:opts, 'type', '') ==# 'tree' || a:opts.path =~# '/$' | ||
return '' | ||
elseif get(a:opts, 'type', '') ==# 'blob' || a:opts.path =~# '[^/]$' | ||
let url = root . '/browse/'.path.'?until='.commit | ||
if get(a:opts, 'line1') | ||
let url .= '#' . a:opts.line1 | ||
if get(a:opts, 'line2') != get(a:opts, 'line1') | ||
let url .= '-' . a:opts.line2 | ||
endif | ||
endif | ||
else | ||
let url = root . '/commits/' . commit | ||
endif | ||
return url | ||
endfunction |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,5 @@ | ||
function! s:function(name) abort | ||
return function(substitute(a:name,'^s:',matchstr(expand('<sfile>'), '<SNR>\d\+_'),'')) | ||
endfunction | ||
|
||
function! s:bitbucketserver_url(opts, ...) abort | ||
if a:0 || type(a:opts) != type({}) | ||
return '' | ||
endif | ||
|
||
|
||
let domains = g:fugitive_bitbucketservers_domains | ||
let domain_patterns = [] | ||
|
||
for domain in domains | ||
call add(domain_patterns, escape(split(domain, '://')[-1], '.')) | ||
endfor | ||
|
||
let domain_pattern = join(domain_patterns, '\|') | ||
let repo = matchstr(a:opts.remote,'^\%(https\=://\|git://\|\(ssh://\)\=git@\)\%(.\{-\}@\)\=\zs\('.domain_pattern.'\)[/:].\{-\}\ze\%(\.git\)\=$') | ||
if repo ==# '' | ||
return '' | ||
endif | ||
|
||
let url_split = split(repo,'/') | ||
|
||
if index(domains, 'http://' . matchstr(repo, '^[^:/]*')) >= 0 | ||
let root = 'http://'.url_split[-4] .'/projects/'.toupper(url_split[-2]).'/repos/'.url_split[-1] | ||
else | ||
let root = 'https://'.url_split[-4] .'/projects/'.toupper(url_split[-2]).'/repos/'.url_split[-1] | ||
endif | ||
|
||
let path = substitute(a:opts.path, '^/', '', '') | ||
if path =~# '^\.git/refs/heads/' | ||
return root . '/commits/'.path[16:-1] | ||
elseif path =~# '^\.git/refs/tags/' | ||
return root . '/browse/'.path[15:-1] | ||
elseif path =~# '.git/\%(config$\|hooks\>\)' | ||
return root . '/admin' | ||
elseif path =~# '^\.git\>' | ||
return root | ||
endif | ||
if a:opts.commit =~# '^\d\=$' | ||
let commit = a:opts.repo.rev_parse('HEAD') | ||
else | ||
let commit = a:opts.commit | ||
endif | ||
if get(a:opts, 'type', '') ==# 'tree' || a:opts.path =~# '/$' | ||
return '' | ||
elseif get(a:opts, 'type', '') ==# 'blob' || a:opts.path =~# '[^/]$' | ||
let url = root . '/browse/'.path.'?until='.commit | ||
if get(a:opts, 'line1') | ||
let url .= '#' . a:opts.line1 | ||
if get(a:opts, 'line2') != get(a:opts, 'line1') | ||
let url .= '-' . a:opts.line2 | ||
endif | ||
endif | ||
else | ||
let url = root . '/commits/' . commit | ||
endif | ||
return url | ||
endfunction | ||
|
||
if !exists('g:fugitive_browse_handlers') | ||
let g:fugitive_browse_handlers = [] | ||
endif | ||
|
||
call insert(g:fugitive_browse_handlers, s:function('s:bitbucketserver_url')) | ||
call insert(g:fugitive_browse_handlers, function('fugitive#bitbucketserver#browse_handler')) |