Permalink
Browse files

Version 1.0.2

Fix for default patch command on BSD (it's not GNU compatible but perfectly usable)
  • Loading branch information...
1 parent d22b730 commit 31cd0ba5045affad0ad0929ced0f3aafe04013dd @junkblocker junkblocker committed with Jul 12, 2012
Showing with 56 additions and 18 deletions.
  1. +52 −14 autoload/patchreview.vim
  2. +1 −1 doc/patchreview.txt
  3. +3 −3 plugin/patchreview.vim
View
@@ -1,14 +1,19 @@
" VIM plugin for doing single, multi-patch or diff code reviews {{{
" Home: http://www.vim.org/scripts/script.php?script_id=1563
-" Version : 1.0.1 {{{
+" Version : 1.0.2 {{{
" Author : Manpreet Singh < junkblocker@yahoo.com >
" Copyright : 2006-2012 by Manpreet Singh
" License : This file is placed in the public domain.
" No warranties express or implied. Use at your own risk.
"
" Changelog :
"
+" 1.0.2 - Fix for system's patch command on BSDs.
+" - Better exception handling
+"
+" 1.0.1 - Set foldmethod to diff for patched buffers
+"
" 1.0 - Added Perforce support
" - Add support for arbitrary diff generation commands
" - Added ability to plug in new version control systems by others
@@ -287,6 +292,9 @@ function! <SID>TempName()
endfunction
function! <SID>GetPatchFileLines(patchfile)
+ "
+ " Throws: "File " . a:patchfile . " is not readable"
+ "
let l:patchfile = expand(a:patchfile, ":p")
if ! filereadable(expand(l:patchfile))
throw "File " . l:patchfile . " is not readable"
@@ -653,8 +661,12 @@ function! patchreview#PatchReview(...) "{{{
set shortmess=aW
call s:WipeMsgBuf()
let s:reviewmode = 'patch'
- let l:lines = s:GetPatchFileLines(a:1)
- call s:_GenericReview([l:lines] + a:000[1:])
+ try
+ let l:lines = s:GetPatchFileLines(a:1)
+ call s:_GenericReview([l:lines] + a:000[1:])
+ catch /.*/
+ call s:me.Echo('ERROR: ' . v:exception)
+ endtry
let &eadirection = s:eadirection
let &equalalways = s:equalalways
let &autowriteall = s:save_awa
@@ -689,8 +701,12 @@ function! patchreview#ReversePatchReview(...) "{{{
set shortmess=aW
call s:WipeMsgBuf()
let s:reviewmode = 'rpatch'
- let l:lines = s:GetPatchFileLines(a:1)
- call s:_GenericReview([l:lines] + a:000[1:])
+ try
+ let l:lines = s:GetPatchFileLines(a:1)
+ call s:_GenericReview([l:lines] + a:000[1:])
+ catch /.*/
+ call s:me.Echo('ERROR: ' . v:exception)
+ endtry
let &eadirection = s:eadirection
let &equalalways = s:equalalways
let &autowriteall = s:save_awa
@@ -912,19 +928,41 @@ function! <SID>_GenericReview(argslist) "{{{
"endif
if patch.type == '+' && s:reviewmode =~ 'patch'
let l:inputfile = ''
- let l:patchcmd = g:patchreview_patch . ' '
- \ . join(map(['--binary', '-s', '-o', l:tmp_patched]
- \ + patch_R_options + [l:inputfile],
- \ "shellescape(v:val)"), ' ') . ' < ' . shellescape(l:tmp_patch)
+ if filereadable('/etc/rc.conf')
+ " BSD patch is not GNU patch but works just fine without the
+ " unavailable --binary option
+ let l:patchcmd = g:patchreview_patch . ' '
+ \ . join(map(['-s', '-o', l:tmp_patched]
+ \ + patch_R_options + [l:inputfile],
+ \ "shellescape(v:val)"), ' ') . ' < '
+ \ . shellescape(l:tmp_patch)
+ else
+ let l:patchcmd = g:patchreview_patch . ' '
+ \ . join(map(['--binary', '-s', '-o', l:tmp_patched]
+ \ + patch_R_options + [l:inputfile],
+ \ "shellescape(v:val)"), ' ') . ' < '
+ \ . shellescape(l:tmp_patch)
+ endif
elseif patch.type == '+' && s:reviewmode == 'diff'
let l:inputfile = ''
unlet! l:patchcmd
else
let l:inputfile = expand(l:stripped_rel_path, ':p')
- let l:patchcmd = g:patchreview_patch . ' '
- \ . join(map(['--binary', '-s', '-o', l:tmp_patched]
- \ + patch_R_options + [l:inputfile],
- \ "shellescape(v:val)"), ' ') . ' < ' . shellescape(l:tmp_patch)
+ if filereadable('/etc/rc.conf')
+ " BSD patch is not GNU patch but works just fine without the
+ " unavailable --binary option
+ let l:patchcmd = g:patchreview_patch . ' '
+ \ . join(map(['-s', '-o', l:tmp_patched]
+ \ + patch_R_options + [l:inputfile],
+ \ "shellescape(v:val)"), ' ') . ' < '
+ \ . shellescape(l:tmp_patch)
+ else
+ let l:patchcmd = g:patchreview_patch . ' '
+ \ . join(map(['--binary', '-s', '-o', l:tmp_patched]
+ \ + patch_R_options + [l:inputfile],
+ \ "shellescape(v:val)"), ' ') . ' < '
+ \ . shellescape(l:tmp_patch)
+ endif
endif
let error = 0
if exists('l:patchcmd')
@@ -1147,4 +1185,4 @@ endfunction
"}}}
" modeline
-" vim: set et fdl=4 fdm=marker fenc=utf-8 ff=unix ft=vim sts=0 sw=2 ts=2 tw=79 nowrap :
+" vim: set et fdl=4 fdm=marker fenc= ff=unix ft=vim sts=0 sw=2 ts=2 tw=79 nowrap :
View
@@ -1,5 +1,5 @@
*patchreview.txt* Vim global plugin for doing single, multi-patch or diff code reviews
- Version 1.0.1 (for Vim version 7.0 or higher)
+ Version 1.0.2 (for Vim version 7.0 or higher)
Author: Manpreet Singh < junkblocker@yahoo.com >
Copyright (C) 2006-2011 by Manpreet Singh
View
@@ -1,7 +1,7 @@
" VIM plugin for doing single, multi-patch or diff code reviews {{{
" Home: http://www.vim.org/scripts/script.php?script_id=1563
-" Version : 1.0.1 " {{{
+" Version : 1.0.2 " {{{
" Author : Manpreet Singh < junkblocker@yahoo.com >
" Copyright : 2006-2012 by Manpreet Singh
" License : This file is placed in the public domain.
@@ -62,7 +62,7 @@
if &cp || (! exists('g:patchreview_debug') && exists('g:loaded_patchreview'))
finish
endif
-let g:loaded_patchreview="1.0.1"
+let g:loaded_patchreview="1.0.2"
if v:version < 700
echomsg 'patchreview: You need at least Vim 7.0'
finish
@@ -90,4 +90,4 @@ command! -nargs=* -complete=file DiffReviewPersist let g:patchreview_persist=1
"}}}
" modeline
-" vim: set et fdl=1 fdm=marker fenc=latin ff=unix ft=vim sw=2 sts=0 ts=2 tw=78 nowrap :
+" vim: set et fdl=1 fdm=marker fenc= ff=unix ft=vim sw=2 sts=0 ts=2 tw=78 nowrap :

0 comments on commit 31cd0ba

Please sign in to comment.