From 43ca708c9990dcc3ab4788c024d7fb0c44cfffed Mon Sep 17 00:00:00 2001 From: killphi Date: Wed, 7 Aug 2013 12:57:02 +0200 Subject: [PATCH 1/3] Add variable option to pass to VCS diff command --- autoload/sy/repo.vim | 52 +++++++++++++++++++++++++++++++++++--------- doc/signify.txt | 8 +++++++ 2 files changed, 50 insertions(+), 10 deletions(-) diff --git a/autoload/sy/repo.vim b/autoload/sy/repo.vim index 0237c57..614a990 100644 --- a/autoload/sy/repo.vim +++ b/autoload/sy/repo.vim @@ -24,6 +24,8 @@ else endif endif +s:diffoptions = '' + " Function: #detect {{{1 function! sy#repo#detect(path) abort for type in get(g:, 'signify_vcs_list', [ 'git', 'hg', 'svn', 'darcs', 'bzr', 'fossil', 'cvs', 'rcs', 'accurev', 'perforce' ]) @@ -39,7 +41,10 @@ endfunction " Function: #get_diff_git {{{1 function! sy#repo#get_diff_git(path) abort if executable('git') - let diff = system('cd '. sy#util#escape(fnamemodify(a:path, ':h')) .' && git diff --no-ext-diff -U0 -- '. sy#util#escape(a:path)) + if exists('g:signify_diffoptions["git"]') + let s:diffoptions = g:signify_diffoptions['git'] + endif + let diff = system('cd '. sy#util#escape(fnamemodify(a:path, ':h')) .' && git diff --no-ext-diff -U0 '. s:diffoptions .' -- '. sy#util#escape(a:path)) return v:shell_error ? '' : diff endif endfunction @@ -78,7 +83,10 @@ endfunction " Function: #get_diff_hg {{{1 function! sy#repo#get_diff_hg(path) abort if executable('hg') - let diff = system('hg diff --nodates -U0 -- '. sy#util#escape(a:path)) + if exists('g:signify_diffoptions["hg"]') + let s:diffoptions = g:signify_diffoptions['hg'] + endif + let diff = system('hg diff --nodates -U0 '. s:diffoptions .' -- '. sy#util#escape(a:path)) return v:shell_error ? '' : diff endif endfunction @@ -86,7 +94,10 @@ endfunction " Function: #get_diff_svn {{{1 function! sy#repo#get_diff_svn(path) abort if executable('svn') - let diff = system('svn diff --diff-cmd '. s:difftool .' -x -U0 -- '. sy#util#escape(a:path)) + if exists('g:signify_diffoptions["svn"]') + let s:diffoptions = g:signify_diffoptions['svn'] + endif + let diff = system('svn diff --diff-cmd '. s:difftool .' -x -U0 '. s:diffoptions .' -- '. sy#util#escape(a:path)) return v:shell_error ? '' : diff endif endfunction @@ -94,7 +105,10 @@ endfunction " Function: #get_diff_bzr {{{1 function! sy#repo#get_diff_bzr(path) abort if executable('bzr') - let diff = system('bzr diff --using '. s:difftool .' --diff-options=-U0 -- '. sy#util#escape(a:path)) + if exists('g:signify_diffoptions["bzr"]') + let s:diffoptions = g:signify_diffoptions['bzr'] + endif + let diff = system('bzr diff --using '. s:difftool .' --diff-options=-U0 '. s:diffoptions .' -- '. sy#util#escape(a:path)) return ((v:shell_error == 0) || (v:shell_error == 1) || (v:shell_error == 2)) ? diff : '' endif endfunction @@ -102,7 +116,10 @@ endfunction " Function: #get_diff_darcs {{{1 function! sy#repo#get_diff_darcs(path) abort if executable('darcs') - let diff = system('cd '. sy#util#escape(fnamemodify(a:path, ':h')) .' && darcs diff --no-pause-for-gui --diff-command="'. s:difftool .' -U0 %1 %2" -- '. sy#util#escape(a:path)) + if exists('g:signify_diffoptions["darcs"]') + let s:diffoptions = g:signify_diffoptions['darcs'] + endif + let diff = system('cd '. sy#util#escape(fnamemodify(a:path, ':h')) .' && darcs diff --no-pause-for-gui --diff-command="'. s:difftool .' -U0 %1 %2" '. s:diffoptions .' -- '. sy#util#escape(a:path)) return v:shell_error ? '' : diff endif endfunction @@ -110,7 +127,10 @@ endfunction " Function: #get_diff_fossil {{{1 function! sy#repo#get_diff_fossil(path) abort if executable('fossil') - let diff = system('cd '. sy#util#escape(fnamemodify(a:path, ':h')) .' && fossil set diff-command "'. s:difftool .' -U 0" && fossil diff --unified -c 0 -- '. sy#util#escape(a:path)) + if exists('g:signify_diffoptions["fossil"]') + let s:diffoptions = g:signify_diffoptions['fossil'] + endif + let diff = system('cd '. sy#util#escape(fnamemodify(a:path, ':h')) .' && fossil set diff-command "'. s:difftool .' -U 0" && fossil diff --unified -c 0 '. s:diffoptions .' -- '. sy#util#escape(a:path)) return v:shell_error ? '' : diff endif endfunction @@ -118,7 +138,10 @@ endfunction " Function: #get_diff_cvs {{{1 function! sy#repo#get_diff_cvs(path) abort if executable('cvs') - let diff = system('cd '. sy#util#escape(fnamemodify(a:path, ':h')) .' && cvs diff -U0 -- '. sy#util#escape(fnamemodify(a:path, ':t'))) + if exists('g:signify_diffoptions["cvs"]') + let s:diffoptions = g:signify_diffoptions['cvs'] + endif + let diff = system('cd '. sy#util#escape(fnamemodify(a:path, ':h')) .' && cvs diff -U0 '. s:diffoptions .' -- '. sy#util#escape(fnamemodify(a:path, ':t'))) return v:shell_error ? '' : diff endif endfunction @@ -126,7 +149,10 @@ endfunction " Function: #get_diff_rcs {{{1 function! sy#repo#get_diff_rcs(path) abort if executable('rcs') - let diff = system('rcsdiff -U0 '. sy#util#escape(a:path) .' 2>/dev/null') + if exists('g:signify_diffoptions["rcs"]') + let s:diffoptions = g:signify_diffoptions['rcs'] + endif + let diff = system('rcsdiff -U0 '. s:diffoptions .' '. sy#util#escape(a:path) .' 2>/dev/null') return v:shell_error ? '' : diff endif endfunction @@ -134,7 +160,10 @@ endfunction " Function: #get_diff_accurev {{{1 function! sy#repo#get_diff_accurev(path) abort if executable('accurev') - let diff = system('cd '. sy#util#escape(fnamemodify(a:path, ':h')) .' && accurev diff '. sy#util#escape(fnamemodify(a:path, ':t')) . ' -- -U0') + if exists('g:signify_diffoptions["accurev"]') + let s:diffoptions = g:signify_diffoptions['accurev'] + endif + let diff = system('cd '. sy#util#escape(fnamemodify(a:path, ':h')) .' && accurev diff '. sy#util#escape(fnamemodify(a:path, ':t')) . ' -- -U0 '. s:diffoptions) return (v:shell_error != 1) ? '' : diff endif endfunction @@ -142,7 +171,10 @@ endfunction " Function: #get_diff_perforce {{{1 function! sy#repo#get_diff_perforce(path) abort if executable('p4') - let diff = system('env P4DIFF=diff p4 diff -dU0 -- '. sy#util#escape(a:path)) + if exists('g:signify_diffoptions["perforce"]') + let s:diffoptions = g:signify_diffoptions['perforce'] + endif + let diff = system('env P4DIFF=diff p4 diff -dU0 '. s:diffoptions .' -- '. sy#util#escape(a:path)) return v:shell_error ? '' : diff endif endfunction diff --git a/doc/signify.txt b/doc/signify.txt index e605289..8abba7c 100644 --- a/doc/signify.txt +++ b/doc/signify.txt @@ -208,6 +208,14 @@ Otherwise 'diff' will be used. Default: Does not exist. +============- + + let g:signify_diffoptions = { 'git': '-w', 'hg': '-w' } + +Default: No additional options. + +This will pass the given additional options to the selected VCS diff command. + ============================================================================== 4. Commands *signify-commands* From 52d025975bd41d7a1b615f84081a0b991352f4df Mon Sep 17 00:00:00 2001 From: killphi Date: Wed, 7 Aug 2013 13:17:12 +0200 Subject: [PATCH 2/3] Add forgotten `let` to fix startup up --- autoload/sy/repo.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload/sy/repo.vim b/autoload/sy/repo.vim index 614a990..19ed4c1 100644 --- a/autoload/sy/repo.vim +++ b/autoload/sy/repo.vim @@ -24,7 +24,7 @@ else endif endif -s:diffoptions = '' +let s:diffoptions = '' " Function: #detect {{{1 function! sy#repo#detect(path) abort From 78a96c4b49bf165f426759534076adb7bb187464 Mon Sep 17 00:00:00 2001 From: Marco Hinz Date: Wed, 7 Aug 2013 15:46:37 +0200 Subject: [PATCH 3/3] Minor syntactic style changes --- autoload/sy/repo.vim | 62 +++++++++++++++----------------------------- doc/signify.txt | 4 +-- 2 files changed, 23 insertions(+), 43 deletions(-) diff --git a/autoload/sy/repo.vim b/autoload/sy/repo.vim index 19ed4c1..c52a151 100644 --- a/autoload/sy/repo.vim +++ b/autoload/sy/repo.vim @@ -24,7 +24,7 @@ else endif endif -let s:diffoptions = '' +let s:diffoptions = get(g:, 'signify_diffoptions', {}) " Function: #detect {{{1 function! sy#repo#detect(path) abort @@ -41,10 +41,8 @@ endfunction " Function: #get_diff_git {{{1 function! sy#repo#get_diff_git(path) abort if executable('git') - if exists('g:signify_diffoptions["git"]') - let s:diffoptions = g:signify_diffoptions['git'] - endif - let diff = system('cd '. sy#util#escape(fnamemodify(a:path, ':h')) .' && git diff --no-ext-diff -U0 '. s:diffoptions .' -- '. sy#util#escape(a:path)) + let diffoptions = has_key(s:diffoptions, 'git') ? s:diffoptions.git : '' + let diff = system('cd '. sy#util#escape(fnamemodify(a:path, ':h')) .' && git diff --no-ext-diff -U0 '. diffoptions .' -- '. sy#util#escape(a:path)) return v:shell_error ? '' : diff endif endfunction @@ -83,10 +81,8 @@ endfunction " Function: #get_diff_hg {{{1 function! sy#repo#get_diff_hg(path) abort if executable('hg') - if exists('g:signify_diffoptions["hg"]') - let s:diffoptions = g:signify_diffoptions['hg'] - endif - let diff = system('hg diff --nodates -U0 '. s:diffoptions .' -- '. sy#util#escape(a:path)) + let diffoptions = has_key(s:diffoptions, 'hg') ? s:diffoptions.hg : '' + let diff = system('hg diff --nodates -U0 '. diffoptions .' -- '. sy#util#escape(a:path)) return v:shell_error ? '' : diff endif endfunction @@ -94,10 +90,8 @@ endfunction " Function: #get_diff_svn {{{1 function! sy#repo#get_diff_svn(path) abort if executable('svn') - if exists('g:signify_diffoptions["svn"]') - let s:diffoptions = g:signify_diffoptions['svn'] - endif - let diff = system('svn diff --diff-cmd '. s:difftool .' -x -U0 '. s:diffoptions .' -- '. sy#util#escape(a:path)) + let diffoptions = has_key(s:diffoptions, 'svn') ? s:diffoptions.svn : '' + let diff = system('svn diff --diff-cmd '. s:difftool .' -x -U0 '. diffoptions .' -- '. sy#util#escape(a:path)) return v:shell_error ? '' : diff endif endfunction @@ -105,10 +99,8 @@ endfunction " Function: #get_diff_bzr {{{1 function! sy#repo#get_diff_bzr(path) abort if executable('bzr') - if exists('g:signify_diffoptions["bzr"]') - let s:diffoptions = g:signify_diffoptions['bzr'] - endif - let diff = system('bzr diff --using '. s:difftool .' --diff-options=-U0 '. s:diffoptions .' -- '. sy#util#escape(a:path)) + let diffoptions = has_key(s:diffoptions, 'bzr') ? s:diffoptions.bzr : '' + let diff = system('bzr diff --using '. s:difftool .' --diff-options=-U0 '. diffoptions .' -- '. sy#util#escape(a:path)) return ((v:shell_error == 0) || (v:shell_error == 1) || (v:shell_error == 2)) ? diff : '' endif endfunction @@ -116,10 +108,8 @@ endfunction " Function: #get_diff_darcs {{{1 function! sy#repo#get_diff_darcs(path) abort if executable('darcs') - if exists('g:signify_diffoptions["darcs"]') - let s:diffoptions = g:signify_diffoptions['darcs'] - endif - let diff = system('cd '. sy#util#escape(fnamemodify(a:path, ':h')) .' && darcs diff --no-pause-for-gui --diff-command="'. s:difftool .' -U0 %1 %2" '. s:diffoptions .' -- '. sy#util#escape(a:path)) + let diffoptions = has_key(s:diffoptions, 'darcs') ? s:diffoptions.darcs : '' + let diff = system('cd '. sy#util#escape(fnamemodify(a:path, ':h')) .' && darcs diff --no-pause-for-gui --diff-command="'. s:difftool .' -U0 %1 %2" '. diffoptions .' -- '. sy#util#escape(a:path)) return v:shell_error ? '' : diff endif endfunction @@ -127,10 +117,8 @@ endfunction " Function: #get_diff_fossil {{{1 function! sy#repo#get_diff_fossil(path) abort if executable('fossil') - if exists('g:signify_diffoptions["fossil"]') - let s:diffoptions = g:signify_diffoptions['fossil'] - endif - let diff = system('cd '. sy#util#escape(fnamemodify(a:path, ':h')) .' && fossil set diff-command "'. s:difftool .' -U 0" && fossil diff --unified -c 0 '. s:diffoptions .' -- '. sy#util#escape(a:path)) + let diffoptions = has_key(s:diffoptions, 'fossil') ? s:diffoptions.fossil : '' + let diff = system('cd '. sy#util#escape(fnamemodify(a:path, ':h')) .' && fossil set diff-command "'. s:difftool .' -U 0" && fossil diff --unified -c 0 '. diffoptions .' -- '. sy#util#escape(a:path)) return v:shell_error ? '' : diff endif endfunction @@ -138,10 +126,8 @@ endfunction " Function: #get_diff_cvs {{{1 function! sy#repo#get_diff_cvs(path) abort if executable('cvs') - if exists('g:signify_diffoptions["cvs"]') - let s:diffoptions = g:signify_diffoptions['cvs'] - endif - let diff = system('cd '. sy#util#escape(fnamemodify(a:path, ':h')) .' && cvs diff -U0 '. s:diffoptions .' -- '. sy#util#escape(fnamemodify(a:path, ':t'))) + let diffoptions = has_key(s:diffoptions, 'cvs') ? s:diffoptions.cvs : '' + let diff = system('cd '. sy#util#escape(fnamemodify(a:path, ':h')) .' && cvs diff -U0 '. diffoptions .' -- '. sy#util#escape(fnamemodify(a:path, ':t'))) return v:shell_error ? '' : diff endif endfunction @@ -149,10 +135,8 @@ endfunction " Function: #get_diff_rcs {{{1 function! sy#repo#get_diff_rcs(path) abort if executable('rcs') - if exists('g:signify_diffoptions["rcs"]') - let s:diffoptions = g:signify_diffoptions['rcs'] - endif - let diff = system('rcsdiff -U0 '. s:diffoptions .' '. sy#util#escape(a:path) .' 2>/dev/null') + let diffoptions = has_key(s:diffoptions, 'rcs') ? s:diffoptions.rcs : '' + let diff = system('rcsdiff -U0 '. diffoptions .' '. sy#util#escape(a:path) .' 2>/dev/null') return v:shell_error ? '' : diff endif endfunction @@ -160,10 +144,8 @@ endfunction " Function: #get_diff_accurev {{{1 function! sy#repo#get_diff_accurev(path) abort if executable('accurev') - if exists('g:signify_diffoptions["accurev"]') - let s:diffoptions = g:signify_diffoptions['accurev'] - endif - let diff = system('cd '. sy#util#escape(fnamemodify(a:path, ':h')) .' && accurev diff '. sy#util#escape(fnamemodify(a:path, ':t')) . ' -- -U0 '. s:diffoptions) + let diffoptions = has_key(s:diffoptions, 'accurev') ? s:diffoptions.accurev : '' + let diff = system('cd '. sy#util#escape(fnamemodify(a:path, ':h')) .' && accurev diff '. sy#util#escape(fnamemodify(a:path, ':t')) . ' -- -U0 '. diffoptions) return (v:shell_error != 1) ? '' : diff endif endfunction @@ -171,10 +153,8 @@ endfunction " Function: #get_diff_perforce {{{1 function! sy#repo#get_diff_perforce(path) abort if executable('p4') - if exists('g:signify_diffoptions["perforce"]') - let s:diffoptions = g:signify_diffoptions['perforce'] - endif - let diff = system('env P4DIFF=diff p4 diff -dU0 '. s:diffoptions .' -- '. sy#util#escape(a:path)) + let diffoptions = has_key(s:diffoptions, 'perforce') ? s:diffoptions.perforce : '' + let diff = system('env P4DIFF=diff p4 diff -dU0 '. diffoptions .' -- '. sy#util#escape(a:path)) return v:shell_error ? '' : diff endif endfunction diff --git a/doc/signify.txt b/doc/signify.txt index 8abba7c..3ba3e36 100644 --- a/doc/signify.txt +++ b/doc/signify.txt @@ -212,10 +212,10 @@ Default: Does not exist. let g:signify_diffoptions = { 'git': '-w', 'hg': '-w' } -Default: No additional options. - This will pass the given additional options to the selected VCS diff command. +Default: Does not exist. + ============================================================================== 4. Commands *signify-commands*