4

出于代码审查的目的,在修改现有源文件后,我们仅审查这些源文件中已更改的代码行。
在对存储库中的源文件进行更改后,我必须在进行同行代码审查之前传达源文件中已更改的代码行。

我可以使用 WinMerge 看到视觉差异,并且我对它为我所做的感到满意,但对我的同事的唯一要求就是知道需要查看的文件名和行号。

有没有办法只获取已更改文件的行号?文件类型可以是文本源文件,例如 Javascript、Java、XML、XSL 等。

示例文件——

富(新版本):

a
b
c
d
e
f
g
h
i
j
k

foo(旧版本):

a
b
C
d
h
i
k

我正在寻找的输出:

foo: 3, 5-7, 10-11

或者

foo:
3
5-7
10-11

我确信某些程序允许这样做。我就是找不到。有什么建议么?我目前正在使用 WinMerge,但任何在 Windows 上运行的程序都可以。如果该软件是开源软件或免费软件,那就更好了。

编辑:GNU DiffUtils 接近我想要的,但不完全符合我的需要。查看命令行选项,我将“-q”(或“--brief”)视为简化的差异,但它太简单了。输出:

C:\Program Files\GnuWin32\bin>diff.exe -q foo1.txt foo2.txt
Files foo1.txt and foo2.txt differ

正常差异输出:

C:\Program Files\GnuWin32\bin>diff.exe foo1.txt foo2.txt
3c3
<     c
---
>     C
5,7d4
<     e
<     f
<     g
10,11c7
<     j
<     k
---
>     k
\ No newline at end of file

差异 -u 输出:

C:\Program Files\GnuWin32\bin>diff.exe -u foo1.txt foo2.txt
--- foo1.txt    2010-11-09 15:47:12.447916000 -0600
+++ foo2.txt    2010-11-09 15:47:36.129954700 -0600
@@ -1,11 +1,7 @@
     a
     b
-    c
+    C
     d
-    e
-    f
-    g
     h
     i
-    j
-    k
+    k
\ No newline at end of file

我正在寻找比 diff -q 提供更多信息的东西,但比 diff -u 和 diff 提供的信息更少。那里有任何差异忍者知道允许这样做的不同选项吗?

我将始终将最近修改的新文件与旧文件进行比较。我只需要在新文件上需要审查的东西。

4

4 回答 4

3

GNU DiffUtils 是开源的、免费的,并且有一个 Windows 端口

于 2010-11-10T03:28:16.303 回答
2

将第一个文件保存为 x.txt,将第二个文件保存为 y.txt

然后运行:

diff -i --unchanged-line-format="¥" --new-line-format=":%dn: %L" y.txt x.txt | perl -pe 's/¥/\n/g' | perl -pe '$count++; if ($_ !~ /^\n$/){print "$count\t";}'

于 2014-01-22T19:23:30.963 回答
1

不知道 Windows 原生方法,但我为此使用了 Textpad 的“比较文件”功能,它非常好。

于 2010-11-09T21:59:53.137 回答
1

Windows 原生。我们的SD Smart Differencer不是在行上而是在程序结构上产生增量,并且对于行/列-行/列以及被编辑的程序实体的类型是精确的。它通过解析源文本进行比较,并使用代码结构来驱动比较。增量是根据程序员感兴趣的操作来描述的:插入、替换、删除、替换。

这是一个例子:

Java~Java1_5 SmartDifferencer Version 1.1.1
Copyright (C) 2009 Semantic Designs, Inc; All Rights Reserved; SD Confidential
Powered by DMS (R) Software Reengineering Toolkit
*** Parsing file C:/DMS/Domains/Java/Java1_5/Analyzers/SmartDifferencer/Tests/diff1_before.java ...
*** Parsing file C:/DMS/Domains/Java/Java1_5/Analyzers/SmartDifferencer/Tests/diff1_after.java ...
*** Creating suffix tree ...
*** Determining maximal pairs ...
*** Sorting maximal pairs ...
*** Determining differences ...
*** Printing edits ...
a12.5 I s12.5-12.57:field_declaration
a179.9 I s185.9-185.71:executable_statement
a193.5 I s201.9-203.9:executable_statement
a272.13 I t279.13-280.33f267.13-268.30[267.17'lineNum'~>279.17'endLineNum',268.17'columnNum'~>280.17'endColumnNum']:statement_sequence_member,statement_sequence_member
a340.68 I s352.68-352.68:',' s352.70-352.70:INTEGER s352.71-352.71:',' s352.73-352.73:INTEGER
a423.13 I t436.13-509.38f450.17-518.35[482.17'hlevel'~>468.13'endLineNum',518.17'hname'~>509.13'endColumnNum']:executable_statement,executable_statement,executable_statement,executable_statement,executable_statement,executable_statement,executable_statement,executable_statement,executable_statement,executable_statement,executable_statement,executable_statement
a423.84 I s513.84-513.84:',' s513.86-513.95:IDENTIFIER s513.96-513.96:',' s513.98-513.109:IDENTIFIER
s424.13-424.59:expression_statement S s514.25-514.47:expression_statement
s429.13-429.64:local_variable_declaration S s515.25-515.87:local_variable_declaration
s430.13-430.71:executable_statement f431.13-431.69[431.13'lineString'~>79.9'config',431.26'lineString'~>79.18'config',431.47'indexOfSpace'~>79.35'end_index']t79.9-79.56:executable_statement s432.13-432.51:executable_statement D a516.25
a433.13 I s516.25-519.25:executable_statement n433.13-439.13:executable_statement s433.13-433.14:'if' s433.16-433.16:'(' s433.17-433.30:relational_expression s433.31-433.31:')' s433.33-433.45:executable_statement s434.13-434.16:'else' n434.18-439.13:block s434.18-434.18:'{' n435.17-438.49:statement_sequence f435.17-435.71[435.17'lineString'~>79.9'config',435.28'lineString'~>79.18'config',435.49'indexOfSpace'~>79.35'end_index']t79.9-79.56:executable_statement s436.17-436.28:executable_statement s437.17-437.51:executable_statement s438.17-438.49:executable_statement s439.13-439.13:'}' D a516.25
a442.13 I s520.25-520.54:executable_statement

高级编辑操作是“I”、“S”、“R”和“D”,详细说明在 I/S/R/D 字符的左侧或右侧添加、插入或删除了什么和行.column 精度。例如,在第 12 行第 5 列,在第 12 行第 5 列到第 57 列中插入了一个字段声明“I”。在第 272 行,从第 279-280 行插入了一个代码块,其中标识符 lineNum 替换为 endLineNum。在第二个文件的第 424 行,表达式语句已被“S”替换为最初来自第 514 行的一个。更多详细信息请参见网站。

如果你想用 Perl 之类的东西,你可以很容易地去掉额外的细节(“:”字符后面和 [] 里面的东西)。

于 2010-11-09T22:39:48.937 回答