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