diff tests/test-diff-unified.t @ 15462:2b1ec74c961f stable

mdiff/patch: fix bad hunk handling for unified diffs with zero context Prior to this patch "hg diff -U0", i.e., zero lines of context, would output hunk headers with a start line one greater than what GNU patch and git output. Guido van Rossum documents the unified diff format[1] as having a start line value "one lower than one would expect" for zero length hunks. Comparing the behaviour of the three systems prior to this patch in transforming c1 c3 to c1 c2 c3 - GNU "diff -U0" reports the hunk as "@@ -1,0 +2 @@" - "git diff -U0" reports the hunk as "@@ -1,0 +2 @@" - "hg diff -U0" reports the hunk as "@@ -2,0 +2,1 @@" After this patch, "hg diff -U0" reports "@@ -1,0 +2,1 @@". Since "hg export --config diff.unified=0" outputs zero-context unified diffs, "hg import" has also been updated to account for start lines one less than expected for zero length hunk ranges. [1]: http://www.artima.com/weblogs/viewpost.jsp?thread=164293
author Nicolas Venegas <nvenegas@atlassian.com>
date Wed, 09 Nov 2011 16:55:59 -0800
parents 4134686b83e1
children 10c8110d114b
line wrap: on
line diff
--- a/tests/test-diff-unified.t	Tue Nov 08 17:08:58 2011 +0100
+++ b/tests/test-diff-unified.t	Wed Nov 09 16:55:59 2011 -0800
@@ -89,23 +89,65 @@
   abort: diff context lines count must be an integer, not 'foo'
   [255]
 
-test off-by-one error with diff -p
+0 lines of context hunk header matches gnu diff hunk header
+
+  $ hg init diffzero
+  $ cd diffzero
+  $ cat > f1 << EOF
+  > c2
+  > c4
+  > c5
+  > EOF
+  $ hg commit -Am0
+  adding f1
+
+  $ cat > f2 << EOF
+  > c1
+  > c2
+  > c3
+  > c4
+  > EOF
+  $ diff -U0 f1 f2
+  --- f1	* (glob)
+  +++ f2	* (glob)
+  @@ -0,0 +1 @@
+  +c1
+  @@ -1,0 +3 @@
+  +c3
+  @@ -3 +4,0 @@
+  -c5
+  [1]
 
-  $ hg init diffp
-  $ cd diffp
-  $ echo a > a
-  $ hg ci -Ama
-  adding a
-  $ rm a
-  $ echo b > a
-  $ echo a >> a
-  $ echo c >> a
-  $ hg diff -U0 -p --nodates
-  diff -r cb9a9f314b8b a
-  --- a/a
-  +++ b/a
-  @@ -1,0 +1,1 @@
-  +b
-  @@ -2,0 +3,1 @@ a
-  +c
+  $ mv f2 f1
+  $ hg diff -U0 --nodates
+  diff -r 55d8ff78db23 f1
+  --- a/f1
+  +++ b/f1
+  @@ -0,0 +1,1 @@
+  +c1
+  @@ -1,0 +3,1 @@
+  +c3
+  @@ -3,1 +4,0 @@
+  -c5
 
+  $ hg diff -U0 --nodates --git
+  diff --git a/f1 b/f1
+  --- a/f1
+  +++ b/f1
+  @@ -0,0 +1,1 @@
+  +c1
+  @@ -1,0 +3,1 @@
+  +c3
+  @@ -3,1 +4,0 @@
+  -c5
+
+  $ hg diff -U0 --nodates -p
+  diff -r 55d8ff78db23 f1
+  --- a/f1
+  +++ b/f1
+  @@ -0,0 +1,1 @@
+  +c1
+  @@ -1,0 +3,1 @@ c2
+  +c3
+  @@ -3,1 +4,0 @@ c4
+  -c5