mirror of
https://github.com/tpope/vim-fugitive.git
synced 2025-11-10 20:43:46 -05:00
Use proper argument parsing for :Glog
This commit is contained in:
@@ -57,7 +57,9 @@ endfunction
|
|||||||
|
|
||||||
let s:fnameescape = " \t\n*?[{`$\\%#'\"|!<"
|
let s:fnameescape = " \t\n*?[{`$\\%#'\"|!<"
|
||||||
function! s:fnameescape(file) abort
|
function! s:fnameescape(file) abort
|
||||||
if exists('*fnameescape')
|
if type(a:file) == type([])
|
||||||
|
return join(map(copy(a:file), 's:fnameescape(v:val)'))
|
||||||
|
elseif exists('*fnameescape')
|
||||||
return fnameescape(a:file)
|
return fnameescape(a:file)
|
||||||
else
|
else
|
||||||
return escape(a:file, s:fnameescape)
|
return escape(a:file, s:fnameescape)
|
||||||
@@ -739,7 +741,7 @@ function! fugitive#Path(url, ...) abort
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:Relative(...) abort
|
function! s:Relative(...) abort
|
||||||
return fugitive#Path(@%, a:0 ? a:1 : ':(top)')
|
return fugitive#Path(@%, a:0 ? a:1 : ':(top)', a:0 > 1 ? a:2 : s:Dir())
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! fugitive#Find(object, ...) abort
|
function! fugitive#Find(object, ...) abort
|
||||||
@@ -3394,60 +3396,72 @@ function! s:Grep(cmd,bang,arg) abort
|
|||||||
endtry
|
endtry
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:Log(cmd, bang, line1, line2, ...) abort
|
function! s:Log(type, bang, line1, line2, args) abort
|
||||||
let args = ' ' . join(a:000, ' ')
|
let dir = s:Dir()
|
||||||
let before = substitute(args, ' --\S\@!.*', '', '')
|
let args = s:SplitExpand(a:args, s:Tree(dir))
|
||||||
let after = strpart(args, len(before))
|
let split = index(args, '--')
|
||||||
let path = s:Relative('/')
|
if split > 0
|
||||||
if path =~# '^/\.git\%(/\|$\)' || a:line2 < 0
|
let paths = args[split : -1]
|
||||||
|
let args = args[0 : split - 1]
|
||||||
|
elseif split == 0
|
||||||
|
let paths = args
|
||||||
|
let args = []
|
||||||
|
else
|
||||||
|
let paths = []
|
||||||
|
endif
|
||||||
|
let path = fugitive#Path(@%, '', dir)
|
||||||
|
if path =~# '^\.git\%(/\|$\)' || a:line2 < 0
|
||||||
let path = ''
|
let path = ''
|
||||||
elseif a:line2 > 0
|
elseif a:line2 > 0
|
||||||
let before .= ' -L ' . s:shellesc(a:line1 . ',' . a:line2 . ':' . path[1:-1])
|
call add(args, '-L' . a:line1 . ',' . a:line2 . ':' . path)
|
||||||
else
|
else
|
||||||
let after = (len(after) > 3 ? after : ' -- ') . path[1:-1]
|
if empty(paths)
|
||||||
|
call add(paths, '--')
|
||||||
|
endif
|
||||||
|
call add(paths, path)
|
||||||
endif
|
endif
|
||||||
if len(path) && before !~# '\s[^[:space:]-]'
|
if len(path) && empty(filter(copy(args), 'v:val =~# "^[^-]"'))
|
||||||
let owner = s:Owner(@%)
|
let owner = s:Owner(@%, dir)
|
||||||
if len(owner)
|
if len(owner)
|
||||||
let before .= ' ' . s:shellesc(owner)
|
call add(args, owner)
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
let grepformat = &grepformat
|
let grepformat = &grepformat
|
||||||
let grepprg = &grepprg
|
let grepprg = &grepprg
|
||||||
try
|
try
|
||||||
let cdback = s:Cd(s:Tree())
|
let format = s:HasOpt(args, '-g', '--walk-reflogs') ? "%gd\t\t%gs" : "%h\t\t" . g:fugitive_summary_format
|
||||||
let format = before =~# ' -g\| --walk-reflogs' ? "%gd\t\t%gs" : "%h\t\t" . g:fugitive_summary_format
|
let &grepprg = escape(s:UserCommand(dir) . ' --no-pager log --no-color ' .
|
||||||
let &grepprg = escape(s:UserCommand() . ' --no-pager log --no-color ' .
|
\ s:shellesc('--pretty=format:fugitive://' . dir . '//%H' . path . "\t\t" . format), '%#|')
|
||||||
\ s:shellesc('--pretty=format:fugitive://'.s:Dir().'//%H'.path."\t\t".format), '%#')
|
|
||||||
if has('patch-8.0.1782')
|
if has('patch-8.0.1782')
|
||||||
let module = '%o'
|
let module = '%o'
|
||||||
else
|
else
|
||||||
let module = '%[^[:space:]]%#'
|
let module = '%[^[:space:]]%#'
|
||||||
endif
|
endif
|
||||||
let &grepformat = '%Cdiff %.%#,%C--- %.%#,%C+++ %.%#,%Z@@ -%\d%\+\,%\d%\+ +%l\,%\d%\+ @@,%-G-%.%#,%-G+%.%#,%-G %.%#,%-G,%A%f' . "\t\t" . module . "\t\t%m"
|
let &grepformat = '%Cdiff %.%#,%C--- %.%#,%C+++ %.%#,%Z@@ -%\d%\+\,%\d%\+ +%l\,%\d%\+ @@,%-G-%.%#,%-G+%.%#,%-G %.%#,%-G,%A%f' . "\t\t" . module . "\t\t%m"
|
||||||
silent! exe a:cmd . '!' . escape(s:ShellExpand(before . after), '|')
|
silent! exe (a:type ==# 'l' ? 'lgrep' : 'grep') . '!' . escape(s:shellesc(args + paths), '|')
|
||||||
|
if exists(':chistory')
|
||||||
|
call setqflist([], 'a', {'title': (a:type ==# 'l' ? ':Gllog ' : ':Glog ') . s:fnameescape(args + paths)})
|
||||||
|
endif
|
||||||
redraw!
|
redraw!
|
||||||
finally
|
finally
|
||||||
let &grepformat = grepformat
|
let &grepformat = grepformat
|
||||||
let &grepprg = grepprg
|
let &grepprg = grepprg
|
||||||
execute cdback
|
|
||||||
endtry
|
endtry
|
||||||
let winnr = winnr()
|
let winnr = winnr()
|
||||||
let letter = a:cmd =~# '^l' ? 'l' : 'c'
|
exe a:type . 'open'
|
||||||
exe letter . 'open'
|
|
||||||
if winnr != winnr()
|
if winnr != winnr()
|
||||||
wincmd p
|
wincmd p
|
||||||
endif
|
endif
|
||||||
if !a:bang && len(letter ==# 'l' ? getloclist(0) : getqflist())
|
if !a:bang && len(a:type ==# 'l' ? getloclist(0) : getqflist())
|
||||||
return letter . 'first'
|
return a:type . 'first'
|
||||||
endif
|
endif
|
||||||
return ''
|
return ''
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
call s:command("-bar -bang -nargs=? -complete=customlist,s:GrepComplete Ggrep :execute s:Grep('grep',<bang>0,<q-args>)")
|
call s:command("-bar -bang -nargs=? -complete=customlist,s:GrepComplete Ggrep :execute s:Grep('grep',<bang>0,<q-args>)")
|
||||||
call s:command("-bar -bang -nargs=? -complete=customlist,s:GrepComplete Glgrep :execute s:Grep('lgrep',<bang>0,<q-args>)")
|
call s:command("-bar -bang -nargs=? -complete=customlist,s:GrepComplete Glgrep :execute s:Grep('lgrep',<bang>0,<q-args>)")
|
||||||
call s:command("-bar -bang -nargs=? -range=-1 -complete=customlist,s:LogComplete Glog :exe s:Log('grep',<bang>0,<line1>,<count>,<q-args>)")
|
call s:command("-bar -bang -nargs=? -range=-1 -complete=customlist,s:LogComplete Glog :exe s:Log('c',<bang>0,<line1>,<count>,<q-args>)")
|
||||||
call s:command("-bar -bang -nargs=? -range=-1 -complete=customlist,s:LogComplete Gllog :exe s:Log('lgrep',<bang>0,<line1>,<count>,<q-args>)")
|
call s:command("-bar -bang -nargs=? -range=-1 -complete=customlist,s:LogComplete Gllog :exe s:Log('l',<bang>0,<line1>,<count>,<q-args>)")
|
||||||
|
|
||||||
" Section: :Gedit, :Gpedit, :Gsplit, :Gvsplit, :Gtabedit, :Gread
|
" Section: :Gedit, :Gpedit, :Gsplit, :Gvsplit, :Gtabedit, :Gread
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user