Mercurial > public > mercurial-scm > hg-stable
diff mercurial/mdiff.py @ 31808:ca3b4a2b7e54
mdiff: add a hunkinrange helper function
This factors out hunk filtering logic by line range that is similar in
mdiff.blocksinrange() and hgweb.webutil.diffs().
author | Denis Laxalde <denis@laxalde.org> |
---|---|
date | Sat, 01 Apr 2017 12:24:59 +0200 |
parents | 6c80f985a13c |
children | 2d84947cd85d |
line wrap: on
line diff
--- a/mercurial/mdiff.py Fri Apr 22 21:46:33 2016 +0900 +++ b/mercurial/mdiff.py Sat Apr 01 12:24:59 2017 +0200 @@ -117,6 +117,31 @@ s1 = i1 s2 = i2 +def hunkinrange(hunk, linerange): + """Return True if `hunk` defined as (start, length) is in `linerange` + defined as (lowerbound, upperbound). + + >>> hunkinrange((5, 10), (2, 7)) + True + >>> hunkinrange((5, 10), (6, 12)) + True + >>> hunkinrange((5, 10), (13, 17)) + True + >>> hunkinrange((5, 10), (3, 17)) + True + >>> hunkinrange((5, 10), (1, 3)) + False + >>> hunkinrange((5, 10), (18, 20)) + False + >>> hunkinrange((5, 10), (1, 5)) + False + >>> hunkinrange((5, 10), (15, 27)) + False + """ + start, length = hunk + lowerbound, upperbound = linerange + return lowerbound < start + length and start < upperbound + def blocksinrange(blocks, rangeb): """filter `blocks` like (a1, a2, b1, b2) from items outside line range `rangeb` from ``(b1, b2)`` point of view. @@ -150,7 +175,7 @@ uba = a1 + (ubb - b1) else: uba = a2 - if lbb < b2 and b1 < ubb: + if hunkinrange((b1, (b2 - b1)), rangeb): filteredblocks.append(block) if lba is None or uba is None or uba < lba: raise error.Abort(_('line range exceeds file size'))