changeset 7436:07faba78cf5a

diff: fix obscure off-by-one error in diff -p
author Dirkjan Ochtman <dirkjan@ochtman.nl>
date Thu, 27 Nov 2008 17:00:54 +0100
parents 5e13df32fb74
children 3cdaac732b2b
files mercurial/mdiff.py tests/test-diff-unified
diffstat 2 files changed, 12 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/mdiff.py	Thu Nov 27 16:07:17 2008 +0100
+++ b/mercurial/mdiff.py	Thu Nov 27 17:00:54 2008 +0100
@@ -160,7 +160,7 @@
         if opts.showfunc:
             # walk backwards from the start of the context
             # to find a line starting with an alphanumeric char.
-            for x in xrange(astart, -1, -1):
+            for x in xrange(astart - 1, -1, -1):
                 t = l1[x].rstrip()
                 if funcre.match(t):
                     func = ' ' + t[:40]
--- a/tests/test-diff-unified	Thu Nov 27 16:07:17 2008 +0100
+++ b/tests/test-diff-unified	Thu Nov 27 17:00:54 2008 +0100
@@ -44,6 +44,15 @@
 echo '% invalid diff.unified'
 hg --config diff.unified=foo diff --nodates
 
-exit 0
+echo % test off-by-one error with diff -p
+hg init diffp
+cd diffp
+echo a > a
+hg ci -Ama
+rm a
+echo b > a
+echo a >> a
+echo c >> a
+hg diff -U0 -p
 
-
+exit 0