mirror of
https://github.com/tpope/vim-fugitive.git
synced 2025-11-11 04:53:45 -05:00
Rewrite :Glog to use string argument rather than list
This makes shell expansion less weird.
This commit is contained in:
@@ -542,8 +542,8 @@ function! s:Expand(rev, ...) abort
|
||||
\ '\.\@<=/$','')
|
||||
endfunction
|
||||
|
||||
function! s:ExecExpand(cmd, ...) abort
|
||||
return substitute(a:cmd, '\\\@<![%#]', '\=s:RemoveDot(fugitive#Path(expand(submatch(0)), "./", a:0 ? a:1 : get(b:, "git_dir", "")))', 'g')
|
||||
function! s:ShellExpand(cmd, ...) abort
|
||||
return substitute(a:cmd, '\\\@<![%#]:\@!', '\=s:RemoveDot(fugitive#Path(expand(submatch(0)), "./", a:0 ? a:1 : get(b:, "git_dir", "")))', 'g')
|
||||
endfunction
|
||||
|
||||
let s:trees = {}
|
||||
@@ -1362,7 +1362,7 @@ function! s:Git(bang, mods, args) abort
|
||||
if has('win32')
|
||||
let after = '|call fugitive#ReloadStatus()' . after
|
||||
endif
|
||||
let exec = escape(git . ' ' . s:ExecExpand(args), '!#%')
|
||||
let exec = escape(git . ' ' . s:ShellExpand(args), '!#%')
|
||||
if exists(':terminal') && has('nvim') && !get(g:, 'fugitive_force_bang_command')
|
||||
if len(@%)
|
||||
-tabedit %
|
||||
@@ -1746,7 +1746,7 @@ function! s:Commit(mods, args, ...) abort
|
||||
else
|
||||
let command = 'env GIT_EDITOR=false '
|
||||
endif
|
||||
let args = s:ExecExpand(a:args)
|
||||
let args = s:ShellExpand(a:args)
|
||||
let command .= s:UserCommand() . ' commit ' . args
|
||||
if &shell =~# 'csh'
|
||||
noautocmd silent execute '!('.escape(command, '!#%').' > '.outfile.') >& '.errorfile
|
||||
@@ -1982,8 +1982,8 @@ endfunction
|
||||
|
||||
call s:command("-bang -nargs=? -complete=customlist,s:GrepComplete Ggrep :execute s:Grep('grep',<bang>0,<q-args>)")
|
||||
call s:command("-bang -nargs=? -complete=customlist,s:GrepComplete Glgrep :execute s:Grep('lgrep',<bang>0,<q-args>)")
|
||||
call s:command("-bar -bang -nargs=* -range=0 -complete=customlist,s:GrepComplete Glog :call s:Log('grep',<bang>0,<line1>,<count>,<f-args>)")
|
||||
call s:command("-bar -bang -nargs=* -range=0 -complete=customlist,s:GrepComplete Gllog :call s:Log('lgrep',<bang>0,<line1>,<count>,<f-args>)")
|
||||
call s:command("-bar -bang -nargs=* -range=-1 -complete=customlist,s:GrepComplete Glog :call s:Log('grep',<bang>0,<line1>,<count>,<q-args>)")
|
||||
call s:command("-bar -bang -nargs=* -range=-1 -complete=customlist,s:GrepComplete Gllog :call s:Log('lgrep',<bang>0,<line1>,<count>,<q-args>)")
|
||||
|
||||
function! s:Grep(cmd,bang,arg) abort
|
||||
let grepprg = &grepprg
|
||||
@@ -1994,7 +1994,7 @@ function! s:Grep(cmd,bang,arg) abort
|
||||
execute cd s:fnameescape(s:Tree())
|
||||
let &grepprg = s:UserCommand() . ' --no-pager grep -n --no-color'
|
||||
let &grepformat = '%f:%l:%m,%m %f match%ts,%f'
|
||||
exe a:cmd.'! '.escape(s:ExecExpand(matchstr(a:arg, '\v\C.{-}%($|[''" ]\@=\|)@=')), '|#%')
|
||||
exe a:cmd.'! '.escape(s:ShellExpand(matchstr(a:arg, '\v\C.{-}%($|[''" ]\@=\|)@=')), '|#%')
|
||||
let list = a:cmd =~# '^l' ? getloclist(0) : getqflist()
|
||||
for entry in list
|
||||
if bufname(entry.bufnr) =~ ':'
|
||||
@@ -2025,37 +2025,40 @@ function! s:Grep(cmd,bang,arg) abort
|
||||
endfunction
|
||||
|
||||
function! s:Log(cmd, bang, line1, line2, ...) abort
|
||||
let args = ' ' . join(a:000, ' ')
|
||||
let before = substitute(args, ' --\S\@!.*', '', '')
|
||||
let after = strpart(args, len(before))
|
||||
let path = s:Relative('/')
|
||||
if path =~# '^/\.git\%(/\|$\)' || index(a:000,'--') != -1
|
||||
if path =~# '^/\.git\%(/\|$\)' || len(after)
|
||||
let path = ''
|
||||
endif
|
||||
let cmd = ['--no-pager', 'log', '--no-color']
|
||||
let cmd += ['--pretty=format:fugitive://'.b:git_dir.'//%H'.path.'::'.g:fugitive_summary_format]
|
||||
if empty(filter(a:000[0 : index(a:000,'--')],'v:val !~# "^-"'))
|
||||
let commit = s:DirCommitFile(@%)[1]
|
||||
if len(commit) > 2
|
||||
let cmd += [commit]
|
||||
elseif s:Relative('') =~# '^\.git/refs/\|^\.git/.*HEAD$'
|
||||
let cmd += [s:Relative('')[5:-1]]
|
||||
endif
|
||||
end
|
||||
let cmd += map(copy(a:000),'s:ExecExpand(v:val)')
|
||||
if path =~# '/.'
|
||||
if a:line2
|
||||
let cmd += ['-L', a:line1 . ',' . a:line2 . ':' . path[1:-1]]
|
||||
else
|
||||
let cmd += ['--', path[1:-1]]
|
||||
let relative = s:Relative('')
|
||||
if before !~# '\s[^[:space:]-]'
|
||||
let commit = matchstr(s:DirCommitFile(@%)[1], '^\x\x\+$')
|
||||
if len(commit)
|
||||
let before .= ' ' . commit
|
||||
elseif relative =~# '^\.git/refs/\|^\.git/.*HEAD$'
|
||||
let before .= ' ' . relative[5:-1]
|
||||
endif
|
||||
endif
|
||||
if relative =~# '^\.git\%(/\|$\)'
|
||||
let relative = ''
|
||||
endif
|
||||
if len(relative) && a:line2 > 0
|
||||
let before .= ' -L ' . s:shellesc(a:line1 . ',' . a:line2 . ':' . relative)
|
||||
elseif len(relative) && (empty(after) || a:line2 == 0)
|
||||
let after = (len(after) > 3 ? after : ' -- ') . relative
|
||||
endif
|
||||
let grepformat = &grepformat
|
||||
let grepprg = &grepprg
|
||||
let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd' : 'cd'
|
||||
let dir = getcwd()
|
||||
try
|
||||
execute cd s:fnameescape(s:Tree())
|
||||
let &grepprg = escape(s:UserCommand() . join(map(cmd, '" ".s:shellesc(v:val)'), ''), '%#')
|
||||
let &grepprg = escape(s:UserCommand() . ' --no-pager log --no-color ' .
|
||||
\ s:shellesc('--pretty=format:fugitive://'.b:git_dir.'//%H'.path.'::'.g:fugitive_summary_format), '%#')
|
||||
let &grepformat = '%Cdiff %.%#,%C--- %.%#,%C+++ %.%#,%Z@@ -%\d%\+\,%\d%\+ +%l\,%\d%\+ @@,%-G-%.%#,%-G+%.%#,%-G %.%#,%A%f::%m,%-G%.%#'
|
||||
exe a:cmd . (a:bang ? '!' : '')
|
||||
exe a:cmd . (a:bang ? '! ' : ' ') . s:ShellExpand(before . after)
|
||||
finally
|
||||
let &grepformat = grepformat
|
||||
let &grepprg = grepprg
|
||||
@@ -2159,7 +2162,7 @@ function! s:Read(count, line1, line2, range, bang, mods, args, ...) abort
|
||||
let delete = ''
|
||||
endif
|
||||
if a:bang
|
||||
let args = s:ExecExpand(a:args)
|
||||
let args = s:ShellExpand(a:args)
|
||||
let git = s:UserCommand()
|
||||
let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd' : 'cd'
|
||||
let cwd = getcwd()
|
||||
|
||||
Reference in New Issue
Block a user