mirror of
https://github.com/tpope/vim-fugitive.git
synced 2025-11-15 14:53:51 -05:00
Encapsulate update-index --index-info
This commit is contained in:
@@ -1316,6 +1316,12 @@ function! fugitive#getfperm(url) abort
|
|||||||
return perm ==# '---------' ? '' : perm
|
return perm ==# '---------' ? '' : perm
|
||||||
endfunction
|
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
|
function! fugitive#setfperm(url, perm) abort
|
||||||
let [dir, commit, file] = s:DirCommitFile(a:url)
|
let [dir, commit, file] = s:DirCommitFile(a:url)
|
||||||
let entry = s:PathInfo(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')
|
\ substitute(perm, 'x', '-', 'g') !=# substitute(a:perm, 'x', '-', 'g')
|
||||||
return -2
|
return -2
|
||||||
endif
|
endif
|
||||||
let exec_error = s:SystemError([dir, 'update-index', '--index-info'],
|
let error = s:UpdateIndex(dir, [a:perm =~# 'x' ? '000755' : '000644', entry[3], commit, file[1:-1]])
|
||||||
\ (a:perm =~# 'x' ? '000755 ' : '000644 ') . entry[3] . ' ' . commit . "\t" . file[1:-1])[1]
|
return len(error) ? -1 : 0
|
||||||
return exec_error ? -1 : 0
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:TempCmd(out, cmd) abort
|
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 [hash, exec_error] = s:ChompError([dir, 'hash-object', '-w', temp])
|
||||||
let mode = len(entry[1]) ? entry[1] : '100644'
|
let mode = len(entry[1]) ? entry[1] : '100644'
|
||||||
if !exec_error && hash =~# '^\x\{40,\}$'
|
if !exec_error && hash =~# '^\x\{40,\}$'
|
||||||
let exec_error = s:SystemError([dir, 'update-index', '--index-info'],
|
let error = s:UpdateIndex(dir, [mode, hash, commit, file[1:-1]])
|
||||||
\ mode . ' ' . hash . ' ' . commit . "\t" . file[1:-1])[1]
|
if empty(error)
|
||||||
if !exec_error
|
|
||||||
return 0
|
return 0
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
@@ -1451,9 +1455,8 @@ function! fugitive#delete(url, ...) abort
|
|||||||
if entry[2] !=# 'blob'
|
if entry[2] !=# 'blob'
|
||||||
return -1
|
return -1
|
||||||
endif
|
endif
|
||||||
let exec_error = s:SystemError([dir, 'update-index', '--index-info'],
|
let error = s:UpdateIndex(dir, ['000000', '0000000000000000000000000000000000000000', commit, file[1:-1]])
|
||||||
\ '000000 0000000000000000000000000000000000000000 ' . commit . "\t" . file[1:-1])[1]
|
return len(error) ? -1 : 0
|
||||||
return exec_error ? -1 : 0
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" Section: Buffer Object
|
" Section: Buffer Object
|
||||||
@@ -2050,9 +2053,8 @@ function! fugitive#FileWriteCmd(...) abort
|
|||||||
if empty(old_mode)
|
if empty(old_mode)
|
||||||
let old_mode = executable(s:Tree(dir) . file) ? '100755' : '100644'
|
let old_mode = executable(s:Tree(dir) . file) ? '100755' : '100644'
|
||||||
endif
|
endif
|
||||||
let info = old_mode.' '.sha1.' '.commit."\t".file[1:-1]
|
let error = s:UpdateIndex(dir, [old_mode, sha1, commit, file[1:-1]])
|
||||||
let [error, exec_error] = s:SystemError([dir, 'update-index', '--index-info'], info . "\n")
|
if empty(error)
|
||||||
if !exec_error
|
|
||||||
setlocal nomodified
|
setlocal nomodified
|
||||||
if exists('#' . autype . 'WritePost')
|
if exists('#' . autype . 'WritePost')
|
||||||
execute s:DoAutocmd(autype . 'WritePost ' . s:fnameescape(amatch))
|
execute s:DoAutocmd(autype . 'WritePost ' . s:fnameescape(amatch))
|
||||||
|
|||||||
Reference in New Issue
Block a user