Skip to content

Commit

Permalink
Allow to change diff target
Browse files Browse the repository at this point in the history
Signed-off-by: Wolfgang E. Sanyer <WolfgangSanyer@Google.com>
  • Loading branch information
ezzieyguywuf committed Feb 10, 2022
1 parent 69498f6 commit c1a69d2
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
25 changes: 23 additions & 2 deletions autoload/sy/repo.vim
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,11 @@ function! s:undo_hunk(sy, vcs, diff) abort
return sy#start()
endfunction

" #update_target {{{1
function! sy#repo#update_target(target) abort
let g:signify_vcs_target = a:target
endfunction

" s:initialize_job {{{1
function! s:initialize_job(bufnr, vcs) abort
return s:wrap_cmd(a:bufnr, a:vcs, s:get_base_cmd(a:bufnr, a:vcs, g:signify_vcs_cmds))
Expand Down Expand Up @@ -505,6 +510,20 @@ function! s:get_base_cmd(bufnr, vcs, vcs_cmds) abort
let cmd = s:replace(cmd, '%f', s:get_vcs_path(a:bufnr, a:vcs))
let cmd = s:replace(cmd, '%d', s:difftool)
let cmd = s:replace(cmd, '%n', s:devnull)

if index(['git', 'hg'], a:vcs) >= 0
let s:target = ""
if g:signify_vcs_target == "default"
if a:vcs == 'git'
let s:target = 'HEAD'
else
let s:target = '.'
endif
else
let s:target = g:signify_vcs_target
endif
let cmd = s:replace(cmd, '%t', s:target)
endif
return cmd
endfunction

Expand Down Expand Up @@ -613,9 +632,9 @@ endfunction

" Variables {{{1
let s:default_vcs_cmds = {
\ 'git': 'git diff --no-color --no-ext-diff -U0 -- %f',
\ 'git': 'git diff --no-color --no-ext-diff -U0 %t -- %f',
\ 'yadm': 'yadm diff --no-color --no-ext-diff -U0 -- %f',
\ 'hg': 'hg diff --color=never --config aliases.diff= --nodates -U0 -- %f',
\ 'hg': 'hg diff --color=never --config aliases.diff= --nodates -U0 --from %t -- %f',
\ 'svn': 'svn diff --diff-cmd %d -x -U0 -- %f',
\ 'bzr': 'bzr diff --using %d --diff-options=-U0 -- %f',
\ 'darcs': 'darcs diff --no-pause-for-gui --no-unified --diff-opts=-U0 -- %f',
Expand Down Expand Up @@ -653,6 +672,8 @@ else
let g:signify_vcs_cmds_diffmode = s:default_vcs_cmds_diffmode
endif

let g:signify_vcs_target = 'default'

let s:vcs_dict = map(copy(g:signify_vcs_cmds), 'split(v:val)[0]')

if exists('g:signify_skip') && has_key(g:signify_skip, 'vcs')
Expand Down
17 changes: 15 additions & 2 deletions doc/signify.txt
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ Modifiers:~
%f actual filepath
%d |g:signify_difftool|
%n Unix: `/dev/null`, Windows: `NUL`
%t Target commit for the diff. NOTE: only works with git and hg at
the moment

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

------------------------------------------------------------------------------
*signify-:SignifyChangeTarget* >
:SignifyChangeTarget HEAD~
<
Changes the target commit for the diff.

Defaults:

git: HEAD
hg: .

------------------------------------------------------------------------------
*signify-:SignifyEnableAll* >
:SignifyEnableAll
Expand Down
2 changes: 2 additions & 0 deletions plugin/signify.vim
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ command! -nargs=0 -bar SignifyToggleHighlight call sy#highlight#line_toggl
command! -nargs=0 -bar SignifyEnableAll call sy#start_all()
command! -nargs=0 -bar SignifyDisableAll call sy#stop_all()

command! -nargs=1 -bar SignifyChangeTarget call sy#repo#update_target(<f-args>)

" Mappings {{{1
let s:cpoptions = &cpoptions
set cpoptions+=B
Expand Down

0 comments on commit c1a69d2

Please sign in to comment.