From c1a69d211e8637fcd3d5a55ea9d1de8d65d16d66 Mon Sep 17 00:00:00 2001 From: "Wolfgang E. Sanyer" Date: Thu, 10 Feb 2022 03:58:29 +0000 Subject: [PATCH] Allow to change diff target Signed-off-by: Wolfgang E. Sanyer --- autoload/sy/repo.vim | 25 +++++++++++++++++++++++-- doc/signify.txt | 17 +++++++++++++++-- plugin/signify.vim | 2 ++ 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/autoload/sy/repo.vim b/autoload/sy/repo.vim index e379c0b..d6e6c03 100644 --- a/autoload/sy/repo.vim +++ b/autoload/sy/repo.vim @@ -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)) @@ -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 @@ -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', @@ -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') diff --git a/doc/signify.txt b/doc/signify.txt index 91aec23..b1afb17 100644 --- a/doc/signify.txt +++ b/doc/signify.txt @@ -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. @@ -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', @@ -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 diff --git a/plugin/signify.vim b/plugin/signify.vim index 5ec3ad5..de9a893 100644 --- a/plugin/signify.vim +++ b/plugin/signify.vim @@ -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() + " Mappings {{{1 let s:cpoptions = &cpoptions set cpoptions+=B