diff --git a/autoload/fugitive.vim b/autoload/fugitive.vim index 3984179..4123f46 100644 --- a/autoload/fugitive.vim +++ b/autoload/fugitive.vim @@ -542,8 +542,8 @@ function! s:Expand(rev, ...) abort \ '\.\@<=/$','') endfunction -function! s:ExecExpand(cmd, ...) abort - return substitute(a:cmd, '\\\@ '.outfile.') >& '.errorfile @@ -1982,8 +1982,8 @@ endfunction call s:command("-bang -nargs=? -complete=customlist,s:GrepComplete Ggrep :execute s:Grep('grep',0,)") call s:command("-bang -nargs=? -complete=customlist,s:GrepComplete Glgrep :execute s:Grep('lgrep',0,)") -call s:command("-bar -bang -nargs=* -range=0 -complete=customlist,s:GrepComplete Glog :call s:Log('grep',0,,,)") -call s:command("-bar -bang -nargs=* -range=0 -complete=customlist,s:GrepComplete Gllog :call s:Log('lgrep',0,,,)") +call s:command("-bar -bang -nargs=* -range=-1 -complete=customlist,s:GrepComplete Glog :call s:Log('grep',0,,,)") +call s:command("-bar -bang -nargs=* -range=-1 -complete=customlist,s:GrepComplete Gllog :call s:Log('lgrep',0,,,)") 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()