mirror of
https://github.com/tpope/vim-fugitive.git
synced 2025-11-13 22:03:51 -05:00
Resolve temp files only when using as buffer name
Closes https://github.com/tpope/vim-fugitive/issues/1078
This commit is contained in:
@@ -61,14 +61,6 @@ function! s:fnameescape(file) abort
|
|||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:tempname() abort
|
|
||||||
let temp = resolve(tempname())
|
|
||||||
if has('win32')
|
|
||||||
let temp = fnamemodify(fnamemodify(temp, ':h'), ':p').fnamemodify(temp, ':t')
|
|
||||||
endif
|
|
||||||
return temp
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! s:throw(string) abort
|
function! s:throw(string) abort
|
||||||
let v:errmsg = 'fugitive: '.a:string
|
let v:errmsg = 'fugitive: '.a:string
|
||||||
throw v:errmsg
|
throw v:errmsg
|
||||||
@@ -97,6 +89,14 @@ function! s:PlatformSlash(path) abort
|
|||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! s:Resolve(path) abort
|
||||||
|
let path = resolve(a:path)
|
||||||
|
if has('win32')
|
||||||
|
let path = s:PlatformSlash(fnamemodify(fnamemodify(path, ':h'), ':p') . fnamemodify(path, ':t'))
|
||||||
|
endif
|
||||||
|
return path
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! s:cpath(path, ...) abort
|
function! s:cpath(path, ...) abort
|
||||||
if exists('+fileignorecase') && &fileignorecase
|
if exists('+fileignorecase') && &fileignorecase
|
||||||
let path = s:PlatformSlash(tolower(a:path))
|
let path = s:PlatformSlash(tolower(a:path))
|
||||||
@@ -858,9 +858,9 @@ function! s:BlobTemp(url) abort
|
|||||||
return ''
|
return ''
|
||||||
endif
|
endif
|
||||||
if !has_key(s:blobdirs, dir)
|
if !has_key(s:blobdirs, dir)
|
||||||
let s:blobdirs[dir] = s:tempname()
|
let s:blobdirs[dir] = tempname()
|
||||||
endif
|
endif
|
||||||
let tempfile = s:PlatformSlash(s:blobdirs[dir] . '/' . commit . file)
|
let tempfile = s:blobdirs[dir] . '/' . commit . file
|
||||||
let tempparent = fnamemodify(tempfile, ':h')
|
let tempparent = fnamemodify(tempfile, ':h')
|
||||||
if !isdirectory(tempparent)
|
if !isdirectory(tempparent)
|
||||||
call mkdir(tempparent, 'p')
|
call mkdir(tempparent, 'p')
|
||||||
@@ -874,7 +874,7 @@ function! s:BlobTemp(url) abort
|
|||||||
return ''
|
return ''
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
return tempfile
|
return s:Resolve(tempfile)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! fugitive#readfile(url, ...) abort
|
function! fugitive#readfile(url, ...) abort
|
||||||
@@ -894,7 +894,7 @@ function! fugitive#writefile(lines, url, ...) abort
|
|||||||
let [dir, commit, file] = s:DirCommitFile(url)
|
let [dir, commit, file] = s:DirCommitFile(url)
|
||||||
let entry = s:PathInfo(url)
|
let entry = s:PathInfo(url)
|
||||||
if commit =~# '^\d$' && entry[2] !=# 'tree'
|
if commit =~# '^\d$' && entry[2] !=# 'tree'
|
||||||
let temp = s:tempname()
|
let temp = tempname()
|
||||||
if a:0 && a:1 =~# 'a' && entry[2] ==# 'blob'
|
if a:0 && a:1 =~# 'a' && entry[2] ==# 'blob'
|
||||||
call writefile(fugitive#readfile(url, 'b'), temp, 'b')
|
call writefile(fugitive#readfile(url, 'b'), temp, 'b')
|
||||||
endif
|
endif
|
||||||
@@ -1158,14 +1158,15 @@ endfunction
|
|||||||
" Section: Buffer auto-commands
|
" Section: Buffer auto-commands
|
||||||
|
|
||||||
function! s:ReplaceCmd(cmd) abort
|
function! s:ReplaceCmd(cmd) abort
|
||||||
let tmp = tempname()
|
let temp = tempname()
|
||||||
let err = s:TempCmd(tmp, a:cmd)
|
let err = s:TempCmd(temp, a:cmd)
|
||||||
if v:shell_error
|
if v:shell_error
|
||||||
call s:throw((len(err) ? err : filereadable(tmp) ? join(readfile(tmp), ' ') : 'unknown error running ' . a:cmd))
|
call s:throw((len(err) ? err : filereadable(temp) ? join(readfile(temp), ' ') : 'unknown error running ' . a:cmd))
|
||||||
endif
|
endif
|
||||||
|
let temp = s:Resolve(temp)
|
||||||
let fn = expand('%:p')
|
let fn = expand('%:p')
|
||||||
silent exe 'doau BufReadPre '.s:fnameescape(fn)
|
silent exe 'doau BufReadPre '.s:fnameescape(fn)
|
||||||
silent exe 'keepalt file '.tmp
|
silent exe 'keepalt file '.temp
|
||||||
try
|
try
|
||||||
silent noautocmd edit!
|
silent noautocmd edit!
|
||||||
finally
|
finally
|
||||||
@@ -1173,8 +1174,8 @@ function! s:ReplaceCmd(cmd) abort
|
|||||||
silent exe 'keepalt file '.s:fnameescape(fn)
|
silent exe 'keepalt file '.s:fnameescape(fn)
|
||||||
catch /^Vim\%((\a\+)\)\=:E302:/
|
catch /^Vim\%((\a\+)\)\=:E302:/
|
||||||
endtry
|
endtry
|
||||||
call delete(tmp)
|
call delete(temp)
|
||||||
if fnamemodify(bufname('$'), ':p') ==# tmp
|
if s:cpath(fnamemodify(bufname('$'), ':p'), temp)
|
||||||
silent execute 'bwipeout '.bufnr('$')
|
silent execute 'bwipeout '.bufnr('$')
|
||||||
endif
|
endif
|
||||||
silent exe 'doau BufReadPost '.s:fnameescape(fn)
|
silent exe 'doau BufReadPost '.s:fnameescape(fn)
|
||||||
@@ -2276,7 +2277,7 @@ function! s:Edit(cmd, bang, mods, args, ...) abort
|
|||||||
let mods = a:mods ==# '<mods>' ? '' : a:mods
|
let mods = a:mods ==# '<mods>' ? '' : a:mods
|
||||||
|
|
||||||
if a:bang
|
if a:bang
|
||||||
let temp = s:tempname()
|
let temp = tempname()
|
||||||
let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd' : 'cd'
|
let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd' : 'cd'
|
||||||
let cwd = getcwd()
|
let cwd = getcwd()
|
||||||
try
|
try
|
||||||
@@ -2288,6 +2289,7 @@ function! s:Edit(cmd, bang, mods, args, ...) abort
|
|||||||
finally
|
finally
|
||||||
execute cd s:fnameescape(cwd)
|
execute cd s:fnameescape(cwd)
|
||||||
endtry
|
endtry
|
||||||
|
let temp = s:Resolve(temp)
|
||||||
let s:temp_files[s:cpath(temp)] = { 'dir': b:git_dir, 'filetype': 'git' }
|
let s:temp_files[s:cpath(temp)] = { 'dir': b:git_dir, 'filetype': 'git' }
|
||||||
if a:cmd ==# 'edit'
|
if a:cmd ==# 'edit'
|
||||||
call s:BlurStatus()
|
call s:BlurStatus()
|
||||||
@@ -2903,7 +2905,7 @@ function! s:Blame(bang, line1, line2, count, mods, args) abort
|
|||||||
let cwd = getcwd()
|
let cwd = getcwd()
|
||||||
execute cd s:fnameescape(tree)
|
execute cd s:fnameescape(tree)
|
||||||
endif
|
endif
|
||||||
let error = s:tempname()
|
let error = tempname()
|
||||||
let temp = error.'.fugitiveblame'
|
let temp = error.'.fugitiveblame'
|
||||||
if &shell =~# 'csh'
|
if &shell =~# 'csh'
|
||||||
silent! execute '%write !('.basecmd.' > '.temp.') >& '.error
|
silent! execute '%write !('.basecmd.' > '.temp.') >& '.error
|
||||||
@@ -2947,6 +2949,7 @@ function! s:Blame(bang, line1, line2, count, mods, args) abort
|
|||||||
endif
|
endif
|
||||||
let top = line('w0') + &scrolloff
|
let top = line('w0') + &scrolloff
|
||||||
let current = line('.')
|
let current = line('.')
|
||||||
|
let temp = s:Resolve(temp)
|
||||||
let s:temp_files[s:cpath(temp)] = { 'dir': b:git_dir, 'filetype': 'fugitiveblame', 'args': cmd, 'bufnr': bufnr }
|
let s:temp_files[s:cpath(temp)] = { 'dir': b:git_dir, 'filetype': 'fugitiveblame', 'args': cmd, 'bufnr': bufnr }
|
||||||
exe 'keepalt leftabove vsplit '.temp
|
exe 'keepalt leftabove vsplit '.temp
|
||||||
let b:fugitive_blamed_bufnr = bufnr
|
let b:fugitive_blamed_bufnr = bufnr
|
||||||
@@ -3258,9 +3261,9 @@ function! s:Browse(bang,line1,count,...) abort
|
|||||||
let remotehead = cdir . '/refs/remotes/' . remote . '/' . merge
|
let remotehead = cdir . '/refs/remotes/' . remote . '/' . merge
|
||||||
let commit = filereadable(remotehead) ? get(readfile(remotehead), 0, '') : ''
|
let commit = filereadable(remotehead) ? get(readfile(remotehead), 0, '') : ''
|
||||||
if a:count && !a:0 && commit =~# '^\x\{40\}$'
|
if a:count && !a:0 && commit =~# '^\x\{40\}$'
|
||||||
let blame_list = s:tempname()
|
let blame_list = tempname()
|
||||||
call writefile([commit, ''], blame_list, 'b')
|
call writefile([commit, ''], blame_list, 'b')
|
||||||
let blame_in = s:tempname()
|
let blame_in = tempname()
|
||||||
silent exe '%write' blame_in
|
silent exe '%write' blame_in
|
||||||
let blame = split(s:TreeChomp('blame', '--contents', blame_in, '-L', a:line1.','.a:count, '-S', blame_list, '-s', '--show-number', './' . path), "\n")
|
let blame = split(s:TreeChomp('blame', '--contents', blame_in, '-L', a:line1.','.a:count, '-S', blame_list, '-s', '--show-number', './' . path), "\n")
|
||||||
if !v:shell_error
|
if !v:shell_error
|
||||||
|
|||||||
Reference in New Issue
Block a user