Accept alternate forms of Fugitive URL

This is to prepare for a potential transition to a URL replacement that
isn't mutilated by simplify().
This commit is contained in:
Tim Pope
2018-06-15 23:10:05 -04:00
parent bb54881388
commit d39d5ca429
2 changed files with 11 additions and 11 deletions

View File

@@ -428,7 +428,7 @@ call s:add_methods('repo',['keywordprg'])
" Section: Buffer
function! s:UrlSplit(path) abort
let vals = matchlist(s:shellslash(a:path), '\c^fugitive://\(.\{-\}\)//\(\w\+\)\(/.*\)\=$')
let vals = matchlist(s:shellslash(a:path), '\c^fugitive:\%(//\)\=\(.\{-\}\)\%(//\|::\)\(\w\+\)\(/.*\)\=$')
if empty(vals)
return ['', '', '']
endif
@@ -527,7 +527,7 @@ function! s:buffer_name() dict abort
endfunction
function! s:buffer_commit() dict abort
return matchstr(self.spec(),'^fugitive://.\{-\}//\zs\w*')
return matchstr(self.spec(),'^fugitive:\%(//\)\=.\{-\}\%(//\|::\)\zs\w*')
endfunction
function! s:cpath(path) abort
@@ -539,7 +539,7 @@ function! s:cpath(path) abort
endfunction
function! s:buffer_path(...) dict abort
let rev = matchstr(self.spec(),'^fugitive://.\{-\}//\zs.*')
let rev = matchstr(self.spec(),'^fugitive:\%(//\)\=.\{-\}\%(//\|::\)\zs.*')
if rev != ''
let rev = s:sub(rev,'\w*','')
elseif s:cpath(self.spec()[0 : len(self.repo().dir())]) ==#
@@ -554,7 +554,7 @@ function! s:buffer_path(...) dict abort
endfunction
function! s:buffer_rev() dict abort
let rev = matchstr(self.spec(),'^fugitive://.\{-\}//\zs.*')
let rev = matchstr(self.spec(),'^fugitive:\%(//\)\=.\{-\}\%(//\|::\)\zs.*')
if rev =~ '^\x/'
return ':'.rev[0].':'.rev[2:-1]
elseif rev =~ '.'
@@ -569,7 +569,7 @@ function! s:buffer_rev() dict abort
endfunction
function! s:buffer_sha1() dict abort
if self.spec() =~ '^fugitive://' || self.spec() =~ '\.git/refs/\|\.git/.*HEAD$'
if self.spec() =~? '^fugitive:' || self.spec() =~ '\.git/refs/\|\.git/.*HEAD$'
return self.repo().rev_parse(self.rev())
else
return ''
@@ -2219,9 +2219,9 @@ function! s:Browse(bang,line1,count,...) abort
endif
let full = s:repo().translate(expanded)
let commit = ''
if full =~# '^fugitive://'
let commit = matchstr(full,'://.*//\zs\w\w\+')
let path = matchstr(full,'://.*//\w\+\zs/.*')
if full =~? '^fugitive:'
let commit = matchstr(full,':\%(//\)\=.*\%(//\|::\)\zs\w\w\+')
let path = matchstr(full,':\%(//\)\=.*\%(//\|::\)\w\+\zs/.*')
if commit =~ '..'
let type = s:repo().git_chomp('cat-file','-t',commit.s:sub(path,'^/',':'))
let branch = matchstr(expanded, '^[^:]*')
@@ -2567,7 +2567,7 @@ endfunction
function! fugitive#FileRead() abort
try
let repo = s:repo(FugitiveExtractGitDir(expand('<amatch>')))
let path = s:sub(s:sub(matchstr(expand('<amatch>'),'fugitive://.\{-\}//\zs.*'),'/',':'),'^\d:',':&')
let path = s:sub(s:sub(matchstr(expand('<amatch>'),'fugitive:\%(//\)\=.\{-\}\%(//\|::\)\zs.*'),'/',':'),'^\d:',':&')
let hash = repo.rev_parse(path)
if path =~ '^:'
let type = 'blob'

View File

@@ -59,8 +59,8 @@ endfunction
function! FugitiveExtractGitDir(path) abort
let path = s:shellslash(a:path)
if path =~# '^fugitive://.*//'
return matchstr(path, '\C^fugitive://\zs.\{-\}\ze//')
if path =~# '^fugitive:'
return matchstr(path, '\C^fugitive:\%(//\)\=\zs.\{-\}\ze\%(//\|::\|$\)')
elseif isdirectory(path)
let path = fnamemodify(path, ':p:s?/$??')
else