diff --git a/mercurial/mdiff.py b/mercurial/mdiff.py --- a/mercurial/mdiff.py +++ b/mercurial/mdiff.py @@ -160,7 +160,7 @@ def bunidiff(t1, t2, l1, l2, header1, he 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] diff --git a/tests/test-diff-unified b/tests/test-diff-unified --- a/tests/test-diff-unified +++ b/tests/test-diff-unified @@ -44,6 +44,15 @@ hg diff --nodates -U 1 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