Skip to content

Commit 1253132

Browse files
committed
Allow to change diff target
1 parent 9caa7ef commit 1253132

File tree

4 files changed

+41
-7
lines changed

4 files changed

+41
-7
lines changed

autoload/sy/repo.vim

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,11 @@ function! s:undo_hunk(sy, vcs, diff) abort
451451
return sy#start()
452452
endfunction
453453

454+
" #update_target {{{1
455+
function! sy#repo#update_target(target) abort
456+
let g:signify_vcs_target = a:target
457+
endfunction
458+
454459
" s:initialize_job {{{1
455460
function! s:initialize_job(bufnr, vcs) abort
456461
return s:wrap_cmd(a:bufnr, a:vcs, s:get_base_cmd(a:bufnr, a:vcs, g:signify_vcs_cmds))
@@ -510,6 +515,20 @@ function! s:get_base_cmd(bufnr, vcs, vcs_cmds) abort
510515
let cmd = s:replace(cmd, '%f', s:get_vcs_path(a:bufnr, a:vcs))
511516
let cmd = s:replace(cmd, '%d', s:difftool)
512517
let cmd = s:replace(cmd, '%n', s:devnull)
518+
519+
if index(['git', 'hg'], a:vcs) >= 0
520+
let s:target = ""
521+
if g:signify_vcs_target == "default"
522+
if a:vcs == 'git'
523+
let s:target = 'HEAD'
524+
else
525+
let s:target = '.'
526+
endif
527+
else
528+
let s:target = g:signify_vcs_target
529+
endif
530+
let cmd = s:replace(cmd, '%t', s:target)
531+
endif
513532
return cmd
514533
endfunction
515534

@@ -618,9 +637,9 @@ endfunction
618637

619638
" Variables {{{1
620639
let s:default_vcs_cmds = {
621-
\ 'git': 'git diff --no-color --no-ext-diff -U0 -- %f',
640+
\ 'git': 'git diff --no-color --no-ext-diff -U0 %t -- %f',
622641
\ 'yadm': 'yadm diff --no-color --no-ext-diff -U0 -- %f',
623-
\ 'hg': 'hg diff --color=never --config aliases.diff= --nodates -U0 -- %f',
642+
\ 'hg': 'hg --config alias.diff=diff diff --color=never --nodates -U0 --from %t -- %f',
624643
\ 'svn': 'svn diff --diff-cmd %d -x -U0 -- %f',
625644
\ 'bzr': 'bzr diff --using %d --diff-options=-U0 -- %f',
626645
\ 'darcs': 'darcs diff --no-pause-for-gui --no-unified --diff-opts=-U0 -- %f',
@@ -658,6 +677,8 @@ else
658677
let g:signify_vcs_cmds_diffmode = s:default_vcs_cmds_diffmode
659678
endif
660679

680+
let g:signify_vcs_target = 'default'
681+
661682
let s:vcs_dict = map(copy(g:signify_vcs_cmds), 'split(v:val)[0]')
662683

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

autoload/sy/util.vim

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,7 @@ endfunction
134134
" #popup_close {{{1
135135
function! sy#util#popup_close() abort
136136
if s:popup_window
137-
if nvim_win_is_valid(s:popup_window)
138-
call nvim_win_close(s:popup_window, 1)
139-
endif
137+
call nvim_win_close(s:popup_window, 1)
140138
let s:popup_window = 0
141139
endif
142140
endfunction

doc/signify.txt

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

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

364+
------------------------------------------------------------------------------
365+
*signify-:SignifyChangeTarget* >
366+
:SignifyChangeTarget HEAD~
367+
<
368+
Changes the target commit for the diff.
369+
370+
Defaults:
371+
372+
git: HEAD
373+
hg: .
374+
362375
------------------------------------------------------------------------------
363376
*signify-:SignifyEnableAll* >
364377
: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)