Skip to content

Commit

Permalink
Add FugitiveFilename() to determine corresponding real file
Browse files Browse the repository at this point in the history
  • Loading branch information
tpope committed Jun 14, 2018
1 parent b571bff commit cc9d8d9
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
27 changes: 27 additions & 0 deletions autoload/fugitive.vim
Expand Up @@ -66,6 +66,14 @@ function! s:shellslash(path) abort
endif
endfunction

function! s:PlatformSlash(path) abort
if exists('+shellslash') && !&shellslash
return tr(a:path, '/', '\')
else
return a:path
endif
endfunction

let s:executables = {}

function! s:executable(binary) abort
Expand Down Expand Up @@ -429,6 +437,25 @@ call s:add_methods('repo',['keywordprg'])

" Section: Buffer

function! s:UrlSplit(path) abort
let vals = matchlist(s:shellslash(a:path), '\c^fugitive://\(.\{-\}\)//\(\w\+\)\(/.*\)\=$')
if empty(vals)
return ['', '', '']
endif
return [vals[1], (vals[2] =~# '^.$' ? ':' : '') . vals[2], vals[3]]
endfunction

function! fugitive#Filename(url) abort
let [dir, rev, file] = s:UrlSplit(a:url)
if len(dir)
return s:PlatformSlash(FugitiveTreeForGitDir(dir) . file)
elseif a:url =~# '^[\\/]\|^\a:[\\/]'
return s:PlatformSlash(a:url)
else
return ''
endif
endfunction

let s:buffer_prototype = {}

function! s:buffer(...) abort
Expand Down
9 changes: 9 additions & 0 deletions plugin/fugitive.vim
Expand Up @@ -138,6 +138,15 @@ function! FugitiveHead(...) abort
return fugitive#repo().head(a:0 ? a:1 : 0)
endfunction

function! FugitiveFilename(...) abort
let file = fnamemodify(a:0 ? a:1 : @%, ':p')
if file =~? '^fugitive:'
return fugitive#Filename(file)
else
return file
endif
endfunction

augroup fugitive
autocmd!

Expand Down

0 comments on commit cc9d8d9

Please sign in to comment.