mirror of
https://github.com/tpope/vim-fugitive.git
synced 2025-11-16 23:33:43 -05:00
Encapsulate appending relative path to Fugitive URL
This gives us a central place to add URL encoding
This commit is contained in:
@@ -543,16 +543,20 @@ function! s:SameRepo(one, two) abort
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
if exists('+shellslash')
|
if exists('+shellslash')
|
||||||
function! s:DirUrlPrefix(...) abort
|
function! s:DirUrlPrefix(dir) abort
|
||||||
let gd = call('s:GitDir', a:000)
|
let gd = s:GitDir(a:dir)
|
||||||
return 'fugitive://' . (gd =~# '^[^/]' ? '/' : '') . gd . '//'
|
return 'fugitive://' . (gd =~# '^[^/]' ? '/' : '') . gd . '//'
|
||||||
endfunction
|
endfunction
|
||||||
else
|
else
|
||||||
function! s:DirUrlPrefix(...) abort
|
function! s:DirUrlPrefix(dir) abort
|
||||||
return 'fugitive://' . call('s:GitDir', a:000) . '//'
|
return 'fugitive://' . s:GitDir(a:dir) . '//'
|
||||||
endfunction
|
endfunction
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
function! s:PathJoin(prefix, str) dict abort
|
||||||
|
return a:prefix . a:str
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! s:Tree(...) abort
|
function! s:Tree(...) abort
|
||||||
return a:0 ? FugitiveWorkTree(a:1) : FugitiveWorkTree()
|
return a:0 ? FugitiveWorkTree(a:1) : FugitiveWorkTree()
|
||||||
endfunction
|
endfunction
|
||||||
@@ -1791,7 +1795,7 @@ function! fugitive#Find(object, ...) abort
|
|||||||
if f =~# '^\.\./\.\.\%(/\|$\)'
|
if f =~# '^\.\./\.\.\%(/\|$\)'
|
||||||
let f = simplify(len(tree) ? tree . f[2:-1] : fdir . f)
|
let f = simplify(len(tree) ? tree . f[2:-1] : fdir . f)
|
||||||
elseif f =~# '^\.\.\%(/\|$\)'
|
elseif f =~# '^\.\.\%(/\|$\)'
|
||||||
let f = base . f[2:-1]
|
let f = s:PathJoin(base, f[2:-1])
|
||||||
elseif cdir !=# fdir && (
|
elseif cdir !=# fdir && (
|
||||||
\ f =~# '^\%(config\|hooks\|info\|logs/refs\|objects\|refs\|worktrees\)\%(/\|$\)' ||
|
\ f =~# '^\%(config\|hooks\|info\|logs/refs\|objects\|refs\|worktrees\)\%(/\|$\)' ||
|
||||||
\ f !~# '^\%(index$\|index\.lock$\|\w*MSG$\|\w*HEAD$\|logs/\w*HEAD$\|logs$\|rebase-\w\+\)\%(/\|$\)' &&
|
\ f !~# '^\%(index$\|index\.lock$\|\w*MSG$\|\w*HEAD$\|logs/\w*HEAD$\|logs$\|rebase-\w\+\)\%(/\|$\)' &&
|
||||||
@@ -1803,17 +1807,17 @@ function! fugitive#Find(object, ...) abort
|
|||||||
elseif rev ==# ':/'
|
elseif rev ==# ':/'
|
||||||
let f = tree
|
let f = tree
|
||||||
elseif rev =~# '^\.\%(/\|$\)'
|
elseif rev =~# '^\.\%(/\|$\)'
|
||||||
let f = base . rev[1:-1]
|
let f = s:PathJoin(base, rev[1:-1])
|
||||||
elseif rev =~# '^::\%(/\|\a\+\:\)'
|
elseif rev =~# '^::\%(/\|\a\+\:\)'
|
||||||
let f = rev[2:-1]
|
let f = rev[2:-1]
|
||||||
elseif rev =~# '^::\.\.\=\%(/\|$\)'
|
elseif rev =~# '^::\.\.\=\%(/\|$\)'
|
||||||
let f = simplify(getcwd() . '/' . rev[2:-1])
|
let f = simplify(getcwd() . '/' . rev[2:-1])
|
||||||
elseif rev =~# '^::'
|
elseif rev =~# '^::'
|
||||||
let f = base . '/' . rev[2:-1]
|
let f = s:PathJoin(base, '/' . rev[2:-1])
|
||||||
elseif rev =~# '^:\%([0-3]:\)\=\.\.\=\%(/\|$\)\|^:[0-3]:\%(/\|\a\+:\)'
|
elseif rev =~# '^:\%([0-3]:\)\=\.\.\=\%(/\|$\)\|^:[0-3]:\%(/\|\a\+:\)'
|
||||||
let f = rev =~# '^:\%([0-3]:\)\=\.' ? simplify(getcwd() . '/' . matchstr(rev, '\..*')) : rev[3:-1]
|
let f = rev =~# '^:\%([0-3]:\)\=\.' ? simplify(getcwd() . '/' . matchstr(rev, '\..*')) : rev[3:-1]
|
||||||
if s:cpath(base . '/', (f . '/')[0 : len(base)])
|
if s:cpath(base . '/', (f . '/')[0 : len(base)])
|
||||||
let f = urlprefix . +matchstr(rev, '^:\zs\d\ze:') . '/' . strpart(f, len(base) + 1)
|
let f = s:PathJoin(urlprefix, +matchstr(rev, '^:\zs\d\ze:') . '/' . strpart(f, len(base) + 1))
|
||||||
else
|
else
|
||||||
let altdir = FugitiveExtractGitDir(f)
|
let altdir = FugitiveExtractGitDir(f)
|
||||||
if len(altdir) && !s:cpath(dir, altdir)
|
if len(altdir) && !s:cpath(dir, altdir)
|
||||||
@@ -1821,7 +1825,7 @@ function! fugitive#Find(object, ...) abort
|
|||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
elseif rev =~# '^:[0-3]:'
|
elseif rev =~# '^:[0-3]:'
|
||||||
let f = urlprefix . rev[1] . '/' . rev[3:-1]
|
let f = s:PathJoin(urlprefix, rev[1] . '/' . rev[3:-1])
|
||||||
elseif rev ==# ':'
|
elseif rev ==# ':'
|
||||||
let fdir = simplify(FugitiveActualDir(dir) . '/')
|
let fdir = simplify(FugitiveActualDir(dir) . '/')
|
||||||
let f = fdir . 'index'
|
let f = fdir . 'index'
|
||||||
@@ -1840,10 +1844,10 @@ function! fugitive#Find(object, ...) abort
|
|||||||
if f=~# '^\.\.\=\%(/\|$\)'
|
if f=~# '^\.\.\=\%(/\|$\)'
|
||||||
let f = simplify(getcwd() . '/' . f)
|
let f = simplify(getcwd() . '/' . f)
|
||||||
elseif f !~# '^/\|^\%(\a\a\+:\).*\%(//\|::\)' . (has('win32') ? '\|^\a:/' : '')
|
elseif f !~# '^/\|^\%(\a\a\+:\).*\%(//\|::\)' . (has('win32') ? '\|^\a:/' : '')
|
||||||
let f = base . '/' . f
|
let f = s:PathJoin(base, '/' . f)
|
||||||
endif
|
endif
|
||||||
elseif rev =~# '^:/\@!'
|
elseif rev =~# '^:/\@!'
|
||||||
let f = urlprefix . '0/' . rev[1:-1]
|
let f = s:PathJoin(urlprefix, '0/' . rev[1:-1])
|
||||||
else
|
else
|
||||||
if !exists('f')
|
if !exists('f')
|
||||||
let commit = matchstr(rev, '^\%([^:.-]\|\.\.[^/:]\)[^:]*\|^:.*')
|
let commit = matchstr(rev, '^\%([^:.-]\|\.\.[^/:]\)[^:]*\|^:.*')
|
||||||
@@ -1872,9 +1876,9 @@ function! fugitive#Find(object, ...) abort
|
|||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
if len(commit)
|
if len(commit)
|
||||||
let f = urlprefix . commit . file
|
let f = s:PathJoin(urlprefix, commit . file)
|
||||||
else
|
else
|
||||||
let f = base . '/' . substitute(rev, '^:/:\=\|^[^:]\+:', '', '')
|
let f = s:PathJoin(base, '/' . substitute(rev, '^:/:\=\|^[^:]\+:', '', ''))
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
@@ -2155,7 +2159,7 @@ function! fugitive#simplify(url) abort
|
|||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
return s:VimSlash(s:DirUrlPrefix(simplify(s:GitDir(dir))) . commit . simplify(file))
|
return s:VimSlash(s:PathJoin(s:DirUrlPrefix(simplify(s:GitDir(dir))), commit . simplify(file)))
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! fugitive#resolve(url) abort
|
function! fugitive#resolve(url) abort
|
||||||
@@ -2333,7 +2337,7 @@ function! fugitive#glob(url, ...) abort
|
|||||||
call filter(files, 'v:val =~# pattern')
|
call filter(files, 'v:val =~# pattern')
|
||||||
let prepend = s:DirUrlPrefix(dir) . substitute(commit, '^:', '', '') . '/'
|
let prepend = s:DirUrlPrefix(dir) . substitute(commit, '^:', '', '') . '/'
|
||||||
call sort(files)
|
call sort(files)
|
||||||
call map(files, 's:VimSlash(prepend . v:val . append)')
|
call map(files, 's:VimSlash(s:PathJoin(prepend, v:val . append))')
|
||||||
call extend(results, files)
|
call extend(results, files)
|
||||||
endfor
|
endfor
|
||||||
if a:0 > 1 && a:2
|
if a:0 > 1 && a:2
|
||||||
@@ -5610,7 +5614,7 @@ function! s:GrepParseLine(options, quiet, dir, line) abort
|
|||||||
return {'text': a:line}
|
return {'text': a:line}
|
||||||
endif
|
endif
|
||||||
if entry.module !~# ':'
|
if entry.module !~# ':'
|
||||||
let entry.filename = a:options.prefix . entry.module
|
let entry.filename = s:PathJoin(a:options.prefix, entry.module)
|
||||||
else
|
else
|
||||||
let entry.filename = fugitive#Find(entry.module, a:dir)
|
let entry.filename = fugitive#Find(entry.module, a:dir)
|
||||||
endif
|
endif
|
||||||
@@ -5811,7 +5815,7 @@ function! s:LogParse(state, dir, prefix, line) abort
|
|||||||
let a:state.queue = [{
|
let a:state.queue = [{
|
||||||
\ 'valid': 1,
|
\ 'valid': 1,
|
||||||
\ 'context': context,
|
\ 'context': context,
|
||||||
\ 'filename': a:state.base . a:state.target,
|
\ 'filename': s:PathJoin(a:state.base, a:state.target),
|
||||||
\ 'module': a:state.base_module . substitute(a:state.target, '^/', ':', ''),
|
\ 'module': a:state.base_module . substitute(a:state.target, '^/', ':', ''),
|
||||||
\ 'text': a:state.message}]
|
\ 'text': a:state.message}]
|
||||||
let a:state.child_found = 0
|
let a:state.child_found = 0
|
||||||
|
|||||||
Reference in New Issue
Block a user