Make fugitive#Prepare() private

This commit is contained in:
Tim Pope
2018-07-28 19:54:35 -04:00
parent deaf4aa139
commit 035cdf44e8

View File

@@ -106,14 +106,9 @@ function! s:System(cmd) abort
endtry endtry
endfunction endfunction
function! fugitive#Prepare(...) abort function! s:Prepare(dir, ...) abort
let args = copy(a:000) let args = ['--git-dir=' . a:dir] + (a:000)
if empty(args) return g:fugitive_git_executable . ' ' . join(map(args, 's:shellesc(v:val)'))
return g:fugitive_git_executable
elseif args[0] !~# '^-' && args[0] =~# '[\/.]\|^$'
let args[0] = '--git-dir=' . args[0]
endif
return g:fugitive_git_executable . ' ' . join(map(args, 's:shellesc(v:val)'), ' ')
endfunction endfunction
let s:git_versions = {} let s:git_versions = {}
@@ -137,11 +132,12 @@ function! s:TreeChomp(...) abort
let args = ['-C', tree] + args let args = ['-C', tree] + args
endif endif
endif endif
return s:sub(s:System(pre . call('fugitive#Prepare', args)),'\n$','') return s:sub(s:System(pre . g:fugitive_git_executable . ' ' .
\ join(map(args, 's:shellesc(v:val)'))), '\n$', '')
endfunction endfunction
function! fugitive#Config(name, ...) abort function! fugitive#Config(name, ...) abort
let cmd = fugitive#Prepare(a:0 ? a:1 : get(b:, 'git_dir', ''), 'config', '--get', a:name) let cmd = s:Prepare(a:0 ? a:1 : get(b:, 'git_dir', ''), 'config', '--get', a:name)
let out = matchstr(system(cmd), "[^\r\n]*") let out = matchstr(system(cmd), "[^\r\n]*")
return v:shell_error ? '' : out return v:shell_error ? '' : out
endfunction endfunction
@@ -164,7 +160,7 @@ function! fugitive#RemoteUrl(...) abort
if fugitive#GitVersion() =~# '^[01]\.\|^2\.[0-6]\.' if fugitive#GitVersion() =~# '^[01]\.\|^2\.[0-6]\.'
return fugitive#Config('remote.' . remote . '.url') return fugitive#Config('remote.' . remote . '.url')
endif endif
let cmd = fugitive#Prepare(dir, 'remote', 'get-url', remote) let cmd = s:Prepare(dir, 'remote', 'get-url', remote)
let out = substitute(system(cmd), "\n$", '', '') let out = substitute(system(cmd), "\n$", '', '')
return v:shell_error ? '' : out return v:shell_error ? '' : out
endfunction endfunction
@@ -365,7 +361,7 @@ function! s:repo_translate(spec, ...) dict abort
let commit = substitute(matchstr(rev,'^[^:]\+\|^:.*'), '^@\%($|[^~]\)\@=', 'HEAD', '') let commit = substitute(matchstr(rev,'^[^:]\+\|^:.*'), '^@\%($|[^~]\)\@=', 'HEAD', '')
let file = substitute(matchstr(rev, '^[^:]\+\zs:.*'), '^:', '/', '') let file = substitute(matchstr(rev, '^[^:]\+\zs:.*'), '^:', '/', '')
if commit !~# '^[0-9a-f]\{40\}$' if commit !~# '^[0-9a-f]\{40\}$'
let commit = system(fugitive#Prepare(dir, 'rev-parse', '--verify', commit))[0:-2] let commit = system(s:Prepare(dir, 'rev-parse', '--verify', commit))[0:-2]
let commit = v:shell_error ? '' : commit let commit = v:shell_error ? '' : commit
endif endif
if len(commit) if len(commit)
@@ -409,7 +405,7 @@ function! s:repo_git_command(...) dict abort
endfunction endfunction
function! s:repo_git_chomp(...) dict abort function! s:repo_git_chomp(...) dict abort
return s:sub(s:System(call('fugitive#Prepare', [self.git_dir] + a:000)),'\n$','') return s:sub(s:System(call('s:Prepare', [self.git_dir] + a:000)),'\n$','')
endfunction endfunction
function! s:repo_git_chomp_in_tree(...) dict abort function! s:repo_git_chomp_in_tree(...) dict abort
@@ -544,7 +540,7 @@ endfunction
let s:trees = {} let s:trees = {}
let s:indexes = {} let s:indexes = {}
function! s:TreeInfo(dir, commit) abort function! s:TreeInfo(dir, commit) abort
let git = fugitive#Prepare(a:dir) let git = s:Prepare(a:dir)
if a:commit =~# '^:\=[0-3]$' if a:commit =~# '^:\=[0-3]$'
let index = get(s:indexes, a:dir, []) let index = get(s:indexes, a:dir, [])
let newftime = getftime(a:dir . '/index') let newftime = getftime(a:dir . '/index')
@@ -637,7 +633,7 @@ function! fugitive#getfsize(url) abort
let entry = s:PathInfo(a:url) let entry = s:PathInfo(a:url)
if entry[4] == -2 && entry[2] ==# 'blob' && len(entry[3]) if entry[4] == -2 && entry[2] ==# 'blob' && len(entry[3])
let dir = s:DirCommitFile(a:url)[0] let dir = s:DirCommitFile(a:url)[0]
let size = +system(fugitive#Prepare(dir, 'cat-file', '-s', entry[3])) let size = +system(s:Prepare(dir, 'cat-file', '-s', entry[3]))
let entry[4] = v:shell_error ? -1 : size let entry[4] = v:shell_error ? -1 : size
endif endif
return entry[4] return entry[4]
@@ -690,7 +686,7 @@ 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
call system(fugitive#Prepare(dir, 'update-index', '--index-info'), call system(s:Prepare(dir, 'update-index', '--index-info'),
\ (a:perm =~# 'x' ? '000755 ' : '000644 ') . entry[3] . ' ' . commit . "\t" . file[1:-1]) \ (a:perm =~# 'x' ? '000755 ' : '000644 ') . entry[3] . ' ' . commit . "\t" . file[1:-1])
return v:shell_error ? -1 : 0 return v:shell_error ? -1 : 0
endfunction endfunction
@@ -698,7 +694,7 @@ endfunction
function! s:TempCmd(out, cmd) abort function! s:TempCmd(out, cmd) abort
let prefix = '' let prefix = ''
try try
let cmd = (type(a:cmd) == type([]) ? call('fugitive#Prepare', a:cmd) : a:cmd) let cmd = (type(a:cmd) == type([]) ? call('s:Prepare', a:cmd) : a:cmd)
let redir = ' > ' . a:out let redir = ' > ' . a:out
if s:winshell() if s:winshell()
let cmd_escape_char = &shellxquote == '(' ? '^' : '^^^' let cmd_escape_char = &shellxquote == '(' ? '^' : '^^^'
@@ -729,7 +725,7 @@ function! s:BlobTemp(url) abort
endif endif
if commit =~# '^\d$' || !filereadable(tempfile) if commit =~# '^\d$' || !filereadable(tempfile)
let rev = s:DirRev(a:url)[1] let rev = s:DirRev(a:url)[1]
let command = fugitive#Prepare(dir, 'cat-file', 'blob', rev) let command = s:Prepare(dir, 'cat-file', 'blob', rev)
call s:TempCmd(tempfile, command) call s:TempCmd(tempfile, command)
if v:shell_error if v:shell_error
call delete(tempfile) call delete(tempfile)
@@ -761,10 +757,10 @@ function! fugitive#writefile(lines, url, ...) abort
call writefile(fugitive#readfile(url, 'b'), temp, 'b') call writefile(fugitive#readfile(url, 'b'), temp, 'b')
endif endif
call call('writefile', [a:lines, temp] + a:000) call call('writefile', [a:lines, temp] + a:000)
let hash = system(fugitive#Prepare(dir, 'hash-object', '-w', temp))[0:-2] let hash = system(s:Prepare(dir, 'hash-object', '-w', temp))[0:-2]
let mode = len(entry[1]) ? entry[1] : '100644' let mode = len(entry[1]) ? entry[1] : '100644'
if !v:shell_error && hash =~# '^\x\{40\}$' if !v:shell_error && hash =~# '^\x\{40\}$'
call system(fugitive#Prepare(dir, 'update-index', '--index-info'), call system(s:Prepare(dir, 'update-index', '--index-info'),
\ mode . ' ' . hash . ' ' . commit . "\t" . file[1:-1]) \ mode . ' ' . hash . ' ' . commit . "\t" . file[1:-1])
if !v:shell_error if !v:shell_error
return 0 return 0
@@ -812,7 +808,7 @@ function! fugitive#delete(url, ...) abort
if entry[2] !=# 'blob' if entry[2] !=# 'blob'
return -1 return -1
endif endif
call system(fugitive#Prepare(dir, 'update-index', '--index-info'), call system(s:Prepare(dir, 'update-index', '--index-info'),
\ '000000 0000000000000000000000000000000000000000 ' . commit . "\t" . file[1:-1]) \ '000000 0000000000000000000000000000000000000000 ' . commit . "\t" . file[1:-1])
return v:shell_error ? -1 : 0 return v:shell_error ? -1 : 0
endfunction endfunction
@@ -2328,7 +2324,7 @@ function! s:Blame(bang, line1, line2, count, mods, args) abort
let cmd += ['--contents', '-'] let cmd += ['--contents', '-']
endif endif
let cmd += ['--', s:Relative('')] let cmd += ['--', s:Relative('')]
let basecmd = escape(call('fugitive#Prepare', cmd), '!#%') let basecmd = escape(call('s:Prepare', cmd), '!#%')
try try
let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd' : 'cd' let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd' : 'cd'
let tree = FugitiveTreeForGitDir(b:git_dir) let tree = FugitiveTreeForGitDir(b:git_dir)
@@ -2805,7 +2801,7 @@ function! fugitive#BufReadStatus() abort
endif endif
let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd' : 'cd' let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd' : 'cd'
let cwd = getcwd() let cwd = getcwd()
let cmd_str = prefix . call('fugitive#Prepare', [dir] + cmd) let cmd_str = prefix . call('s:Prepare', [dir] + cmd)
try try
if exists('old_index') if exists('old_index')
let $GIT_INDEX_FILE = amatch let $GIT_INDEX_FILE = amatch
@@ -2879,9 +2875,9 @@ function! fugitive#FileReadCmd(...) abort
return 'noautocmd ' . line . 'read ' . s:fnameescape(amatch) return 'noautocmd ' . line . 'read ' . s:fnameescape(amatch)
endif endif
if rev !~# ':' if rev !~# ':'
let cmd = fugitive#Prepare(dir, 'log', '--pretty=format:%B', '-1', rev) let cmd = s:Prepare(dir, 'log', '--pretty=format:%B', '-1', rev)
else else
let cmd = fugitive#Prepare(dir, 'cat-file', '-p', rev) let cmd = s:Prepare(dir, 'cat-file', '-p', rev)
endif endif
return line . 'read !' . escape(cmd, '!#%') return line . 'read !' . escape(cmd, '!#%')
endfunction endfunction
@@ -2898,18 +2894,18 @@ function! fugitive#FileWriteCmd(...) abort
if commit !~# '^[0-3]$' || !v:cmdbang && (line("'[") != 1 || line("']") != line('$')) if commit !~# '^[0-3]$' || !v:cmdbang && (line("'[") != 1 || line("']") != line('$'))
return "noautocmd '[,']write" . (v:cmdbang ? '!' : '') . ' ' . s:fnameescape(amatch) return "noautocmd '[,']write" . (v:cmdbang ? '!' : '') . ' ' . s:fnameescape(amatch)
endif endif
silent execute "'[,']write !".fugitive#Prepare(dir, 'hash-object', '-w', '--stdin').' > '.tmp silent execute "'[,']write !".s:Prepare(dir, 'hash-object', '-w', '--stdin').' > '.tmp
let sha1 = readfile(tmp)[0] let sha1 = readfile(tmp)[0]
let old_mode = matchstr(system(fugitive#Prepare(dir, 'ls-files', '--stage', file[1:-1])), '^\d\+') let old_mode = matchstr(system(s:Prepare(dir, 'ls-files', '--stage', file[1:-1])), '^\d\+')
if old_mode == '' if old_mode == ''
let old_mode = executable(FugitiveTreeForGitDir(dir) . file) ? '100755' : '100644' let old_mode = executable(FugitiveTreeForGitDir(dir) . file) ? '100755' : '100644'
endif endif
let info = old_mode.' '.sha1.' '.commit."\t".file[1:-1] let info = old_mode.' '.sha1.' '.commit."\t".file[1:-1]
call writefile([info],tmp) call writefile([info],tmp)
if s:winshell() if s:winshell()
let error = s:System('type '.s:gsub(tmp,'/','\\').'|'.fugitive#Prepare(dir, 'update-index', '--index-info')) let error = s:System('type '.s:gsub(tmp,'/','\\').'|'.s:Prepare(dir, 'update-index', '--index-info'))
else else
let error = s:System(fugitive#Prepare(dir, 'update-index', '--index-info').' < '.tmp) let error = s:System(s:Prepare(dir, 'update-index', '--index-info').' < '.tmp)
endif endif
if v:shell_error == 0 if v:shell_error == 0
setlocal nomodified setlocal nomodified
@@ -2933,7 +2929,7 @@ function! fugitive#BufReadCmd(...) abort
if empty(dir) if empty(dir)
return 'echo "Invalid Fugitive URL"' return 'echo "Invalid Fugitive URL"'
endif endif
let b:fugitive_type = system(fugitive#Prepare(dir, 'cat-file', '-t', rev))[0:-2] let b:fugitive_type = system(s:Prepare(dir, 'cat-file', '-t', rev))[0:-2]
if v:shell_error if v:shell_error
unlet b:fugitive_type unlet b:fugitive_type
return 'silent doautocmd BufNewFile '.s:fnameescape(amatch) return 'silent doautocmd BufNewFile '.s:fnameescape(amatch)
@@ -2959,7 +2955,7 @@ function! fugitive#BufReadCmd(...) abort
if b:fugitive_display_format if b:fugitive_display_format
call s:ReplaceCmd([dir, 'ls-tree', rev]) call s:ReplaceCmd([dir, 'ls-tree', rev])
else else
let sha = system(fugitive#Prepare(dir, 'rev-parse', '--verify', rev))[0:-2] let sha = system(s:Prepare(dir, 'rev-parse', '--verify', rev))[0:-2]
call s:ReplaceCmd([dir, 'show', '--no-color', sha]) call s:ReplaceCmd([dir, 'show', '--no-color', sha])
endif endif
elseif b:fugitive_type ==# 'tag' elseif b:fugitive_type ==# 'tag'