Browse Source

Merge 61d6f00ea6 into 08e9894d2a

pull/354/merge
Ezequiel Valenzuela 12 years ago
parent
commit
b305e671c3
5 changed files with 186 additions and 21 deletions
  1. +157
    -0
      autoload/vundle/compat.vim
  2. +20
    -12
      autoload/vundle/config.vim
  3. +4
    -4
      autoload/vundle/installer.vim
  4. +4
    -4
      autoload/vundle/scripts.vim
  5. +1
    -1
      test/vimrc

+ 157
- 0
autoload/vundle/compat.vim View File

@ -0,0 +1,157 @@
" vundle - vim compatibility support module
" this abstracts the operation:
" exec 'set runtimepath-='.fnameescape(LIST)
"
" ... even when fnameescape() is not available (on vim-7.0, for example)
"
" notes:
" * it attempts to do the "real thing", if it can
" (if 'fnameescape()' is available);
" * otherwise, it has a number of fallback scenarios, ordered by
" reliability;
" * special case: if a:dirs contains a ',' (multiple entries), this function
" attempts the
" exec 'set runtimepath-='.fnameescape(LIST)
" first (if fnameescape() is available).
" if that does not alter &runtimepath, then it tries to remove a:dirs
" elements individually;
"
" args:
" dirs [string]: described as 'LIST' above;
"
" for now, it does not produce an explicit return value
"
func! vundle#compat#rtp_rm_entry(dirs)
" debug: echomsg '[debug] vundle#compat#rtp_rm_entry(): entered. rtp: ' . string(&rtp) . '; dirs: ' . string(a:dirs)
" optimisation: there seems to be a few of these cases
if empty(a:dirs)
return 0
endif
let l:runtimepath_orig = &rtp
let l:processed_flag = 0
let l:elem_separator = ','
for l:process_stage in range(1, 4)
if ( l:process_stage == 1 )
if exists('*fnameescape')
exec 'set rtp-='.fnameescape(a:dirs)
" if &rtp was altered, or a:dirs had only one element, we won't keep
" trying
let l:processed_flag = ( ( &rtp != l:runtimepath_orig ) || ( stridx(a:dirs, l:elem_separator) < 0 ) )
endif
elseif ( l:process_stage == 2 )
if exists('*split') && exists('*filter') && exists('*join')
" a bit costly, but more compatible
let l:runtimepath_list = split(&rtp, l:elem_separator, 1)
for l:entry_dir in split(a:dirs, l:elem_separator, 1)
let l:runtimepath_list = filter(l:runtimepath_list, 'v:val != l:entry_dir')
endfor
" assemble the runtime variable from the list
let &rtp = join(l:runtimepath_list, l:elem_separator)
let l:processed_flag = 1
endif
elseif ( l:process_stage == 3 )
if exists('*escape')
" from fnameescape() documentation:
" it escapes: " \t\n*?[{`$\\%#'\"|!<"
" plus, depending on 'isfname', other characters.
" (TODO: add those cases, if needed)
exec 'set rtp-='.escape(a:dirs, " \t\n*?[{`$\\%#'\"|!<")
let l:processed_flag = 1
endif
elseif ( l:process_stage == 4 )
" cheap and cheerful (but no escaping)
exec 'set rtp-='.a:dirs
let l:processed_flag = 1
endif
if l:processed_flag
break
endif
endfor
" debug: echomsg '[debug] vundle#compat#rtp_rm_entry(): exiting. rtp: ' . string(&rtp)
endf
" abstracts the following operations:
" exec 'set runtimepath^='.fnameescape(LIST)
" exec 'set runtimepath+='.fnameescape(LIST)
" exec 'set runtimepath='.fnameescape(LIST)
"
" ... even when fnameescape() is not available (on vim-7.0, for example)
"
" args:
" dirs [string]: described as 'LIST' above;
" addset_operator [string]: one of:
" '^': prepend ('set runtimepath^=');
" '+': append ('set runtimepath+=');
" '': set ('set runtimepath=');
"
" for now, it does not produce an explicit return value
"
func! vundle#compat#rtp_addset_entry(dirs, addset_operator)
" debug: echomsg '[debug] vundle#compat#rtp_addset_entry(): entered. rtp: ' . string(&rtp) . '; dirs: ' . string(a:dirs) . '; operator: ' . string( a:addset_operator )
if exists('*fnameescape')
exec 'set rtp'.a:addset_operator.'='.fnameescape(a:dirs)
else
" a bit costly, but more compatible
if ( a:addset_operator == '' ) && empty(&rtp)
" this should be quick
let &rtp = a:dirs
else
let l:elem_separator = ','
" only add the elements not already present in &runtimepath
if exists('*split') && exists('*filter') && exists('*join')
" a bit costly, but more compatible
let l:dirs_list = split(a:dirs, l:elem_separator, 1)
for l:entry_dir in split(&rtp, l:elem_separator, 1)
let l:dirs_list = filter(l:dirs_list, 'v:val != l:entry_dir')
endfor
let l:dirs = join(l:dirs_list, l:elem_separator)
else
" nothing we can do about this: we'll take the input as is
let l:dirs = a:dirs
endif
if !empty(l:dirs)
if a:addset_operator == '^'
let &rtp = l:dirs . l:elem_separator . &rtp
elseif a:addset_operator == '+'
let &rtp = &rtp . l:elem_separator . l:dirs
else
" FIXME: report internal error
endif
endif
endif
endif
" debug: echomsg '[debug] vundle#compat#rtp_addset_entry(): exiting. rtp: ' . string(&rtp)
endf
func! vundle#compat#has_dos_windows_paths()
return exists('+shellslash')
endf
" provides the same functionality as shellescape()
" (even on vim versions that don't support it)
"
" note: behaviour taken from vim-7.1 documentation
func! vundle#compat#shellescape(string_value)
if vundle#compat#has_dos_windows_paths()
if &shellslash
" return as is?
return a:string_value
else
" double all double quotes within string,
" and enclose result in double quotes
return '"' . substitute(a:string_value,'"','""','g') . '"'
endif
else
" replace all "'" with "'\''"
return "'" . substitute(a:string_value,"'","'".'\\'."''",'g') . "'"
endif
endf
" MAYBE: also provide fnameescape()
" (first appeared in a major release in vim-7.2)

+ 20
- 12
autoload/vundle/config.vim View File

@ -69,28 +69,36 @@ endf
func! s:rtp_rm_a()
let paths = map(copy(g:bundles), 'v:val.rtpath')
let prepends = join(paths, ',')
let appends = join(paths, '/after,').'/after'
exec 'set rtp-='.fnameescape(prepends)
exec 'set rtp-='.fnameescape(appends)
if !empty(paths)
let prepends = join(paths, ',')
let appends = join(paths, '/after,').'/after'
call vundle#compat#rtp_rm_entry(prepends)
call vundle#compat#rtp_rm_entry(appends)
endif
endf
func! s:rtp_add_a()
let paths = map(copy(g:bundles), 'v:val.rtpath')
let prepends = join(paths, ',')
let appends = join(paths, '/after,').'/after'
exec 'set rtp^='.fnameescape(prepends)
exec 'set rtp+='.fnameescape(appends)
if !empty(paths)
let prepends = join(paths, ',')
let appends = join(paths, '/after,').'/after'
call vundle#compat#rtp_addset_entry(prepends,'^')
call vundle#compat#rtp_addset_entry(appends,'+')
endif
endf
func! s:rtp_rm(dir) abort
exec 'set rtp-='.fnameescape(expand(a:dir, 1))
exec 'set rtp-='.fnameescape(expand(a:dir.'/after', 1))
if !empty(a:dir)
call vundle#compat#rtp_rm_entry(expand(a:dir, 1))
call vundle#compat#rtp_rm_entry(expand(a:dir.'/after', 1))
endif
endf
func! s:rtp_add(dir) abort
exec 'set rtp^='.fnameescape(expand(a:dir, 1))
exec 'set rtp+='.fnameescape(expand(a:dir.'/after', 1))
if !empty(a:dir)
call vundle#compat#rtp_addset_entry(expand(a:dir, 1), '^')
call vundle#compat#rtp_addset_entry(expand(a:dir.'/after', 1), '+')
endif
endf
func! s:expand_path(path) abort


+ 4
- 4
autoload/vundle/installer.vim View File

@ -174,7 +174,7 @@ func! vundle#installer#delete(bang, dir_name) abort
\ 'rm -rf'
let bundle = vundle#config#init_bundle(a:dir_name, {})
let cmd .= ' '.shellescape(bundle.path())
let cmd .= ' '.vundle#compat#shellescape(bundle.path())
let out = s:system(cmd)
@ -214,15 +214,15 @@ func! s:sync(bang, bundle) abort
let git_dir = expand(a:bundle.path().'/.git/', 1)
if isdirectory(git_dir) || filereadable(expand(a:bundle.path().'/.git', 1))
if !(a:bang) | return 'todate' | endif
let cmd = 'cd '.shellescape(a:bundle.path()).' && git pull && git submodule update --init --recursive'
let cmd = 'cd '.vundle#compat#shellescape(a:bundle.path()).' && git pull && git submodule update --init --recursive'
let cmd = g:shellesc_cd(cmd)
let get_current_sha = 'cd '.shellescape(a:bundle.path()).' && git rev-parse HEAD'
let get_current_sha = 'cd '.vundle#compat#shellescape(a:bundle.path()).' && git rev-parse HEAD'
let get_current_sha = g:shellesc_cd(get_current_sha)
let initial_sha = s:system(get_current_sha)[0:15]
else
let cmd = 'git clone --recursive '.shellescape(a:bundle.uri).' '.shellescape(a:bundle.path())
let cmd = 'git clone --recursive '.vundle#compat#shellescape(a:bundle.uri).' '.vundle#compat#shellescape(a:bundle.path())
let initial_sha = ''
endif


+ 4
- 4
autoload/vundle/scripts.vim View File

@ -39,7 +39,7 @@ func! s:create_changelog() abort
let updated_sha = bundle_data[1]
let bundle = bundle_data[2]
let cmd = 'cd '.shellescape(bundle.path()).
let cmd = 'cd '.vundle#compat#shellescape(bundle.path()).
\ ' && git log --pretty=format:"%s %an, %ar" --graph '.
\ initial_sha.'..'.updated_sha
@ -155,10 +155,10 @@ func! s:fetch_scripts(to)
let l:vim_scripts_json = 'http://vim-scripts.org/api/scripts.json'
if executable("curl")
let cmd = 'curl --fail -s -o '.shellescape(a:to).' '.l:vim_scripts_json
let cmd = 'curl --fail -s -o '.vundle#compat#shellescape(a:to).' '.l:vim_scripts_json
elseif executable("wget")
let temp = shellescape(tempname())
let cmd = 'wget -q -O '.temp.' '.l:vim_scripts_json. ' && mv -f '.temp.' '.shellescape(a:to)
let temp = vundle#compat#shellescape(tempname())
let cmd = 'wget -q -O '.temp.' '.l:vim_scripts_json. ' && mv -f '.temp.' '.vundle#compat#shellescape(a:to)
if (has('win32') || has('win64'))
let cmd = substitute(cmd, 'mv -f ', 'move /Y ', '') " change force flag
let cmd = g:shellesc(cmd)


+ 1
- 1
test/vimrc View File

@ -12,7 +12,7 @@ let src = 'http://github.com/gmarik/vundle.git'
" let g:vundle_default_git_proto = 'git'
if !isdirectory(expand(root, 1).'/vundle')
exec '!git clone '.src.' '.shellescape(root, 1).'/vundle'
exec '!git clone '.src.' '.vundle#compat#shellescape(root, 1).'/vundle'
endif
filetype off


Loading…
Cancel
Save