Only target current file if range is given to :Glog

This commit is contained in:
Tim Pope 2019-06-29 19:55:16 -04:00
parent c8ac43422e
commit 7c66d544e5
2 changed files with 10 additions and 24 deletions

View File

@ -3111,24 +3111,19 @@ function! s:Log(cmd, bang, line1, line2, ...) abort
let before = substitute(args, ' --\S\@!.*', '', '') let before = substitute(args, ' --\S\@!.*', '', '')
let after = strpart(args, len(before)) let after = strpart(args, len(before))
let path = s:Relative('/') let path = s:Relative('/')
let relative = path[1:-1] if path =~# '^/\.git\%(/\|$\)' || a:line2 < 0
if path =~# '^/\.git\%(/\|$\)' || len(after)
let path = '' let path = ''
elseif a:line2 > 0
let before .= ' -L ' . s:shellesc(a:line1 . ',' . a:line2 . ':' . path[1:-1])
else
let after = (len(after) > 3 ? after : ' -- ') . path[1:-1]
endif endif
if before !~# '\s[^[:space:]-]' if len(path) && before !~# '\s[^[:space:]-]'
let owner = s:Owner(@%) let owner = s:Owner(@%)
if len(owner) if len(owner)
let before .= ' ' . s:shellesc(owner) let before .= ' ' . s:shellesc(owner)
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
try try
@ -3138,12 +3133,6 @@ function! s:Log(cmd, bang, line1, line2, ...) abort
\ s:shellesc('--pretty=format:fugitive://'.s:Dir().'//%H'.path.'::'.format), '%#') \ s:shellesc('--pretty=format:fugitive://'.s:Dir().'//%H'.path.'::'.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 ? '! ' : ' ') . s:ShellExpand(before . after) exe a:cmd . (a:bang ? '! ' : ' ') . s:ShellExpand(before . after)
if len(path) && a:line2 == -1
redraw
echohl WarningMsg
echo ':Glog will soon default to all files. Use :0Glog to target current file'
echohl NONE
endif
finally finally
let &grepformat = grepformat let &grepformat = grepformat
let &grepprg = grepprg let &grepprg = grepprg

View File

@ -75,14 +75,11 @@ that are part of Git repositories).
:Glgrep[!] [args] |:lgrep|[!] with git-grep as 'grepprg'. :Glgrep[!] [args] |:lgrep|[!] with git-grep as 'grepprg'.
*fugitive-:Glog* *fugitive-:Glog*
:Glog [args] Load the commit history into the |quickfix| list. :Glog[!] [args] Use git-log [args] to load the commit history into the
Additional git-log arguments can be given (for |quickfix| list. Jump to the first commit unless [!]
example, --reverse). Provide "--" in the argument is given.
list to target all commits. Otherwise, only commits
changing the current file will be targeted. This
special casing is slated to be removed.
:{range}Glog [args] Use git-log -L to load previous revisions of the given :{range}Glog[!] [args] Use git-log -L to load previous revisions of the given
range of the current file into the |quickfix| list. range of the current file into the |quickfix| list.
The cursor is positioned on the first line of the The cursor is positioned on the first line of the
first diff hunk for each commit. Use :0Glog to target first diff hunk for each commit. Use :0Glog to target