2

我有统一差异格式的“cvs diff”输出(对于项目中的所有文件)。格式可能是这样的:

Index: somefile.cpp
===================================================================
RCS file: /CVS_repo/SomeProject/somefile.cpp,v
retrieving revision 1.19
diff -r1.19 somefile.cpp
31c31
<       return "Read line four times";
---
>       return "Read line five times";
36c36
<       return "Make a bad thing";
---
>       return "Make a good thing";
Index: otherfile.cpp
===================================================================
RCS file: /CVS_repo/SomeProject/otherfile.cpp,v
retrieving revision 1.19
<       ........
---
>       ........

甚至像这样:

Index: somefile.cpp
===================================================================
RCS file: /CVS_repo/SomeProject/somefile.cpp,v
retrieving revision 1.19
diff -u -r1.19 somefile.cpp
--- somefile.cpp 13 Mar 2013 08:45:18 -0000      1.19
+++ somefile.cpp 26 Mar 2013 08:10:33 -0000
@@ -28,12 +28,12 @@
 //---------------------------------------------------------------------------
 extern "C" char *FuncGetSomeText()
 {
-       return "Read line four times";
+       return "Read line five times";
 }
 //---------------------------------------------------------------------------
 extern "C" char *FuncGetAwesomeText()
 {
-       return "Make a bad thing";
+       return "Make a good thing";
 }
 //---------------------------------------------------------------------------
Index: otherfile.cpp
===================================================================
RCS file: /CVS_repo/SomeProject/otherfile.cpp,v
retrieving revision 1.19
diff -u -r1.19 otherfile.cpp
--- otherfile.cpp 13 Mar 2013 08:45:18 -0000      1.19
+++ otherfile.cpp 26 Mar 2013 08:10:33 -0000
@@ -28,12 +28,12 @@
 //---------------------------------------------------------------------------
 extern "C" char *Func()
 {
-       .......
+       .......
 }
 //---------------------------------------------------------------------------

有什么方法可以与 vim 并排查看此文本?或者也许可以将 cvs 中的默认差异工具更改为 vimdiff?

4

1 回答 1

0

Some sed magic help me:

\cvs -n diff -u > ~diff.tmp; vim -O <(sed -r -e 's/^\+[^\+]+.*$//g;s/^\+$//g' ~diff.tmp) <(sed -r -e 's/^-[^-]+.*$//g;s/^-$//g' ~diff.tmp) +'set scb | set nowrap | wincmd w | set scb | set nowrap'

It is not perfect solution, but better then nothing. Here what this script doing:

\cvs -n diff -u > ~diff.tmp; 

Write CVS diff output in unified format (-u option) to temp file ~diff.tmp. '\' char prevent from taking alias of "cvs" command.

(sed -r -e 's/^\+[^\+]+.*$//g;s/^\+$//g' ~diff.tmp)
(sed -r -e 's/^-[^-]+.*$//g;s/^-$//g' ~diff.tmp)

This commands output text from ~diff.tmp, replace lines beginning with '+' and '-' symbols with empty line.

vim -O <(sed...) <(sed...) +'set scb | set nowrap | wincmd w | set scb | set nowrap'

Open two windows (-O option) with sed's output in each. Command followed '+' set srollbind on and nowrap for first window, then switch to second window (with 'wincmd w') and do same things

于 2013-04-12T07:09:26.040 回答