comparison plugin/lawrencium.vim @ 126:47209552ec46

Shellescaped all command arguments in HgRepo.GetCommand, so that the commands work properly with ugly file names, in my case containing parentheses. Wrapping revision arguments in quotes is no longer necessary, so removed all of that as well.
author namark <nshan.nnnn@gmail.com>
date Wed, 02 Dec 2015 22:45:12 +0400
parents a9136d95cf47
children 96e4423e729e
comparison
equal deleted inserted replaced
122:a9136d95cf47 126:47209552ec46
57 " Utility {{{ 57 " Utility {{{
58 58
59 " Strips the ending slash in a path. 59 " Strips the ending slash in a path.
60 function! s:stripslash(path) 60 function! s:stripslash(path)
61 return fnamemodify(a:path, ':s?[/\\]$??') 61 return fnamemodify(a:path, ':s?[/\\]$??')
62 endfunction
63
64 " Surrounds the given string with double quotes.
65 function! s:addquotes(str)
66 return '"' . a:str . '"'
67 endfunction 62 endfunction
68 63
69 " Returns whether a path is absolute. 64 " Returns whether a path is absolute.
70 function! s:isabspath(path) 65 function! s:isabspath(path)
71 return a:path =~# '\v^(\w\:)?[/\\]' 66 return a:path =~# '\v^(\w\:)?[/\\]'
357 let l:arg_list = a:1 352 let l:arg_list = a:1
358 endif 353 endif
359 let l:hg_command = g:lawrencium_hg_executable . ' --repository ' . shellescape(s:stripslash(self.root_dir)) 354 let l:hg_command = g:lawrencium_hg_executable . ' --repository ' . shellescape(s:stripslash(self.root_dir))
360 let l:hg_command = l:hg_command . ' ' . a:command 355 let l:hg_command = l:hg_command . ' ' . a:command
361 for l:arg in l:arg_list 356 for l:arg in l:arg_list
362 if stridx(l:arg, ' ') >= 0 357 let l:hg_command = l:hg_command . ' ' . shellescape(l:arg)
363 let l:hg_command = l:hg_command . ' "' . l:arg . '"'
364 else
365 let l:hg_command = l:hg_command . ' ' . l:arg
366 endif
367 endfor 358 endfor
368 return l:hg_command 359 return l:hg_command
369 endfunction 360 endfunction
370 361
371 " Runs a Mercurial command in the repo. 362 " Runs a Mercurial command in the repo.
670 function! s:read_lawrencium_rev(repo, path_parts, full_path) abort 661 function! s:read_lawrencium_rev(repo, path_parts, full_path) abort
671 let l:rev = a:path_parts['value'] 662 let l:rev = a:path_parts['value']
672 if l:rev == '' 663 if l:rev == ''
673 call a:repo.ReadCommandOutput('cat', a:full_path) 664 call a:repo.ReadCommandOutput('cat', a:full_path)
674 else 665 else
675 call a:repo.ReadCommandOutput('cat', '-r', s:addquotes(l:rev), a:full_path) 666 call a:repo.ReadCommandOutput('cat', '-r', l:rev, a:full_path)
676 endif 667 endif
677 endfunction 668 endfunction
678 669
679 " Status (`hg status`) 670 " Status (`hg status`)
680 function! s:read_lawrencium_status(repo, path_parts, full_path) abort 671 function! s:read_lawrencium_status(repo, path_parts, full_path) abort
710 let l:commaidx = stridx(a:path_parts['value'], ',') 701 let l:commaidx = stridx(a:path_parts['value'], ',')
711 if l:commaidx > 0 702 if l:commaidx > 0
712 let l:rev1 = strpart(a:path_parts['value'], 0, l:commaidx) 703 let l:rev1 = strpart(a:path_parts['value'], 0, l:commaidx)
713 let l:rev2 = strpart(a:path_parts['value'], l:commaidx + 1) 704 let l:rev2 = strpart(a:path_parts['value'], l:commaidx + 1)
714 if l:rev1 == '-' 705 if l:rev1 == '-'
715 let l:diffargs = [ '-r', s:addquotes(l:rev2) ] 706 let l:diffargs = [ '-r', l:rev2 ]
716 elseif l:rev2 == '-' 707 elseif l:rev2 == '-'
717 let l:diffargs = [ '-r', s:addquotes(l:rev1) ] 708 let l:diffargs = [ '-r', l:rev1 ]
718 else 709 else
719 let l:diffargs = [ '-r', s:addquotes(l:rev1), '-r', s:addquotes(l:rev2) ] 710 let l:diffargs = [ '-r', l:rev1, '-r', l:rev2 ]
720 endif 711 endif
721 elseif a:path_parts['value'] != '' 712 elseif a:path_parts['value'] != ''
722 let l:diffargs = [ '-c', a:path_parts['value'] ] 713 let l:diffargs = [ '-c', a:path_parts['value'] ]
723 else 714 else
724 let l:diffargs = [] 715 let l:diffargs = []