# HG changeset patch # User Ludovic Chabant # Date 1455925834 28800 # Node ID 7ad578b151c1ac2cf9cdcd59ed483af37a0512e2 # Parent 96e4423e729e3845a30315f045c6229b4977900d# Parent e2757acfd9b1a1b42a85b00d1203adcee0c1f7cc Merge pull request #8 from GitHub. diff -r e2757acfd9b1 -r 7ad578b151c1 plugin/lawrencium.vim --- a/plugin/lawrencium.vim Fri Dec 18 13:17:54 2015 +0100 +++ b/plugin/lawrencium.vim Fri Feb 19 15:50:34 2016 -0800 @@ -61,11 +61,6 @@ return fnamemodify(a:path, ':s?[/\\]$??') endfunction -" Surrounds the given string with double quotes. -function! s:addquotes(str) - return '"' . a:str . '"' -endfunction - " Returns whether a path is absolute. function! s:isabspath(path) return a:path =~# '\v^(\w\:)?[/\\]' @@ -356,24 +351,38 @@ if a:0 == 1 && type(a:1) == type([]) let l:arg_list = a:1 endif + let l:prev_shellslash = &shellslash + setlocal noshellslash let l:hg_command = g:lawrencium_hg_executable . ' --repository ' . shellescape(s:stripslash(self.root_dir)) let l:hg_command = l:hg_command . ' ' . a:command for l:arg in l:arg_list - if stridx(l:arg, ' ') >= 0 - let l:hg_command = l:hg_command . ' "' . l:arg . '"' - else - let l:hg_command = l:hg_command . ' ' . l:arg - endif + let l:hg_command = l:hg_command . ' ' . shellescape(l:arg) endfor + if l:prev_shellslash + setlocal shellslash + endif return l:hg_command endfunction " Runs a Mercurial command in the repo. function! s:HgRepo.RunCommand(command, ...) abort + let l:all_args = [1, a:command] + a:000 + return call(self['RunCommandEx'], l:all_args, self) +endfunction + +function! s:HgRepo.RunCommandEx(plain_mode, command, ...) abort + let l:prev_hgplain = $HGPLAIN + if a:plain_mode + let $HGPLAIN = 'true' + endif let l:all_args = [a:command] + a:000 let l:hg_command = call(self['GetCommand'], l:all_args, self) call s:trace("Running Mercurial command: " . l:hg_command) - return system(l:hg_command) + let l:cmd_out = system(l:hg_command) + if a:plain_mode + let $HGPLAIN = l:prev_hgplain + endif + return l:cmd_out endfunction " Runs a Mercurial command in the repo and reads its output into the current @@ -672,7 +681,7 @@ if l:rev == '' call a:repo.ReadCommandOutput('cat', a:full_path) else - call a:repo.ReadCommandOutput('cat', '-r', s:addquotes(l:rev), a:full_path) + call a:repo.ReadCommandOutput('cat', '-r', l:rev, a:full_path) endif endfunction @@ -723,11 +732,11 @@ let l:rev1 = strpart(a:path_parts['value'], 0, l:commaidx) let l:rev2 = strpart(a:path_parts['value'], l:commaidx + 1) if l:rev1 == '-' - let l:diffargs = [ '-r', s:addquotes(l:rev2) ] + let l:diffargs = [ '-r', l:rev2 ] elseif l:rev2 == '-' - let l:diffargs = [ '-r', s:addquotes(l:rev1) ] + let l:diffargs = [ '-r', l:rev1 ] else - let l:diffargs = [ '-r', s:addquotes(l:rev1), '-r', s:addquotes(l:rev2) ] + let l:diffargs = [ '-r', l:rev1, '-r', l:rev2 ] endif elseif a:path_parts['value'] != '' let l:diffargs = [ '-c', a:path_parts['value'] ] @@ -887,7 +896,7 @@ " to make auto-completed paths work magically. execute 'cd! ' . fnameescape(l:repo.root_dir) endif - let l:output = call(l:repo.RunCommand, a:000, l:repo) + let l:output = call(l:repo.RunCommandEx, [0] + a:000, l:repo) if g:lawrencium_auto_cd execute 'cd! -' endif