From 051dc1a853cb86231497c58a5c06dc82a17837ca Mon Sep 17 00:00:00 2001 From: Marco Hinz Date: Thu, 25 Feb 2016 01:18:41 +0100 Subject: [PATCH] Add support for Team Foundation Server The actual patch is courtesy of @Grueslayer. Thanks! Closes #177. --- README.md | 2 +- autoload/sy/repo.vim | 88 +++++++++++++++++++++++++++++++++++++++++++- doc/signify.txt | 3 ++ 3 files changed, 90 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index faefe68..619310b 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ implements features that work for _all_ supported VCS. **Features:** - supports git, mercurial, darcs, bazaar, subversion, cvs, rcs, fossil, accurev, - perforce + perforce, tfs - quick jumping between blocks of changed lines ("hunks") - apart from signs there is also optional line highlighting - preserves signs from other plugins diff --git a/autoload/sy/repo.vim b/autoload/sy/repo.vim index e80d46c..ce36349 100644 --- a/autoload/sy/repo.vim +++ b/autoload/sy/repo.vim @@ -85,6 +85,12 @@ function! sy#repo#get_diff_perforce() abort return v:shell_error ? [0, ''] : [1, diff] endfunction +" Function: #get_diff_tfs {{{1 +function! sy#repo#get_diff_tfs() abort + let diff = s:run(g:signify_vcs_cmds.tfs, b:sy_info.file, 0) + return v:shell_error ? [0, ''] : [1, s:strip_context(diff)] +endfunction + " Function: #get_stats {{{1 function! sy#repo#get_stats() abort if !exists('b:sy') || !has_key(b:sy, 'stats') @@ -112,6 +118,7 @@ function! sy#repo#debug_detection() \ 'rcs': [g:signify_vcs_cmds.rcs, b:sy_info.path, 0], \ 'accurev': [g:signify_vcs_cmds.accurev, b:sy_info.file, 1], \ 'perforce': [g:signify_vcs_cmds.perforce, b:sy_info.path, 0], + \ 'tfs': [g:signify_vcs_cmds.tfs, b:sy_info.file, 0], \ } for vcs in s:vcs_list @@ -167,6 +174,80 @@ function! s:replace(cmd, pat, sub) endif endfunction +" Function: s:strip_context {{{1 +function! s:strip_context(context) + let diff = [] + let hunk = [] + let state = 0 + let lines = split(a:context,"\n",1) + let linenr = 0 + + while linenr < len(lines) + let line = lines[linenr] + + if state == 0 + if line =~ "^@@ " + let tokens = matchlist(line, '^@@ -\v(\d+),?(\d*) \+(\d+),?(\d*)') + let old_line = str2nr(tokens[1]) + let new_line = str2nr(tokens[3]) + let old_count = empty(tokens[2]) ? 1 : str2nr(tokens[2]) + let new_count = empty(tokens[4]) ? 1 : str2nr(tokens[4]) + let state = 1 + else + call add(diff,line) + endif + let linenr = linenr + 1 + elseif state == 1 + if line[0] == ' ' + let old_line = old_line + 1 + let new_line = new_line + 1 + let old_count = old_count - 1 + let new_count = new_count - 1 + let linenr = linenr + 1 + else + let hunk = [] + let old_count_part = 0 + let new_count_part = 0 + let state = 2 + endif + elseif state == 2 + if line[0] == '-' + call add(hunk,line) + let old_count_part = old_count_part + 1 + let linenr = linenr + 1 + else + let state = 3 + endif + elseif state == 3 + if line[0] == '+' + call add(hunk,line) + let new_count_part = new_count_part + 1 + let linenr = linenr + 1 + else + call add(diff, printf("@@ -%d,%d +%d,%d @@",old_line, old_count_part, (new_count_part == 0 && new_line > 0) ? new_line - 1 : new_line, new_count_part)) + let diff = diff + hunk + let hunk = [] + let old_count = old_count - old_count_part + let new_count = new_count - new_count_part + let old_line = old_line + old_count_part + let new_line = new_line + new_count_part + let state = 1 + endif + endif + + if state > 0 && new_count <= 0 && old_count <= 0 + if len(hunk) > 0 + call add(diff, printf("@@ -%d,%d +%d,%d @@",old_line, old_count_part, (new_count_part == 0 && new_line > 0) ? new_line - 1 : new_line, new_count_part)) + let diff = diff + hunk + let hunk = [] + endif + let state = 0 + endif + endwhile + + return join(diff,"\n")."\n" +endfunction + " Variables {{{1 let s:difftool = get(g:, 'signify_difftool', 'diff') if executable(s:difftool) @@ -180,7 +261,8 @@ if executable(s:difftool) \ 'cvs': 'cvs', \ 'rcs': 'rcsdiff', \ 'accurev': 'accurev', - \ 'perforce': 'p4' + \ 'perforce': 'p4', + \ 'tfs': 'tf' \ } else echomsg 'signify: No diff tool found -> no support for svn, darcs, bzr, fossil.' @@ -190,7 +272,8 @@ else \ 'cvs': 'cvs', \ 'rcs': 'rcsdiff', \ 'accurev': 'accurev', - \ 'perforce': 'p4' + \ 'perforce': 'p4', + \ 'tfs': 'tf' \ } endif @@ -210,6 +293,7 @@ let s:vcs_cmds = { \ 'rcs': 'rcsdiff -U0 %f 2>%n', \ 'accurev': 'accurev diff %f -- -U0', \ 'perforce': 'p4 info '. sy#util#shell_redirect('%n') .' && env P4DIFF=%d p4 diff -dU0 %f', + \ 'tfs': 'tf diff -version:W -noprompt -format:Unified %f' \ } if exists('g:signify_vcs_cmds') diff --git a/doc/signify.txt b/doc/signify.txt index c6dc764..1ba1332 100644 --- a/doc/signify.txt +++ b/doc/signify.txt @@ -63,6 +63,7 @@ Supported VCS:~ fossil accurev perforce + tfs < Sign explanation:~ @@ -123,6 +124,7 @@ Possible values: 'accurev' 'perforce' 'rcs' 'svn' + 'tfs' NOTE: This is the most important option, so read closely. @@ -186,6 +188,7 @@ Default: \ 'rcs': 'rcsdiff -U0 %f 2>%n', \ 'accurev': 'accurev diff %f -- -U0', \ 'perforce': 'p4 info '. sy#util#shell_redirect('%n') .' && env P4DIFF=%d p4 diff -dU0 %f' + \ 'tfs': 'tf diff -version:W -noprompt %f', \ } < ------------------------------------------------------------------------------