diff: fix obscure off-by-one error in diff -p
authorDirkjan Ochtman <dirkjan@ochtman.nl>
Thu, 27 Nov 2008 17:00:54 +0100
changeset 7436 07faba78cf5a
parent 7435 5e13df32fb74
child 7437 3cdaac732b2b
diff: fix obscure off-by-one error in diff -p
mercurial/mdiff.py
tests/test-diff-unified
--- 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