From 276f89837f6cea617b04f757e6242323068cfaa5 Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Tue, 24 Jun 2014 13:02:04 -0400 Subject: [PATCH] Use -L to handle :Glog range Closes #507. References #286. --- doc/fugitive.txt | 5 +++++ plugin/fugitive.vim | 16 ++++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/doc/fugitive.txt b/doc/fugitive.txt index 8d585c6..a94751a 100644 --- a/doc/fugitive.txt +++ b/doc/fugitive.txt @@ -84,6 +84,11 @@ that are part of Git repositories). previous commits rather than previous file revisions 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* :Gllog [args] Like |:Glog|, but use the location list instead of the quickfix list. diff --git a/plugin/fugitive.vim b/plugin/fugitive.vim index 4baf267..0884507 100644 --- a/plugin/fugitive.vim +++ b/plugin/fugitive.vim @@ -1065,8 +1065,8 @@ endif call s:command("-bang -nargs=? -complete=customlist,s:EditComplete Ggrep :execute s:Grep('grep',0,)") call s:command("-bang -nargs=? -complete=customlist,s:EditComplete Glgrep :execute s:Grep('lgrep',0,)") -call s:command("-bar -bang -nargs=* -range=0 -complete=customlist,s:EditComplete Glog :call s:Log('grep',,)") -call s:command("-bar -bang -nargs=* -complete=customlist,s:EditComplete Gllog :call s:Log('lgrep',,)") +call s:command("-bar -bang -nargs=* -range=0 -complete=customlist,s:EditComplete Glog :call s:Log('grep',,,)") +call s:command("-bar -bang -nargs=* -complete=customlist,s:EditComplete Gllog :call s:Log('lgrep',,,)") function! s:Grep(cmd,bang,arg) abort let grepprg = &grepprg @@ -1107,13 +1107,13 @@ function! s:Grep(cmd,bang,arg) abort endtry endfunction -function! s:Log(cmd, count, ...) abort +function! s:Log(cmd, line1, line2, ...) abort let path = s:buffer().path('/') if path =~# '^/\.git\%(/\|$\)' || index(a:000,'--') != -1 let path = '' endif 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 s:buffer().commit() =~# '\x\{40\}' let cmd += [s:buffer().commit()] @@ -1123,7 +1123,11 @@ function! s:Log(cmd, count, ...) abort end let cmd += map(copy(a:000),'s:sub(v:val,"^\\%(%(:\\w)*)","\\=fnamemodify(s:buffer().path(),submatch(1))")') if path =~# '/.' - let cmd += ['--',path[1:-1]] + if a:line2 + let cmd += ['-L', a:line1 . ',' . a:line2 . ':' . path[1:-1]] + else + let cmd += ['--', path[1:-1]] + endif endif let grepformat = &grepformat let grepprg = &grepprg @@ -1132,7 +1136,7 @@ function! s:Log(cmd, count, ...) abort try execute cd.'`=s:repo().tree()`' 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 finally let &grepformat = grepformat