mirror of
https://github.com/tpope/vim-fugitive.git
synced 2025-11-08 11:33:47 -05:00
Dogfood fugitive#Prepare()
This commit is contained in:
@@ -161,13 +161,8 @@ function! s:UserCommand() abort
|
||||
return get(g:, 'fugitive_git_command', g:fugitive_git_executable)
|
||||
endfunction
|
||||
|
||||
function! s:Prepare(dir, ...) abort
|
||||
if type(a:dir) == type([])
|
||||
let args = ['--git-dir=' . (a:0 ? a:1 : get(b:, 'git_dir', ''))] + a:dir
|
||||
else
|
||||
let args = ['--git-dir=' . a:dir] + (a:000)
|
||||
endif
|
||||
return g:fugitive_git_executable . ' ' . join(map(args, 's:shellesc(v:val)'))
|
||||
function! s:Prepare(...) abort
|
||||
return call('fugitive#Prepare', a:000)
|
||||
endfunction
|
||||
|
||||
let s:git_versions = {}
|
||||
@@ -225,25 +220,6 @@ function! s:PreparePathArgs(cmd, dir, literal) abort
|
||||
return a:cmd
|
||||
endfunction
|
||||
|
||||
function! s:TreeChomp(...) abort
|
||||
let args = copy(type(a:1) == type([]) ? a:1 : a:000)
|
||||
let dir = a:0 > 1 && type(a:1) == type([]) ? a:2 : b:git_dir
|
||||
call s:PreparePathArgs(args, dir, 1)
|
||||
let tree = s:Tree(dir)
|
||||
let pre = ''
|
||||
if empty(tree)
|
||||
let args = ['--git-dir=' . dir] + args
|
||||
elseif s:cpath(tree) !=# s:cpath(getcwd())
|
||||
if fugitive#GitVersion() =~# '^[01]\.'
|
||||
let pre = 'cd ' . s:shellesc(tree) . (s:winshell() ? ' & ' : '; ')
|
||||
else
|
||||
let args = ['-C', tree] + args
|
||||
endif
|
||||
endif
|
||||
return s:sub(s:System(pre . g:fugitive_git_executable . ' ' .
|
||||
\ join(map(args, 's:shellesc(v:val)'))), '\n$', '')
|
||||
endfunction
|
||||
|
||||
let s:prepare_env = {
|
||||
\ 'sequence.editor': 'GIT_SEQUENCE_EDITOR',
|
||||
\ 'core.editor': 'GIT_EDITOR',
|
||||
@@ -310,6 +286,10 @@ function! fugitive#Prepare(...) abort
|
||||
return pre . g:fugitive_git_executable . ' ' . args
|
||||
endfunction
|
||||
|
||||
function! s:TreeChomp(...) abort
|
||||
return s:sub(s:System(call('fugitive#Prepare', a:000)), '\n$', '')
|
||||
endfunction
|
||||
|
||||
function! fugitive#Head(...) abort
|
||||
let dir = a:0 > 1 ? a:2 : get(b:, 'git_dir', '')
|
||||
if empty(dir) || !filereadable(dir . '/HEAD')
|
||||
@@ -335,8 +315,8 @@ function! fugitive#RevParse(rev, ...) abort
|
||||
endfunction
|
||||
|
||||
function! fugitive#Config(name, ...) abort
|
||||
let cmd = s:Prepare(a:0 ? a:1 : get(b:, 'git_dir', ''), 'config', '--get', a:name)
|
||||
let out = matchstr(system(cmd), "[^\r\n]*")
|
||||
let cmd = fugitive#Prepare(a:0 ? a:1 : get(b:, 'git_dir', ''), '--no-literal-pathspecs', 'config', '--get', '--', a:name)
|
||||
let out = matchstr(system(cmd), "[^\n]*")
|
||||
return v:shell_error ? '' : out
|
||||
endfunction
|
||||
|
||||
@@ -444,7 +424,9 @@ function! s:repo_git_command(...) dict abort
|
||||
endfunction
|
||||
|
||||
function! s:repo_git_chomp(...) dict abort
|
||||
return s:sub(s:System(s:Prepare(a:000, self.git_dir)), '\n$', '')
|
||||
let git = g:fugitive_git_executable . ' --git-dir='.s:shellesc(self.git_dir)
|
||||
let output = git . join(map(copy(a:000),'" ".s:shellesc(v:val)'),'')
|
||||
return s:sub(s:System(output),'\n$','')
|
||||
endfunction
|
||||
|
||||
function! s:repo_git_chomp_in_tree(...) dict abort
|
||||
@@ -808,12 +790,11 @@ endfunction
|
||||
let s:trees = {}
|
||||
let s:indexes = {}
|
||||
function! s:TreeInfo(dir, commit) abort
|
||||
let git = s:Prepare(a:dir)
|
||||
if a:commit =~# '^:\=[0-3]$'
|
||||
let index = get(s:indexes, a:dir, [])
|
||||
let newftime = getftime(a:dir . '/index')
|
||||
if get(index, 0, -1) < newftime
|
||||
let out = system(git . ' ls-files --stage')
|
||||
let out = system(fugitive#Prepare(a:dir, 'ls-files', '--stage', '--'))
|
||||
let s:indexes[a:dir] = [newftime, {'0': {}, '1': {}, '2': {}, '3': {}}]
|
||||
if v:shell_error
|
||||
return [{}, -1]
|
||||
@@ -834,13 +815,13 @@ function! s:TreeInfo(dir, commit) abort
|
||||
let s:trees[a:dir] = {}
|
||||
endif
|
||||
if !has_key(s:trees[a:dir], a:commit)
|
||||
let ftime = +system(git . ' log -1 --pretty=format:%ct ' . a:commit)
|
||||
let ftime = +system(fugitive#Prepare(a:dir, 'log', '-1', '--pretty=format:%ct', a:commit, '--'))
|
||||
if v:shell_error
|
||||
let s:trees[a:dir][a:commit] = [{}, -1]
|
||||
return s:trees[a:dir][a:commit]
|
||||
endif
|
||||
let s:trees[a:dir][a:commit] = [{}, +ftime]
|
||||
let out = system(git . ' ls-tree -rtl --full-name ' . a:commit)
|
||||
let out = system(fugitive#Prepare(a:dir, 'ls-tree', '-rtl', '--full-name', a:commit, '--'))
|
||||
if v:shell_error
|
||||
return s:trees[a:dir][a:commit]
|
||||
endif
|
||||
@@ -1319,42 +1300,21 @@ function! fugitive#BufReadStatus() abort
|
||||
let b:fugitive_display_format = b:fugitive_display_format % 2
|
||||
let b:fugitive_type = 'index'
|
||||
try
|
||||
let dir = fnamemodify(amatch, ':h')
|
||||
let cmd = [fnamemodify(amatch, ':h')]
|
||||
setlocal noro ma nomodeline
|
||||
let prefix = ''
|
||||
if s:cpath(fnamemodify($GIT_INDEX_FILE !=# '' ? $GIT_INDEX_FILE : b:git_dir . '/index', ':p')) !=# s:cpath(amatch)
|
||||
if s:winshell()
|
||||
let old_index = $GIT_INDEX_FILE
|
||||
else
|
||||
let prefix = 'env GIT_INDEX_FILE='.s:shellesc(amatch).' '
|
||||
endif
|
||||
let cmd += ['-c', 'GIT_INDEX_FILE=' . amatch]
|
||||
endif
|
||||
if b:fugitive_display_format
|
||||
let cmd = ['ls-files', '--stage']
|
||||
elseif fugitive#GitVersion() =~# '^0\|^1\.[1-7]\.'
|
||||
let cmd = ['status']
|
||||
let cmd += ['ls-files', '--stage']
|
||||
else
|
||||
let cmd = [
|
||||
let cmd += [
|
||||
\ '-c', 'status.displayCommentPrefix=true',
|
||||
\ '-c', 'color.status=false',
|
||||
\ '-c', 'status.short=false',
|
||||
\ 'status']
|
||||
endif
|
||||
let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd' : 'cd'
|
||||
let cwd = getcwd()
|
||||
let cmd_str = prefix . s:Prepare(cmd, dir)
|
||||
try
|
||||
if exists('old_index')
|
||||
let $GIT_INDEX_FILE = amatch
|
||||
endif
|
||||
execute cd s:fnameescape(s:Tree(dir))
|
||||
call s:ReplaceCmd(cmd_str)
|
||||
finally
|
||||
if exists('old_index')
|
||||
let $GIT_INDEX_FILE = old_index
|
||||
endif
|
||||
execute cd s:fnameescape(cwd)
|
||||
endtry
|
||||
call s:ReplaceCmd(call('fugitive#Prepare', cmd))
|
||||
if b:fugitive_display_format
|
||||
if &filetype !=# 'git'
|
||||
set filetype=git
|
||||
@@ -1439,7 +1399,7 @@ function! fugitive#FileWriteCmd(...) abort
|
||||
endif
|
||||
silent execute "'[,']write !".s:Prepare(dir, 'hash-object', '-w', '--stdin', '--').' > '.tmp
|
||||
let sha1 = readfile(tmp)[0]
|
||||
let old_mode = matchstr(system(s:Prepare(dir, 'ls-files', '--stage', '--', '.' . file)), '^\d\+')
|
||||
let old_mode = matchstr(system(s:Prepare(dir, 'ls-files', '--stage', '.' . file)), '^\d\+')
|
||||
if empty(old_mode)
|
||||
let old_mode = executable(s:Tree(dir) . file) ? '100755' : '100644'
|
||||
endif
|
||||
@@ -1470,7 +1430,7 @@ function! fugitive#BufReadCmd(...) abort
|
||||
if rev =~# '^:\d$'
|
||||
let b:fugitive_type = 'stage'
|
||||
else
|
||||
let b:fugitive_type = system(s: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 && rev =~# '^:0'
|
||||
let sha = system(s:Prepare(dir, 'write-tree', '--prefix=' . rev[3:-1]))[0:-2]
|
||||
let b:fugitive_type = 'tree'
|
||||
@@ -1508,7 +1468,7 @@ function! fugitive#BufReadCmd(...) abort
|
||||
call s:ReplaceCmd([dir, 'ls-tree', exists('sha') ? sha : rev])
|
||||
else
|
||||
if !exists('sha')
|
||||
let sha = system(s:Prepare(dir, 'rev-parse', '--verify', rev))[0:-2]
|
||||
let sha = system(s:Prepare(dir, 'rev-parse', '--verify', rev, '--'))[0:-2]
|
||||
endif
|
||||
call s:ReplaceCmd([dir, 'show', '--no-color', sha])
|
||||
endif
|
||||
@@ -3019,8 +2979,8 @@ function! s:Blame(bang, line1, line2, count, mods, args) abort
|
||||
else
|
||||
let cmd += ['--contents', '-']
|
||||
endif
|
||||
let cmd += ['--', s:Relative('')]
|
||||
let basecmd = escape(s:Prepare(cmd), '!#%')
|
||||
let cmd += ['--', expand('%:p')]
|
||||
let basecmd = escape(fugitive#Prepare(cmd), '!#%')
|
||||
try
|
||||
let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd' : 'cd'
|
||||
let tree = s:Tree()
|
||||
|
||||
Reference in New Issue
Block a user