mirror of
https://github.com/tpope/vim-fugitive.git
synced 2025-11-11 12:53:52 -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
|
endfunction
|
||||||
|
|
||||||
function! s:ExecExpand(cmd, ...) abort
|
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')
|
return substitute(a:cmd, '\\\@<![%#]:\@!', '\=s:RemoveDot(fugitive#Path(expand(submatch(0)), "./", a:0 ? a:1 : get(b:, "git_dir", "")))', 'g')
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
let s:trees = {}
|
let s:trees = {}
|
||||||
@@ -1362,7 +1362,7 @@ function! s:Git(bang, mods, args) abort
|
|||||||
if has('win32')
|
if has('win32')
|
||||||
let after = '|call fugitive#ReloadStatus()' . after
|
let after = '|call fugitive#ReloadStatus()' . after
|
||||||
endif
|
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 exists(':terminal') && has('nvim') && !get(g:, 'fugitive_force_bang_command')
|
||||||
if len(@%)
|
if len(@%)
|
||||||
-tabedit %
|
-tabedit %
|
||||||
@@ -1746,7 +1746,7 @@ function! s:Commit(mods, args, ...) abort
|
|||||||
else
|
else
|
||||||
let command = 'env GIT_EDITOR=false '
|
let command = 'env GIT_EDITOR=false '
|
||||||
endif
|
endif
|
||||||
let args = s:ExecExpand(a:args)
|
let args = s:ShellExpand(a:args)
|
||||||
let command .= s:UserCommand() . ' commit ' . args
|
let command .= s:UserCommand() . ' commit ' . args
|
||||||
if &shell =~# 'csh'
|
if &shell =~# 'csh'
|
||||||
noautocmd silent execute '!('.escape(command, '!#%').' > '.outfile.') >& '.errorfile
|
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 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("-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=-1 -complete=customlist,s:GrepComplete Glog :call s:Log('grep',<bang>0,<line1>,<count>,<q-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 Gllog :call s:Log('lgrep',<bang>0,<line1>,<count>,<q-args>)")
|
||||||
|
|
||||||
function! s:Grep(cmd,bang,arg) abort
|
function! s:Grep(cmd,bang,arg) abort
|
||||||
let grepprg = &grepprg
|
let grepprg = &grepprg
|
||||||
@@ -1994,7 +1994,7 @@ function! s:Grep(cmd,bang,arg) abort
|
|||||||
execute cd s:fnameescape(s:Tree())
|
execute cd s:fnameescape(s:Tree())
|
||||||
let &grepprg = s:UserCommand() . ' --no-pager grep -n --no-color'
|
let &grepprg = s:UserCommand() . ' --no-pager grep -n --no-color'
|
||||||
let &grepformat = '%f:%l:%m,%m %f match%ts,%f'
|
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()
|
let list = a:cmd =~# '^l' ? getloclist(0) : getqflist()
|
||||||
for entry in list
|
for entry in list
|
||||||
if bufname(entry.bufnr) =~ ':'
|
if bufname(entry.bufnr) =~ ':'
|
||||||
@@ -2025,37 +2025,40 @@ function! s:Grep(cmd,bang,arg) abort
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:Log(cmd, bang, line1, line2, ...) abort
|
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('/')
|
let path = s:Relative('/')
|
||||||
if path =~# '^/\.git\%(/\|$\)' || index(a:000,'--') != -1
|
if path =~# '^/\.git\%(/\|$\)' || len(after)
|
||||||
let path = ''
|
let path = ''
|
||||||
endif
|
endif
|
||||||
let cmd = ['--no-pager', 'log', '--no-color']
|
let relative = s:Relative('')
|
||||||
let cmd += ['--pretty=format:fugitive://'.b:git_dir.'//%H'.path.'::'.g:fugitive_summary_format]
|
if before !~# '\s[^[:space:]-]'
|
||||||
if empty(filter(a:000[0 : index(a:000,'--')],'v:val !~# "^-"'))
|
let commit = matchstr(s:DirCommitFile(@%)[1], '^\x\x\+$')
|
||||||
let commit = s:DirCommitFile(@%)[1]
|
if len(commit)
|
||||||
if len(commit) > 2
|
let before .= ' ' . commit
|
||||||
let cmd += [commit]
|
elseif relative =~# '^\.git/refs/\|^\.git/.*HEAD$'
|
||||||
elseif s:Relative('') =~# '^\.git/refs/\|^\.git/.*HEAD$'
|
let before .= ' ' . relative[5:-1]
|
||||||
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]]
|
|
||||||
endif
|
endif
|
||||||
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 grepformat = &grepformat
|
||||||
let grepprg = &grepprg
|
let grepprg = &grepprg
|
||||||
let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd' : 'cd'
|
let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd' : 'cd'
|
||||||
let dir = getcwd()
|
let dir = getcwd()
|
||||||
try
|
try
|
||||||
execute cd s:fnameescape(s:Tree())
|
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%.%#'
|
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
|
finally
|
||||||
let &grepformat = grepformat
|
let &grepformat = grepformat
|
||||||
let &grepprg = grepprg
|
let &grepprg = grepprg
|
||||||
@@ -2159,7 +2162,7 @@ function! s:Read(count, line1, line2, range, bang, mods, args, ...) abort
|
|||||||
let delete = ''
|
let delete = ''
|
||||||
endif
|
endif
|
||||||
if a:bang
|
if a:bang
|
||||||
let args = s:ExecExpand(a:args)
|
let args = s:ShellExpand(a:args)
|
||||||
let git = s:UserCommand()
|
let git = s:UserCommand()
|
||||||
let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd' : 'cd'
|
let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd' : 'cd'
|
||||||
let cwd = getcwd()
|
let cwd = getcwd()
|
||||||
|
|||||||
Reference in New Issue
Block a user