Skip to content

Commit 7369c6c

Browse files
committed
Allow to change diff target
1 parent 69498f6 commit 7369c6c

File tree

3 files changed

+40
-4
lines changed

3 files changed

+40
-4
lines changed

autoload/sy/repo.vim

+23-2
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,20 @@ 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+
let s:target = ""
516+
if g:signify_vcs_target == "default"
517+
if a:vcs == 'git'
518+
let s:target = 'HEAD'
519+
else
520+
let s:target = '.'
521+
endif
522+
else
523+
let s:target = g:signify_vcs_target
524+
endif
525+
let cmd = s:replace(cmd, '%t', s:target)
526+
endif
508527
return cmd
509528
endfunction
510529

@@ -613,9 +632,9 @@ endfunction
613632

614633
" Variables {{{1
615634
let s:default_vcs_cmds = {
616-
\ 'git': 'git diff --no-color --no-ext-diff -U0 -- %f',
635+
\ 'git': 'git diff --no-color --no-ext-diff -U0 %t -- %f',
617636
\ 'yadm': 'yadm diff --no-color --no-ext-diff -U0 -- %f',
618-
\ 'hg': 'hg diff --color=never --config aliases.diff= --nodates -U0 -- %f',
637+
\ 'hg': 'hg --config alias.diff=diff diff --color=never --nodates -U0 --from %t -- %f',
619638
\ 'svn': 'svn diff --diff-cmd %d -x -U0 -- %f',
620639
\ 'bzr': 'bzr diff --using %d --diff-options=-U0 -- %f',
621640
\ 'darcs': 'darcs diff --no-pause-for-gui --no-unified --diff-opts=-U0 -- %f',
@@ -653,6 +672,8 @@ else
653672
let g:signify_vcs_cmds_diffmode = s:default_vcs_cmds_diffmode
654673
endif
655674

675+
let g:signify_vcs_target = 'default'
676+
656677
let s:vcs_dict = map(copy(g:signify_vcs_cmds), 'split(v:val)[0]')
657678

658679
if exists('g:signify_skip') && has_key(g:signify_skip, 'vcs')

doc/signify.txt

+15-2
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 --config alias.diff=diff diff --color=never --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

+2
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)