diff tests/test-import.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 67e92d29ecb5
children cf0f3cb8a332
line wrap: on
line diff
--- a/tests/test-import.t	Tue Nov 08 17:08:58 2011 +0100
+++ b/tests/test-import.t	Wed Nov 09 16:55:59 2011 -0800
@@ -958,3 +958,39 @@
   $ diff want have
   $ cd ..
 
+import a unified diff with no lines of context (diff -U0)
+
+  $ hg init diffzero
+  $ cd diffzero
+  $ cat > f << EOF
+  > c2
+  > c4
+  > c5
+  > EOF
+  $ hg commit -Am0
+  adding f
+
+  $ hg import --no-commit - << EOF
+  > # HG changeset patch
+  > # User test
+  > # Date 0 0
+  > # Node ID f4974ab632f3dee767567b0576c0ec9a4508575c
+  > # Parent  8679a12a975b819fae5f7ad3853a2886d143d794
+  > 1
+  > diff -r 8679a12a975b -r f4974ab632f3 f
+  > --- a/f	Thu Jan 01 00:00:00 1970 +0000
+  > +++ b/f	Thu Jan 01 00:00:00 1970 +0000
+  > @@ -0,0 +1,1 @@
+  > +c1
+  > @@ -1,0 +3,1 @@
+  > +c3
+  > @@ -3,1 +4,0 @@
+  > -c5
+  > EOF
+  applying patch from stdin
+
+  $ cat f
+  c1
+  c2
+  c3
+  c4