From 24fd3d9599b70e29e1ebc29a64a121a77ab6a031 Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Tue, 3 Aug 2021 11:43:31 -0400 Subject: [PATCH] Eliminate use of ":write !" This is a prerequisite of eliminating the use of the shell in favor of direct execution via jobs. --- autoload/fugitive.vim | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/autoload/fugitive.vim b/autoload/fugitive.vim index cbe340d..9816233 100644 --- a/autoload/fugitive.vim +++ b/autoload/fugitive.vim @@ -2369,7 +2369,7 @@ function! fugitive#FileReadCmd(...) abort endfunction function! fugitive#FileWriteCmd(...) abort - let tmp = tempname() + let temp = tempname() let amatch = a:0 ? a:1 : expand('') let autype = a:0 > 1 ? 'Buf' : 'File' if exists('#' . autype . 'WritePre') @@ -2380,17 +2380,13 @@ function! fugitive#FileWriteCmd(...) abort if commit !~# '^[0-3]$' || !v:cmdbang && (line("'[") != 1 || line("']") != line('$')) return "noautocmd '[,']write" . (v:cmdbang ? '!' : '') . ' ' . s:fnameescape(amatch) endif - if exists('+guioptions') && &guioptions =~# '!' - let guioptions = &guioptions - set guioptions-=! - endif - silent execute "'[,']write !".fugitive#Prepare(dir, 'hash-object', '-w', '--stdin', '--').' > '.tmp - let sha1 = readfile(tmp)[0] + silent execute "noautocmd keepalt '[,']write ".temp + let hash = s:TreeChomp([dir, 'hash-object', '-w', '--', temp]) let old_mode = matchstr(s:ChompError(['ls-files', '--stage', '.' . file], dir)[0], '^\d\+') if empty(old_mode) let old_mode = executable(s:Tree(dir) . file) ? '100755' : '100644' endif - let error = s:UpdateIndex(dir, [old_mode, sha1, commit, file[1:-1]]) + let error = s:UpdateIndex(dir, [old_mode, hash, commit, file[1:-1]]) if empty(error) setlocal nomodified if exists('#' . autype . 'WritePost') @@ -2400,11 +2396,10 @@ function! fugitive#FileWriteCmd(...) abort else return 'echoerr '.string('fugitive: '.error) endif + catch /^fugitive:/ + return 'echoerr ' . string(v:exception) finally - if exists('guioptions') - let &guioptions = guioptions - endif - call delete(tmp) + call delete(temp) endtry endfunction