Skip to content

Commit 1712f40

Browse files
committed
Allow to change diff target
Signed-off-by: Wolfgang E. Sanyer <[email protected]>
1 parent 69498f6 commit 1712f40

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

autoload/sy/repo.vim

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,11 @@ function! s:undo_hunk(sy, vcs, diff) abort
446446
return sy#start()
447447
endfunction
448448

449+
" #update_target {{{1
450+
function! sy#repo#update_target(target) abort
451+
let g:signify_vcs_target = a:target
452+
endfunction
453+
449454
" s:initialize_job {{{1
450455
function! s:initialize_job(bufnr, vcs) abort
451456
return s:wrap_cmd(a:bufnr, a:vcs, s:get_base_cmd(a:bufnr, a:vcs, g:signify_vcs_cmds))
@@ -505,6 +510,17 @@ function! s:get_base_cmd(bufnr, vcs, vcs_cmds) abort
505510
let cmd = s:replace(cmd, '%f', s:get_vcs_path(a:bufnr, a:vcs))
506511
let cmd = s:replace(cmd, '%d', s:difftool)
507512
let cmd = s:replace(cmd, '%n', s:devnull)
513+
514+
if index(['git', 'hg'], a:vcs) >= 0
515+
if !exists("g:signify_vcs_target")
516+
if a:vcs == 'git'
517+
let g:signify_vcs_target = 'HEAD'
518+
else
519+
let g:signify_vcs_target = '.'
520+
endif
521+
endif
522+
let cmd = s:replace(cmd, '%t', g:signify_vcs_target)
523+
endif
508524
return cmd
509525
endfunction
510526

@@ -613,9 +629,9 @@ endfunction
613629

614630
" Variables {{{1
615631
let s:default_vcs_cmds = {
616-
\ 'git': 'git diff --no-color --no-ext-diff -U0 -- %f',
632+
\ 'git': 'git diff --no-color --no-ext-diff -U0 %t -- %f',
617633
\ 'yadm': 'yadm diff --no-color --no-ext-diff -U0 -- %f',
618-
\ 'hg': 'hg diff --color=never --config aliases.diff= --nodates -U0 -- %f',
634+
\ 'hg': 'hg diff --color=never --config aliases.diff= --nodates -U0 --from %t -- %f',
619635
\ 'svn': 'svn diff --diff-cmd %d -x -U0 -- %f',
620636
\ 'bzr': 'bzr diff --using %d --diff-options=-U0 -- %f',
621637
\ 'darcs': 'darcs diff --no-pause-for-gui --no-unified --diff-opts=-U0 -- %f',

doc/signify.txt

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@ Modifiers:~
168168
%f actual filepath
169169
%d |g:signify_difftool|
170170
%n Unix: `/dev/null`, Windows: `NUL`
171+
%t Target commit for the diff. NOTE: only works with git and hg at
172+
the moment
171173

172174
Redirection: Instead of `>foo` use `sy#util#shell_redirect('foo')`. This
173175
helper function takes 'shellredir' into account.
@@ -189,9 +191,9 @@ colors are emitted. Our parser expects lines in the diff output to start with
189191
Default:
190192
>
191193
let g:signify_vcs_cmds = {
192-
\ 'git': 'git diff --no-color --no-ext-diff -U0 -- %f',
194+
\ 'git': 'git diff --no-color --no-ext-diff -U0 %t -- %f',
193195
\ 'yadm': 'yadm diff --no-color --no-ext-diff -U0 -- %f',
194-
\ 'hg': 'hg diff --color=never --config aliases.diff= --nodates -U0 -- %f',
196+
\ 'hg': 'hg diff --color=never --config aliases.diff= --nodates -U0 --from %t -- %f',
195197
\ 'svn': 'svn diff --diff-cmd %d -x -U0 -- %f',
196198
\ 'bzr': 'bzr diff --using %d --diff-options=-U0 -- %f',
197199
\ 'darcs': 'darcs diff --no-pause-for-gui --no-unified --diff-opts=-U0 -- %f',
@@ -358,6 +360,17 @@ Enable the plugin for the current buffer only.
358360
Can also be used to when a repository was initialized while Sy was already
359361
loaded.
360362

363+
------------------------------------------------------------------------------
364+
*signify-:SignifyChangeTarget* >
365+
:SignifyChangeTarget HEAD~
366+
<
367+
Changes the target commit for the diff.
368+
369+
Defaults:
370+
371+
git: HEAD
372+
hg: .
373+
361374
------------------------------------------------------------------------------
362375
*signify-:SignifyEnableAll* >
363376
:SignifyEnableAll

plugin/signify.vim

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ command! -nargs=0 -bar SignifyToggleHighlight call sy#highlight#line_toggl
2626
command! -nargs=0 -bar SignifyEnableAll call sy#start_all()
2727
command! -nargs=0 -bar SignifyDisableAll call sy#stop_all()
2828

29+
command! -nargs=1 -bar SignifyChangeTarget call sy#repo#update_target(<f-args>)
30+
2931
" Mappings {{{1
3032
let s:cpoptions = &cpoptions
3133
set cpoptions+=B

0 commit comments

Comments
 (0)