Use -L to handle :Glog range

Closes #507.  References #286.
This commit is contained in:
Tim Pope 2014-06-24 13:02:04 -04:00
parent 4581cd4217
commit 276f89837f
2 changed files with 15 additions and 6 deletions

View File

@ -84,6 +84,11 @@ that are part of Git repositories).
previous commits rather than previous file revisions previous commits rather than previous file revisions
are loaded. are loaded.
:{range}Glog [args] Use git-log -L to load previous revisions of the given
range of the current file into the quickfix list. The
cursor is positioned on the first line of the first
diff hunk for each commit.
*fugitive-:Gllog* *fugitive-:Gllog*
:Gllog [args] Like |:Glog|, but use the location list instead of the :Gllog [args] Like |:Glog|, but use the location list instead of the
quickfix list. quickfix list.

View File

@ -1065,8 +1065,8 @@ endif
call s:command("-bang -nargs=? -complete=customlist,s:EditComplete Ggrep :execute s:Grep('grep',<bang>0,<q-args>)") call s:command("-bang -nargs=? -complete=customlist,s:EditComplete Ggrep :execute s:Grep('grep',<bang>0,<q-args>)")
call s:command("-bang -nargs=? -complete=customlist,s:EditComplete Glgrep :execute s:Grep('lgrep',<bang>0,<q-args>)") call s:command("-bang -nargs=? -complete=customlist,s:EditComplete Glgrep :execute s:Grep('lgrep',<bang>0,<q-args>)")
call s:command("-bar -bang -nargs=* -range=0 -complete=customlist,s:EditComplete Glog :call s:Log('grep<bang>',<count>,<f-args>)") call s:command("-bar -bang -nargs=* -range=0 -complete=customlist,s:EditComplete Glog :call s:Log('grep<bang>',<line1>,<count>,<f-args>)")
call s:command("-bar -bang -nargs=* -complete=customlist,s:EditComplete Gllog :call s:Log('lgrep<bang>',<count>,<f-args>)") call s:command("-bar -bang -nargs=* -complete=customlist,s:EditComplete Gllog :call s:Log('lgrep<bang>',<line1>,<count>,<f-args>)")
function! s:Grep(cmd,bang,arg) abort function! s:Grep(cmd,bang,arg) abort
let grepprg = &grepprg let grepprg = &grepprg
@ -1107,13 +1107,13 @@ function! s:Grep(cmd,bang,arg) abort
endtry endtry
endfunction endfunction
function! s:Log(cmd, count, ...) abort function! s:Log(cmd, line1, line2, ...) abort
let path = s:buffer().path('/') let path = s:buffer().path('/')
if path =~# '^/\.git\%(/\|$\)' || index(a:000,'--') != -1 if path =~# '^/\.git\%(/\|$\)' || index(a:000,'--') != -1
let path = '' let path = ''
endif endif
let cmd = ['--no-pager', 'log', '--no-color'] let cmd = ['--no-pager', 'log', '--no-color']
let cmd += ['--pretty=format:fugitive://'.s:repo().dir().'//%H'.path.':'.(a:count ? a:count : '').'::'.g:fugitive_summary_format] let cmd += ['--pretty=format:fugitive://'.s:repo().dir().'//%H'.path.'::'.g:fugitive_summary_format]
if empty(filter(a:000[0 : index(a:000,'--')],'v:val !~# "^-"')) if empty(filter(a:000[0 : index(a:000,'--')],'v:val !~# "^-"'))
if s:buffer().commit() =~# '\x\{40\}' if s:buffer().commit() =~# '\x\{40\}'
let cmd += [s:buffer().commit()] let cmd += [s:buffer().commit()]
@ -1123,8 +1123,12 @@ function! s:Log(cmd, count, ...) abort
end end
let cmd += map(copy(a:000),'s:sub(v:val,"^\\%(%(:\\w)*)","\\=fnamemodify(s:buffer().path(),submatch(1))")') let cmd += map(copy(a:000),'s:sub(v:val,"^\\%(%(:\\w)*)","\\=fnamemodify(s:buffer().path(),submatch(1))")')
if path =~# '/.' if path =~# '/.'
if a:line2
let cmd += ['-L', a:line1 . ',' . a:line2 . ':' . path[1:-1]]
else
let cmd += ['--', path[1:-1]] let cmd += ['--', path[1:-1]]
endif endif
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 '
@ -1132,7 +1136,7 @@ function! s:Log(cmd, count, ...) abort
try try
execute cd.'`=s:repo().tree()`' execute cd.'`=s:repo().tree()`'
let &grepprg = escape(call(s:repo().git_command,cmd,s:repo()),'%#') let &grepprg = escape(call(s:repo().git_command,cmd,s:repo()),'%#')
let &grepformat = '%f:%l::%m,%A%f:::%m,%Cdiff --git %.%#,%C--- %.%#,%C+++ %.%#,%Z@@ -%\d%\+\,%\d%\+ +%l\,%\d%\+ @@,%-G%.%#' let &grepformat = '%Cdiff %.%#,%C--- %.%#,%C+++ %.%#,%Z@@ -%\d%\+\,%\d%\+ +%l\,%\d%\+ @@,%-G-%.%#,%-G+%.%#,%-G %.%#,%A%f::%m,%-G%.%#'
exe a:cmd exe a:cmd
finally finally
let &grepformat = grepformat let &grepformat = grepformat