Skip to content

Commit

Permalink
Allow to change diff target
Browse files Browse the repository at this point in the history
  • Loading branch information
ezzieyguywuf committed Jul 12, 2024
1 parent 9caa7ef commit 1253132
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 7 deletions.
25 changes: 23 additions & 2 deletions autoload/sy/repo.vim
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,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 @@ -510,6 +515,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 @@ -618,9 +637,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 --config alias.diff=diff diff --color=never --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 @@ -658,6 +677,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
4 changes: 1 addition & 3 deletions autoload/sy/util.vim
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,7 @@ endfunction
" #popup_close {{{1
function! sy#util#popup_close() abort
if s:popup_window
if nvim_win_is_valid(s:popup_window)
call nvim_win_close(s:popup_window, 1)
endif
call nvim_win_close(s:popup_window, 1)
let s:popup_window = 0
endif
endfunction
Expand Down
17 changes: 15 additions & 2 deletions doc/signify.txt
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,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 @@ -190,9 +192,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 --config alias.diff=diff diff --color=never --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 @@ -359,6 +361,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 1253132

Please sign in to comment.