mirror of
https://github.com/tpope/vim-fugitive.git
synced 2025-11-13 13:53:51 -05:00
Provide function for preparing Git shell command
This commit is contained in:
@@ -91,12 +91,21 @@ function! s:executable(binary) abort
|
|||||||
return s:executables[a:binary]
|
return s:executables[a:binary]
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
let s:git_versions = {}
|
|
||||||
|
|
||||||
function! s:git_command() abort
|
function! s:git_command() abort
|
||||||
return get(g:, 'fugitive_git_command', g:fugitive_git_executable)
|
return get(g:, 'fugitive_git_command', g:fugitive_git_executable)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! fugitive#Prepare(...) abort
|
||||||
|
let args = copy(a:000)
|
||||||
|
if empty(args)
|
||||||
|
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
|
||||||
|
|
||||||
|
let s:git_versions = {}
|
||||||
function! fugitive#GitVersion(...) abort
|
function! fugitive#GitVersion(...) abort
|
||||||
if !has_key(s:git_versions, g:fugitive_git_executable)
|
if !has_key(s:git_versions, g:fugitive_git_executable)
|
||||||
let s:git_versions[g:fugitive_git_executable] = matchstr(system(g:fugitive_git_executable.' --version'), "\\S\\+\\ze\n")
|
let s:git_versions[g:fugitive_git_executable] = matchstr(system(g:fugitive_git_executable.' --version'), "\\S\\+\\ze\n")
|
||||||
@@ -323,9 +332,7 @@ function! s:repo_git_command(...) dict abort
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:repo_git_chomp(...) dict abort
|
function! s:repo_git_chomp(...) dict abort
|
||||||
let git = g:fugitive_git_executable . ' --git-dir='.s:shellesc(self.git_dir)
|
return s:sub(system(call('fugitive#Prepare', [self.git_dir] + a:000)),'\n$','')
|
||||||
let output = git.join(map(copy(a:000),'" ".s:shellesc(v:val)'),'')
|
|
||||||
return s:sub(system(output),'\n$','')
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:repo_git_chomp_in_tree(...) dict abort
|
function! s:repo_git_chomp_in_tree(...) dict abort
|
||||||
@@ -467,7 +474,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 = g:fugitive_git_executable . ' --git-dir=' . s:shellesc(a:dir)
|
let git = fugitive#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')
|
||||||
@@ -560,7 +567,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(g:fugitive_git_executable . ' ' . s:shellesc('--git-dir=' . dir) . ' cat-file -s ' . entry[3])
|
let size = +system(fugitive#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]
|
||||||
@@ -586,8 +593,7 @@ function! fugitive#readfile(url, ...) abort
|
|||||||
return []
|
return []
|
||||||
endif
|
endif
|
||||||
let [dir, rev] = s:DirRev(a:url)
|
let [dir, rev] = s:DirRev(a:url)
|
||||||
let cmd = g:fugitive_git_executable . ' --git-dir=' . s:shellesc(dir) .
|
let cmd = fugitive#Prepare(dir, 'cat-file', 'blob', rev)
|
||||||
\ ' cat-file blob ' . s:shellesc(rev)
|
|
||||||
if max > 0 && s:executable('head')
|
if max > 0 && s:executable('head')
|
||||||
let cmd .= '|head -' . max
|
let cmd .= '|head -' . max
|
||||||
endif
|
endif
|
||||||
|
|||||||
Reference in New Issue
Block a user