Encapsulate update-index --index-info

This commit is contained in:
Tim Pope
2020-04-08 03:38:58 -04:00
parent 792f51a58b
commit 53dd9b3957

View File

@@ -1316,6 +1316,12 @@ function! fugitive#getfperm(url) abort
return perm ==# '---------' ? '' : perm
endfunction
function s:UpdateIndex(dir, info) abort
let info = join(a:info[0:-2]) . "\t" . a:info[-1] . "\n"
let [error, exec_error] = s:SystemError([a:dir, 'update-index', '--index-info'], info)
return !exec_error ? '' : len(error) ? error : 'fugitive: unknown update-index error'
endfunction
function! fugitive#setfperm(url, perm) abort
let [dir, commit, file] = s:DirCommitFile(a:url)
let entry = s:PathInfo(a:url)
@@ -1324,9 +1330,8 @@ function! fugitive#setfperm(url, perm) abort
\ substitute(perm, 'x', '-', 'g') !=# substitute(a:perm, 'x', '-', 'g')
return -2
endif
let exec_error = s:SystemError([dir, 'update-index', '--index-info'],
\ (a:perm =~# 'x' ? '000755 ' : '000644 ') . entry[3] . ' ' . commit . "\t" . file[1:-1])[1]
return exec_error ? -1 : 0
let error = s:UpdateIndex(dir, [a:perm =~# 'x' ? '000755' : '000644', entry[3], commit, file[1:-1]])
return len(error) ? -1 : 0
endfunction
function! s:TempCmd(out, cmd) abort
@@ -1396,9 +1401,8 @@ function! fugitive#writefile(lines, url, ...) abort
let [hash, exec_error] = s:ChompError([dir, 'hash-object', '-w', temp])
let mode = len(entry[1]) ? entry[1] : '100644'
if !exec_error && hash =~# '^\x\{40,\}$'
let exec_error = s:SystemError([dir, 'update-index', '--index-info'],
\ mode . ' ' . hash . ' ' . commit . "\t" . file[1:-1])[1]
if !exec_error
let error = s:UpdateIndex(dir, [mode, hash, commit, file[1:-1]])
if empty(error)
return 0
endif
endif
@@ -1451,9 +1455,8 @@ function! fugitive#delete(url, ...) abort
if entry[2] !=# 'blob'
return -1
endif
let exec_error = s:SystemError([dir, 'update-index', '--index-info'],
\ '000000 0000000000000000000000000000000000000000 ' . commit . "\t" . file[1:-1])[1]
return exec_error ? -1 : 0
let error = s:UpdateIndex(dir, ['000000', '0000000000000000000000000000000000000000', commit, file[1:-1]])
return len(error) ? -1 : 0
endfunction
" Section: Buffer Object
@@ -2050,9 +2053,8 @@ function! fugitive#FileWriteCmd(...) abort
if empty(old_mode)
let old_mode = executable(s:Tree(dir) . file) ? '100755' : '100644'
endif
let info = old_mode.' '.sha1.' '.commit."\t".file[1:-1]
let [error, exec_error] = s:SystemError([dir, 'update-index', '--index-info'], info . "\n")
if !exec_error
let error = s:UpdateIndex(dir, [old_mode, sha1, commit, file[1:-1]])
if empty(error)
setlocal nomodified
if exists('#' . autype . 'WritePost')
execute s:DoAutocmd(autype . 'WritePost ' . s:fnameescape(amatch))