2013-09-30 04:19:31 -04:00
|
|
|
" vim: et sw=2 sts=2
|
|
|
|
|
2013-08-19 11:36:16 -04:00
|
|
|
scriptencoding utf-8
|
|
|
|
|
2013-07-17 06:30:58 -04:00
|
|
|
" Function: #detect {{{1
|
2017-04-18 11:13:17 -04:00
|
|
|
function! sy#repo#detect() abort
|
2017-04-18 10:59:48 -04:00
|
|
|
for vcs in s:vcs_list
|
2017-02-24 11:16:09 -05:00
|
|
|
let b:sy.detecting += 1
|
2019-08-06 15:15:05 -04:00
|
|
|
call sy#repo#get_diff(vcs, function('sy#sign#set_signs'))
|
2013-07-17 04:14:43 -04:00
|
|
|
endfor
|
2017-01-17 08:22:19 -05:00
|
|
|
endfunction
|
|
|
|
|
2017-02-20 08:52:24 -05:00
|
|
|
" Function: s:callback_nvim_stdout{{{1
|
|
|
|
function! s:callback_nvim_stdout(_job_id, data, _event) dict abort
|
2017-01-17 08:22:19 -05:00
|
|
|
if empty(self.stdoutbuf) || empty(self.stdoutbuf[-1])
|
|
|
|
let self.stdoutbuf += a:data
|
|
|
|
else
|
2017-02-15 09:27:17 -05:00
|
|
|
let self.stdoutbuf = self.stdoutbuf[:-2]
|
2017-01-23 06:50:13 -05:00
|
|
|
\ + [self.stdoutbuf[-1] . get(a:data, 0, '')]
|
2017-01-17 08:22:19 -05:00
|
|
|
\ + a:data[1:]
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2017-02-20 08:52:24 -05:00
|
|
|
" Function: s:callback_nvim_exit {{{1
|
|
|
|
function! s:callback_nvim_exit(_job_id, exitval, _event) dict abort
|
2019-08-06 15:15:05 -04:00
|
|
|
return s:handle_diff(self, a:exitval)
|
2017-02-20 08:52:24 -05:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
" Function: s:callback_vim_stdout {{{1
|
|
|
|
function! s:callback_vim_stdout(_job_id, data) dict abort
|
2017-01-17 17:12:00 -05:00
|
|
|
let self.stdoutbuf += [a:data]
|
|
|
|
endfunction
|
|
|
|
|
2017-02-20 08:52:24 -05:00
|
|
|
" Function: s:callback_vim_close {{{1
|
|
|
|
function! s:callback_vim_close(channel) dict abort
|
2017-02-20 08:43:35 -05:00
|
|
|
let job = ch_getjob(a:channel)
|
|
|
|
while 1
|
|
|
|
if job_status(job) == 'dead'
|
|
|
|
let exitval = job_info(job).exitval
|
|
|
|
break
|
|
|
|
endif
|
|
|
|
sleep 10m
|
|
|
|
endwhile
|
2019-08-06 15:15:05 -04:00
|
|
|
return s:handle_diff(self, exitval)
|
2017-02-16 07:54:54 -05:00
|
|
|
endfunction
|
|
|
|
|
2019-08-06 15:15:05 -04:00
|
|
|
" Function: sy#get_diff {{{1
|
|
|
|
function! sy#repo#get_diff(vcs, func) abort
|
|
|
|
call sy#verbose('sy#repo#get_diff()', a:vcs)
|
2017-01-17 17:12:00 -05:00
|
|
|
|
2017-01-30 09:31:14 -05:00
|
|
|
let job_id = get(b:, 'sy_job_id_'.a:vcs)
|
2017-01-18 11:15:15 -05:00
|
|
|
" Neovim
|
2017-01-17 13:41:55 -05:00
|
|
|
if has('nvim')
|
2017-01-30 09:25:41 -05:00
|
|
|
if job_id
|
|
|
|
silent! call jobstop(job_id)
|
2017-01-17 13:41:55 -05:00
|
|
|
endif
|
2017-01-18 11:15:15 -05:00
|
|
|
|
2017-04-18 11:13:17 -04:00
|
|
|
let [cmd, options] = s:initialize_job(a:vcs)
|
2019-08-01 11:44:01 -04:00
|
|
|
let options.func = a:func
|
2018-12-20 16:04:09 -05:00
|
|
|
let [cwd, chdir] = sy#util#chdir()
|
2017-01-18 11:15:15 -05:00
|
|
|
|
2018-12-27 09:37:51 -05:00
|
|
|
call sy#verbose(['CMD: '. string(cmd), 'CMD DIR: '. b:sy.info.dir, 'ORIG DIR: '. cwd], a:vcs)
|
2018-12-20 16:04:09 -05:00
|
|
|
|
|
|
|
try
|
|
|
|
execute chdir fnameescape(b:sy.info.dir)
|
|
|
|
catch
|
|
|
|
echohl ErrorMsg
|
2018-12-27 09:19:49 -05:00
|
|
|
echomsg 'signify: Changing directory failed: '. b:sy.info.dir
|
2018-12-20 16:04:09 -05:00
|
|
|
echohl NONE
|
|
|
|
return
|
|
|
|
endtry
|
2017-02-20 09:14:24 -05:00
|
|
|
let b:sy_job_id_{a:vcs} = jobstart(cmd, extend(options, {
|
|
|
|
\ 'on_stdout': function('s:callback_nvim_stdout'),
|
|
|
|
\ 'on_exit': function('s:callback_nvim_exit'),
|
|
|
|
\ }))
|
2018-12-20 16:04:09 -05:00
|
|
|
execute chdir fnameescape(cwd)
|
2017-01-18 11:15:15 -05:00
|
|
|
|
|
|
|
" Newer Vim
|
2017-02-20 09:03:34 -05:00
|
|
|
elseif has('patch-7.4.1967')
|
2017-02-17 10:25:00 -05:00
|
|
|
if type(job_id) != type(0)
|
2017-01-30 09:25:41 -05:00
|
|
|
silent! call job_stop(job_id)
|
2017-01-17 17:12:00 -05:00
|
|
|
endif
|
2017-01-18 11:15:15 -05:00
|
|
|
|
2017-04-18 11:13:17 -04:00
|
|
|
let [cmd, options] = s:initialize_job(a:vcs)
|
2019-08-01 11:44:01 -04:00
|
|
|
let options.func = a:func
|
2017-01-18 11:15:15 -05:00
|
|
|
let [cwd, chdir] = sy#util#chdir()
|
|
|
|
|
2018-12-27 09:37:51 -05:00
|
|
|
call sy#verbose(['CMD: '. string(cmd), 'CMD DIR: '. b:sy.info.dir, 'ORIG DIR: '. cwd], a:vcs)
|
2018-12-20 16:04:09 -05:00
|
|
|
|
2017-01-17 17:12:00 -05:00
|
|
|
try
|
2018-04-13 08:49:25 -04:00
|
|
|
execute chdir fnameescape(b:sy.info.dir)
|
2018-12-16 11:42:42 -05:00
|
|
|
catch
|
2018-12-20 16:04:09 -05:00
|
|
|
echohl ErrorMsg
|
|
|
|
echomsg 'signify: Changing directory failed: '. b:sy.info.dir
|
|
|
|
echohl NONE
|
|
|
|
return
|
2017-01-17 17:12:00 -05:00
|
|
|
endtry
|
2018-12-20 16:04:09 -05:00
|
|
|
let opts = {
|
|
|
|
\ 'in_io': 'null',
|
|
|
|
\ 'out_cb': function('s:callback_vim_stdout', options),
|
|
|
|
\ 'close_cb': function('s:callback_vim_close', options),
|
|
|
|
\ }
|
|
|
|
let b:sy_job_id_{a:vcs} = job_start(cmd, opts)
|
|
|
|
execute chdir fnameescape(cwd)
|
2017-01-18 11:15:15 -05:00
|
|
|
|
|
|
|
" Older Vim
|
2017-01-17 13:41:55 -05:00
|
|
|
else
|
2017-01-18 10:28:35 -05:00
|
|
|
let diff = split(s:run(a:vcs), '\n')
|
2017-04-18 11:13:17 -04:00
|
|
|
call sy#repo#get_diff_{a:vcs}(b:sy, v:shell_error, diff)
|
2017-01-17 13:41:55 -05:00
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2019-08-06 15:15:05 -04:00
|
|
|
" Function: s:handle_diff {{{1
|
|
|
|
function! s:handle_diff(options, exitval) abort
|
|
|
|
call sy#verbose('s:handle_diff()', a:options.vcs)
|
|
|
|
|
|
|
|
let sy = getbufvar(a:options.bufnr, 'sy')
|
|
|
|
if empty(sy)
|
|
|
|
call sy#verbose(printf('No b:sy found for %s', bufname(a:options.bufnr)), a:options.vcs)
|
|
|
|
return
|
|
|
|
elseif !empty(sy.updated_by) && sy.updated_by != a:options.vcs
|
|
|
|
call sy#verbose(printf('Signs already got updated by %s.', sy.updated_by), a:options.vcs)
|
|
|
|
return
|
|
|
|
elseif empty(sy.vcs) && sy.active
|
|
|
|
let sy.detecting -= 1
|
|
|
|
endif
|
|
|
|
|
|
|
|
let [found_diff, diff] = s:check_diff_{a:options.vcs}(a:exitval, a:options.stdoutbuf)
|
|
|
|
if found_diff
|
|
|
|
if index(sy.vcs, a:options.vcs) == -1
|
|
|
|
let sy.vcs += [a:options.vcs]
|
2017-04-18 10:59:48 -04:00
|
|
|
endif
|
2019-08-06 15:15:05 -04:00
|
|
|
call a:options.func(sy, a:options.vcs, diff)
|
2017-04-18 10:59:48 -04:00
|
|
|
else
|
2019-08-06 15:15:05 -04:00
|
|
|
call sy#verbose('No valid diff found. Disabling this VCS.', a:options.vcs)
|
2017-01-17 21:43:59 -05:00
|
|
|
endif
|
2019-08-06 15:15:05 -04:00
|
|
|
|
|
|
|
call setbufvar(a:options.bufnr, 'sy_job_id_'.a:options.vcs, 0)
|
2013-07-17 04:14:43 -04:00
|
|
|
endfunction
|
|
|
|
|
2019-08-06 15:15:05 -04:00
|
|
|
" Function: s:check_diff_git {{{1
|
|
|
|
function! s:check_diff_git(exitval, diff) abort
|
|
|
|
return a:exitval ? [0, []] : [1, a:diff]
|
2013-07-17 04:14:43 -04:00
|
|
|
endfunction
|
|
|
|
|
2019-08-06 15:15:05 -04:00
|
|
|
" Function: s:check_diff_yadm {{{1
|
|
|
|
function! s:check_diff_yadm(exitval, diff) abort
|
|
|
|
return a:exitval ? [0, []] : [1, a:diff]
|
2019-05-25 11:33:30 -04:00
|
|
|
endfunction
|
|
|
|
|
2019-08-06 15:15:05 -04:00
|
|
|
" Function: s:check_diff_hg {{{1
|
|
|
|
function! s:check_diff_hg(exitval, diff) abort
|
|
|
|
return a:exitval ? [0, []] : [1, a:diff]
|
2013-07-17 04:14:43 -04:00
|
|
|
endfunction
|
|
|
|
|
2019-08-06 15:15:05 -04:00
|
|
|
" Function: s:check_diff_svn {{{1
|
|
|
|
function! s:check_diff_svn(exitval, diff) abort
|
|
|
|
return a:exitval ? [0, []] : [1, a:diff]
|
2013-07-17 04:14:43 -04:00
|
|
|
endfunction
|
|
|
|
|
2019-08-06 15:15:05 -04:00
|
|
|
" Function: s:check_diff_bzr {{{1
|
|
|
|
function! s:check_diff_bzr(exitval, diff) abort
|
|
|
|
return (a:exitval =~ '[012]') ? [1, a:diff] : [0, []]
|
2013-07-17 04:14:43 -04:00
|
|
|
endfunction
|
|
|
|
|
2019-08-06 15:15:05 -04:00
|
|
|
" Function: s:check_diff_darcs {{{1
|
|
|
|
function! s:check_diff_darcs(exitval, diff) abort
|
|
|
|
return a:exitval ? [0, []] : [1, a:diff]
|
2013-07-17 04:14:43 -04:00
|
|
|
endfunction
|
|
|
|
|
2019-08-06 15:15:05 -04:00
|
|
|
" Function: s:check_diff_fossil {{{1
|
|
|
|
function! s:check_diff_fossil(exitval, diff) abort
|
|
|
|
return a:exitval ? [0, []] : [1, a:diff]
|
2013-07-17 04:14:43 -04:00
|
|
|
endfunction
|
|
|
|
|
2019-08-06 15:15:05 -04:00
|
|
|
" Function: s:check_diff_cvs {{{1
|
|
|
|
function! s:check_diff_cvs(exitval, diff) abort
|
2017-02-10 11:40:11 -05:00
|
|
|
let [found_diff, diff] = [0, []]
|
2017-01-22 20:58:40 -05:00
|
|
|
if a:exitval == 1
|
|
|
|
for diffline in a:diff
|
2018-04-15 11:49:03 -04:00
|
|
|
if diffline =~ '^+++'
|
2017-01-22 20:58:40 -05:00
|
|
|
let [found_diff, diff] = [1, a:diff]
|
|
|
|
break
|
|
|
|
endif
|
|
|
|
endfor
|
2019-04-05 05:11:49 -04:00
|
|
|
elseif a:exitval == 0 && len(a:diff) == 0
|
|
|
|
let found_diff = 1
|
2017-01-22 20:58:40 -05:00
|
|
|
endif
|
2019-08-06 15:15:05 -04:00
|
|
|
return [found_diff, diff]
|
2013-07-17 04:14:43 -04:00
|
|
|
endfunction
|
|
|
|
|
2019-08-06 15:15:05 -04:00
|
|
|
" Function: s:check_diff_rcs {{{1
|
|
|
|
function! s:check_diff_rcs(exitval, diff) abort
|
|
|
|
return (a:exitval == 2) ? [0, []] : [1, a:diff]
|
2013-07-17 04:14:43 -04:00
|
|
|
endfunction
|
|
|
|
|
2019-08-06 15:15:05 -04:00
|
|
|
" Function: s:check_diff_accurev {{{1
|
|
|
|
function! s:check_diff_accurev(exitval, diff) abort
|
|
|
|
return (a:exitval >= 2) ? [0, []] : [1, a:diff]
|
2013-07-17 04:14:43 -04:00
|
|
|
endfunction
|
|
|
|
|
2019-08-06 15:15:05 -04:00
|
|
|
" Function: s:check_diff_perforce {{{1
|
|
|
|
function! s:check_diff_perforce(exitval, diff) abort
|
|
|
|
return a:exitval ? [0, []] : [1, a:diff]
|
2013-07-29 15:15:07 -04:00
|
|
|
endfunction
|
|
|
|
|
2019-08-06 15:15:05 -04:00
|
|
|
" Function: s:check_diff_tfs {{{1
|
|
|
|
function! s:check_diff_tfs(exitval, diff) abort
|
|
|
|
return a:exitval ? [0, []] : [1, s:strip_context(a:diff)]
|
2016-02-24 19:18:41 -05:00
|
|
|
endfunction
|
|
|
|
|
2013-08-20 10:27:46 -04:00
|
|
|
" Function: #get_stats {{{1
|
|
|
|
function! sy#repo#get_stats() abort
|
2018-04-15 16:00:17 -04:00
|
|
|
return exists('b:sy') ? b:sy.stats : [-1, -1, -1]
|
2013-08-20 10:27:46 -04:00
|
|
|
endfunction
|
2015-05-19 08:01:26 -04:00
|
|
|
|
2015-05-26 04:59:29 -04:00
|
|
|
" Function: #debug_detection {{{1
|
|
|
|
function! sy#repo#debug_detection()
|
|
|
|
if !exists('b:sy')
|
|
|
|
echomsg 'signify: I cannot detect any changes!'
|
|
|
|
return
|
|
|
|
endif
|
2015-05-24 04:40:18 -04:00
|
|
|
|
2015-05-26 04:59:29 -04:00
|
|
|
for vcs in s:vcs_list
|
2018-04-13 09:01:47 -04:00
|
|
|
let cmd = s:expand_cmd(vcs, g:signify_vcs_cmds)
|
2015-05-26 04:59:29 -04:00
|
|
|
echohl Statement
|
|
|
|
echo cmd
|
|
|
|
echo repeat('=', len(cmd))
|
|
|
|
echohl NONE
|
|
|
|
|
2017-01-17 20:42:00 -05:00
|
|
|
let diff = s:run(vcs)
|
2015-05-26 04:59:29 -04:00
|
|
|
if v:shell_error
|
|
|
|
echohl ErrorMsg
|
|
|
|
echo diff
|
|
|
|
echohl NONE
|
|
|
|
else
|
|
|
|
echo empty(diff) ? "<none>" : diff
|
|
|
|
endif
|
|
|
|
echo "\n"
|
|
|
|
endfor
|
|
|
|
endfunction
|
|
|
|
|
2018-04-11 10:23:43 -04:00
|
|
|
" Function: #diffmode {{{1
|
2018-11-02 16:12:02 -04:00
|
|
|
function! sy#repo#diffmode(do_tab) abort
|
2018-04-15 16:00:17 -04:00
|
|
|
execute sy#util#return_if_no_changes()
|
|
|
|
|
2018-04-11 10:23:43 -04:00
|
|
|
let vcs = b:sy.updated_by
|
|
|
|
if !has_key(g:signify_vcs_cmds_diffmode, vcs)
|
|
|
|
echomsg 'SignifyDiff has no support for: '. vcs
|
|
|
|
echomsg 'Open an issue for it at: https://github.com/mhinz/vim-signify/issues'
|
|
|
|
return
|
|
|
|
endif
|
2018-04-13 09:01:47 -04:00
|
|
|
let cmd = s:expand_cmd(vcs, g:signify_vcs_cmds_diffmode)
|
2018-04-13 06:59:58 -04:00
|
|
|
call sy#verbose('SignifyDiff: '. cmd, vcs)
|
2018-04-11 10:23:43 -04:00
|
|
|
let ft = &filetype
|
2018-11-16 11:23:24 -05:00
|
|
|
let fenc = &fenc
|
2018-11-02 16:12:02 -04:00
|
|
|
if a:do_tab
|
|
|
|
tabedit %
|
|
|
|
endif
|
2018-04-11 10:23:43 -04:00
|
|
|
diffthis
|
2018-04-13 07:01:02 -04:00
|
|
|
let [cwd, chdir] = sy#util#chdir()
|
|
|
|
try
|
2018-04-13 08:49:25 -04:00
|
|
|
execute chdir fnameescape(b:sy.info.dir)
|
2018-04-13 07:01:02 -04:00
|
|
|
leftabove vnew
|
2018-11-16 11:23:24 -05:00
|
|
|
if has('iconv')
|
|
|
|
silent put =iconv(system(cmd), fenc, &enc)
|
|
|
|
else
|
|
|
|
silent put =system(cmd)
|
|
|
|
endif
|
2018-04-13 07:01:02 -04:00
|
|
|
finally
|
|
|
|
execute chdir fnameescape(cwd)
|
|
|
|
endtry
|
2018-04-11 10:23:43 -04:00
|
|
|
silent 1delete
|
|
|
|
set buftype=nofile bufhidden=wipe nomodified
|
|
|
|
let &filetype = ft
|
2019-02-19 08:18:31 -05:00
|
|
|
diffthis
|
2018-04-11 10:23:43 -04:00
|
|
|
wincmd p
|
|
|
|
normal! ]czt
|
|
|
|
endfunction
|
|
|
|
|
2019-08-05 18:34:17 -04:00
|
|
|
" Function: #preview_hunk {{{1
|
|
|
|
function! sy#repo#preview_hunk() abort
|
|
|
|
if exists('b:sy') && has_key(b:sy, 'updated_by')
|
2019-08-06 15:15:05 -04:00
|
|
|
call sy#repo#get_diff(b:sy.updated_by, function('s:preview_hunk'))
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:preview_hunk(_sy, vcs, diff) abort
|
|
|
|
call sy#verbose('s:preview_hunk()', a:vcs)
|
|
|
|
|
|
|
|
let in_hunk = 0
|
|
|
|
let hunk = []
|
|
|
|
|
|
|
|
for line in a:diff
|
|
|
|
if in_hunk
|
|
|
|
if line[:2] == '@@ '
|
|
|
|
break
|
|
|
|
endif
|
|
|
|
call add(hunk, line)
|
2019-08-06 17:36:35 -04:00
|
|
|
elseif line[:2] == '@@ ' && s:is_cur_line_in_hunk(line)
|
2019-08-06 15:15:05 -04:00
|
|
|
let in_hunk = 1
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
|
|
|
|
if !in_hunk
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2019-08-09 09:37:44 -04:00
|
|
|
if exists('*nvim_open_win')
|
|
|
|
call sy#util#renderPopup(hunk)
|
|
|
|
else
|
|
|
|
silent! wincmd P
|
|
|
|
if !&previewwindow
|
|
|
|
noautocmd botright new
|
|
|
|
endif
|
|
|
|
call setline(1, hunk)
|
|
|
|
silent! %foldopen!
|
|
|
|
setlocal previewwindow filetype=diff buftype=nofile bufhidden=delete
|
|
|
|
" With :noautocmd wincmd p, the first line of the preview window would show
|
|
|
|
" the 'cursorline', although it's not focused. Use feedkeys() instead.
|
|
|
|
noautocmd call feedkeys("\<c-w>p", 'nt')
|
2019-08-06 15:15:05 -04:00
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2019-08-06 17:36:35 -04:00
|
|
|
function! s:is_cur_line_in_hunk(hunkline) abort
|
|
|
|
let cur_line = line('.')
|
|
|
|
let [old_line, new_line, _old_count, new_count] = sy#sign#parse_hunk(a:hunkline)
|
2019-08-06 15:15:05 -04:00
|
|
|
|
2019-08-06 17:36:35 -04:00
|
|
|
if cur_line == 1 && new_line == 0
|
|
|
|
" deleted first line
|
|
|
|
return 1
|
|
|
|
endif
|
|
|
|
|
|
|
|
if cur_line == new_line && new_line < old_line
|
|
|
|
" deleted lines
|
|
|
|
return 1
|
|
|
|
endif
|
|
|
|
|
|
|
|
if cur_line >= new_line && cur_line < (new_line + new_count)
|
|
|
|
" added/changed lines
|
2019-08-06 15:15:05 -04:00
|
|
|
return 1
|
2019-08-05 18:34:17 -04:00
|
|
|
endif
|
2019-08-06 15:15:05 -04:00
|
|
|
|
|
|
|
return 0
|
2019-08-05 18:34:17 -04:00
|
|
|
endfunction
|
|
|
|
|
2017-01-18 07:40:34 -05:00
|
|
|
" Function: s:initialize_job {{{1
|
2017-04-18 11:13:17 -04:00
|
|
|
function! s:initialize_job(vcs) abort
|
2018-04-13 09:01:47 -04:00
|
|
|
let vcs_cmd = s:expand_cmd(a:vcs, g:signify_vcs_cmds)
|
2017-02-19 11:10:00 -05:00
|
|
|
if has('win32')
|
|
|
|
if has('nvim')
|
2019-03-21 04:55:49 -04:00
|
|
|
let cmd = &shell =~ '\v%(cmd|powershell)' ? vcs_cmd : ['sh', '-c', vcs_cmd]
|
2017-02-19 11:10:00 -05:00
|
|
|
else
|
2019-02-28 04:36:35 -05:00
|
|
|
if &shell =~ 'cmd'
|
2019-05-29 10:09:54 -04:00
|
|
|
let cmd = join([&shell, &shellcmdflag, '(', vcs_cmd, ')'])
|
2019-02-28 04:36:35 -05:00
|
|
|
elseif empty(&shellxquote)
|
|
|
|
let cmd = join([&shell, &shellcmdflag, &shellquote, vcs_cmd, &shellquote])
|
|
|
|
else
|
|
|
|
let cmd = join([&shell, &shellcmdflag, &shellxquote, vcs_cmd, &shellxquote])
|
|
|
|
endif
|
2017-02-19 11:10:00 -05:00
|
|
|
endif
|
|
|
|
else
|
|
|
|
let cmd = ['sh', '-c', vcs_cmd]
|
|
|
|
endif
|
2017-01-18 07:40:34 -05:00
|
|
|
let options = {
|
|
|
|
\ 'stdoutbuf': [],
|
|
|
|
\ 'vcs': a:vcs,
|
2017-01-23 07:37:48 -05:00
|
|
|
\ 'bufnr': bufnr('%'),
|
2017-01-18 07:40:34 -05:00
|
|
|
\ }
|
|
|
|
return [cmd, options]
|
|
|
|
endfunction
|
|
|
|
|
2017-01-17 20:42:00 -05:00
|
|
|
" Function: s:get_vcs_path {{{1
|
|
|
|
function! s:get_vcs_path(vcs) abort
|
2019-05-25 11:33:30 -04:00
|
|
|
return (a:vcs =~# '\v(git|cvs|accurev|tfs|yadm)') ? b:sy.info.file : b:sy.info.path
|
2017-01-17 20:42:00 -05:00
|
|
|
endfunction
|
|
|
|
|
2015-05-26 04:59:29 -04:00
|
|
|
" Function: s:expand_cmd {{{1
|
2018-04-13 09:01:47 -04:00
|
|
|
function! s:expand_cmd(vcs, vcs_cmds) abort
|
|
|
|
let cmd = a:vcs_cmds[a:vcs]
|
2018-04-11 10:23:43 -04:00
|
|
|
let cmd = s:replace(cmd, '%f', s:get_vcs_path(a:vcs))
|
|
|
|
let cmd = s:replace(cmd, '%d', s:difftool)
|
|
|
|
let cmd = s:replace(cmd, '%n', s:devnull)
|
|
|
|
return cmd
|
|
|
|
endfunction
|
|
|
|
|
2015-05-26 04:59:29 -04:00
|
|
|
" Function: s:run {{{1
|
2017-01-17 20:42:00 -05:00
|
|
|
function! s:run(vcs)
|
2017-01-18 11:15:15 -05:00
|
|
|
let [cwd, chdir] = sy#util#chdir()
|
2015-07-06 16:35:52 -04:00
|
|
|
try
|
2018-04-13 08:49:25 -04:00
|
|
|
execute chdir fnameescape(b:sy.info.dir)
|
2018-04-13 09:01:47 -04:00
|
|
|
let ret = system(s:expand_cmd(a:vcs, g:signify_vcs_cmds))
|
2015-07-06 16:35:52 -04:00
|
|
|
catch
|
|
|
|
" This exception message can be seen via :SignifyDebugUnknown.
|
|
|
|
" E.g. unquoted VCS programs in vcd_cmds can lead to E484.
|
|
|
|
let ret = v:exception .' at '. v:throwpoint
|
|
|
|
finally
|
2017-01-18 11:15:15 -05:00
|
|
|
execute chdir fnameescape(cwd)
|
2015-05-19 08:01:26 -04:00
|
|
|
return ret
|
2015-07-06 16:35:52 -04:00
|
|
|
endtry
|
2015-05-19 08:01:26 -04:00
|
|
|
endfunction
|
2015-05-19 08:57:40 -04:00
|
|
|
|
2015-06-04 03:51:48 -04:00
|
|
|
" Function: s:replace {{{1
|
|
|
|
function! s:replace(cmd, pat, sub)
|
2016-02-23 09:37:52 -05:00
|
|
|
let parts = split(a:cmd, a:pat, 1)
|
|
|
|
return join(parts, a:sub)
|
2015-06-04 03:51:48 -04:00
|
|
|
endfunction
|
|
|
|
|
2016-02-24 19:18:41 -05:00
|
|
|
" Function: s:strip_context {{{1
|
|
|
|
function! s:strip_context(context)
|
|
|
|
let diff = []
|
|
|
|
let hunk = []
|
|
|
|
let state = 0
|
2017-01-31 05:34:43 -05:00
|
|
|
let lines = a:context
|
2016-02-24 19:18:41 -05:00
|
|
|
let linenr = 0
|
|
|
|
|
|
|
|
while linenr < len(lines)
|
|
|
|
let line = lines[linenr]
|
|
|
|
|
|
|
|
if state == 0
|
|
|
|
if line =~ "^@@ "
|
2019-08-01 11:23:23 -04:00
|
|
|
let [old_line, new_line, old_count, new_count] = sy#sign#parse_hunk(line)
|
2016-06-01 12:11:44 -04:00
|
|
|
let hunk = []
|
2016-02-24 19:18:41 -05:00
|
|
|
let state = 1
|
|
|
|
else
|
|
|
|
call add(diff,line)
|
|
|
|
endif
|
2016-06-01 12:11:44 -04:00
|
|
|
let linenr += 1
|
|
|
|
elseif index([1,2,3],state) >= 0 && index(['\','/'],line[0]) >= 0
|
|
|
|
let linenr += 1
|
|
|
|
call add(hunk,line)
|
2016-02-24 19:18:41 -05:00
|
|
|
elseif state == 1
|
|
|
|
if line[0] == ' '
|
2016-06-01 12:11:44 -04:00
|
|
|
let old_line += 1
|
|
|
|
let new_line += 1
|
|
|
|
let old_count -= 1
|
|
|
|
let new_count -= 1
|
|
|
|
let linenr += 1
|
2016-02-24 19:18:41 -05:00
|
|
|
else
|
|
|
|
let old_count_part = 0
|
|
|
|
let new_count_part = 0
|
|
|
|
let state = 2
|
|
|
|
endif
|
|
|
|
elseif state == 2
|
|
|
|
if line[0] == '-'
|
|
|
|
call add(hunk,line)
|
2016-06-01 12:11:44 -04:00
|
|
|
let old_count_part += 1
|
|
|
|
let linenr += 1
|
2016-02-24 19:18:41 -05:00
|
|
|
else
|
|
|
|
let state = 3
|
|
|
|
endif
|
|
|
|
elseif state == 3
|
|
|
|
if line[0] == '+'
|
|
|
|
call add(hunk,line)
|
2016-06-01 12:11:44 -04:00
|
|
|
let new_count_part += 1
|
|
|
|
let linenr += 1
|
2016-02-24 19:18:41 -05:00
|
|
|
else
|
2016-06-01 12:11:44 -04:00
|
|
|
call add(diff, printf("@@ -%d%s +%d%s @@",(old_count_part == 0 && old_line > 0) ? old_line -1 : old_line, old_count_part == 1 ? "" : printf(",%d", old_count_part), (new_count_part == 0 && new_line > 0) ? new_line - 1 : new_line, new_count_part == 1 ? "" : printf(",%d", new_count_part)))
|
|
|
|
let diff += hunk
|
2016-02-24 19:18:41 -05:00
|
|
|
let hunk = []
|
2016-06-01 12:11:44 -04:00
|
|
|
let old_count -= old_count_part
|
|
|
|
let new_count -= new_count_part
|
|
|
|
let old_line += old_count_part
|
|
|
|
let new_line += new_count_part
|
2016-02-24 19:18:41 -05:00
|
|
|
let state = 1
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
|
|
|
if state > 0 && new_count <= 0 && old_count <= 0
|
|
|
|
if len(hunk) > 0
|
2016-06-01 12:11:44 -04:00
|
|
|
call add(diff, printf("@@ -%d%s +%d%s @@",(old_count_part == 0 && old_line > 0) ? old_line -1 : old_line, old_count_part == 1 ? "" : printf(",%d", old_count_part), (new_count_part == 0 && new_line > 0) ? new_line - 1 : new_line, new_count_part == 1 ? "" : printf(",%d", new_count_part)))
|
2016-02-24 19:18:41 -05:00
|
|
|
let diff = diff + hunk
|
|
|
|
let hunk = []
|
|
|
|
endif
|
|
|
|
let state = 0
|
|
|
|
endif
|
|
|
|
endwhile
|
2016-06-01 12:11:44 -04:00
|
|
|
if len(hunk) > 0
|
|
|
|
call add(diff, printf("@@ -%d%s +%d%s @@",(old_count_part == 0 && old_line > 0) ? old_line -1 : old_line, old_count_part == 1 ? "" : printf(",%d", old_count_part), (new_count_part == 0 && new_line > 0) ? new_line - 1 : new_line, new_count_part == 1 ? "" : printf(",%d", new_count_part)))
|
|
|
|
let diff = diff + hunk
|
|
|
|
let hunk = []
|
|
|
|
endif
|
2017-01-31 05:34:43 -05:00
|
|
|
return diff
|
2016-02-24 19:18:41 -05:00
|
|
|
endfunction
|
|
|
|
|
2015-05-20 08:00:39 -04:00
|
|
|
" Variables {{{1
|
2015-05-20 07:11:26 -04:00
|
|
|
let s:difftool = get(g:, 'signify_difftool', 'diff')
|
|
|
|
if executable(s:difftool)
|
|
|
|
let s:vcs_dict = {
|
|
|
|
\ 'git': 'git',
|
2019-05-25 11:33:30 -04:00
|
|
|
\ 'yadm': 'yadm',
|
2015-05-20 07:11:26 -04:00
|
|
|
\ 'hg': 'hg',
|
|
|
|
\ 'svn': 'svn',
|
|
|
|
\ 'darcs': 'darcs',
|
|
|
|
\ 'bzr': 'bzr',
|
|
|
|
\ 'fossil': 'fossil',
|
|
|
|
\ 'cvs': 'cvs',
|
|
|
|
\ 'rcs': 'rcsdiff',
|
|
|
|
\ 'accurev': 'accurev',
|
2016-02-24 19:18:41 -05:00
|
|
|
\ 'perforce': 'p4',
|
|
|
|
\ 'tfs': 'tf'
|
2015-05-20 07:11:26 -04:00
|
|
|
\ }
|
|
|
|
else
|
2019-03-28 03:39:42 -04:00
|
|
|
call sy#verbose('No "diff" executable found. Disable support for svn, darcs, bzr.')
|
2015-05-20 07:11:26 -04:00
|
|
|
let s:vcs_dict = {
|
|
|
|
\ 'git': 'git',
|
2019-05-25 11:33:30 -04:00
|
|
|
\ 'yadm': 'yadm',
|
2015-05-20 07:11:26 -04:00
|
|
|
\ 'hg': 'hg',
|
2019-03-28 03:39:42 -04:00
|
|
|
\ 'fossil': 'fossil',
|
2015-05-20 07:11:26 -04:00
|
|
|
\ 'cvs': 'cvs',
|
|
|
|
\ 'rcs': 'rcsdiff',
|
|
|
|
\ 'accurev': 'accurev',
|
2016-02-24 19:18:41 -05:00
|
|
|
\ 'perforce': 'p4',
|
|
|
|
\ 'tfs': 'tf'
|
2015-05-20 07:11:26 -04:00
|
|
|
\ }
|
|
|
|
endif
|
|
|
|
|
|
|
|
let s:vcs_list = get(g:, 'signify_vcs_list', [])
|
|
|
|
if empty(s:vcs_list)
|
|
|
|
let s:vcs_list = keys(filter(s:vcs_dict, 'executable(v:val)'))
|
|
|
|
endif
|
|
|
|
|
2018-04-11 10:36:35 -04:00
|
|
|
let s:default_vcs_cmds = {
|
2015-05-20 07:11:26 -04:00
|
|
|
\ 'git': 'git diff --no-color --no-ext-diff -U0 -- %f',
|
2019-05-25 11:33:30 -04:00
|
|
|
\ 'yadm': 'yadm diff --no-color --no-ext-diff -U0 -- %f',
|
2018-10-31 11:59:03 -04:00
|
|
|
\ 'hg': 'hg diff --color=never --config aliases.diff= --nodates -U0 -- %f',
|
2015-05-20 07:11:26 -04:00
|
|
|
\ 'svn': 'svn diff --diff-cmd %d -x -U0 -- %f',
|
|
|
|
\ 'bzr': 'bzr diff --using %d --diff-options=-U0 -- %f',
|
2017-07-27 10:39:59 -04:00
|
|
|
\ 'darcs': 'darcs diff --no-pause-for-gui --no-unified --diff-opts=-U0 -- %f',
|
2019-01-24 13:07:00 -05:00
|
|
|
\ 'fossil': 'fossil diff --unified -c 0 -- %f',
|
2015-05-20 07:11:26 -04:00
|
|
|
\ 'cvs': 'cvs diff -U0 -- %f',
|
2015-05-20 08:22:52 -04:00
|
|
|
\ 'rcs': 'rcsdiff -U0 %f 2>%n',
|
2015-05-20 07:11:26 -04:00
|
|
|
\ 'accurev': 'accurev diff %f -- -U0',
|
2018-08-02 04:57:48 -04:00
|
|
|
\ 'perforce': 'p4 info '. sy#util#shell_redirect('%n') . (has('win32') ? ' &&' : ' && env P4DIFF= P4COLORS=') .' p4 diff -du0 %f',
|
2016-02-24 19:18:41 -05:00
|
|
|
\ 'tfs': 'tf diff -version:W -noprompt -format:Unified %f'
|
2015-05-20 07:11:26 -04:00
|
|
|
\ }
|
|
|
|
|
2018-04-11 10:36:35 -04:00
|
|
|
let s:default_vcs_cmds_diffmode = {
|
2018-05-03 11:36:43 -04:00
|
|
|
\ 'git': 'git show HEAD:./%f',
|
2019-05-25 11:33:30 -04:00
|
|
|
\ 'yadm': 'yadm show HEAD:./%f',
|
2018-05-03 11:36:43 -04:00
|
|
|
\ 'hg': 'hg cat %f',
|
|
|
|
\ 'svn': 'svn cat %f',
|
|
|
|
\ 'bzr': 'bzr cat %f',
|
|
|
|
\ 'darcs': 'darcs show contents -- %f',
|
2019-03-28 03:39:42 -04:00
|
|
|
\ 'fossil': 'fossil cat %f',
|
2018-05-03 11:36:43 -04:00
|
|
|
\ 'cvs': 'cvs up -p -- %f 2>%n',
|
|
|
|
\ 'perforce': 'p4 print %f',
|
2018-04-11 10:36:35 -04:00
|
|
|
\ }
|
|
|
|
|
2015-05-20 07:11:26 -04:00
|
|
|
if exists('g:signify_vcs_cmds')
|
2018-04-11 10:36:35 -04:00
|
|
|
call extend(g:signify_vcs_cmds, s:default_vcs_cmds, 'keep')
|
2015-11-04 09:12:08 -05:00
|
|
|
else
|
2018-04-11 10:36:35 -04:00
|
|
|
let g:signify_vcs_cmds = s:default_vcs_cmds
|
|
|
|
endif
|
|
|
|
if exists('g:signify_vcs_cmds_diffmode')
|
|
|
|
call extend(g:signify_vcs_cmds_diffmode, s:default_vcs_cmds_diffmode, 'keep')
|
|
|
|
else
|
|
|
|
let g:signify_vcs_cmds_diffmode = s:default_vcs_cmds_diffmode
|
2015-05-20 07:11:26 -04:00
|
|
|
endif
|
2018-04-11 10:23:43 -04:00
|
|
|
|
2015-05-20 08:00:39 -04:00
|
|
|
let s:difftool = sy#util#escape(s:difftool)
|
2015-05-20 07:11:26 -04:00
|
|
|
let s:devnull = has('win32') || has ('win64') ? 'NUL' : '/dev/null'
|