##// END OF EJS Templates
mdiff: add a hunkinrange helper function...
Denis Laxalde -
r31808:ca3b4a2b default
parent child Browse files
Show More
@@ -27,6 +27,7 b' from .. import ('
27 27 context,
28 28 error,
29 29 match,
30 mdiff,
30 31 patch,
31 32 pathutil,
32 33 templatefilters,
@@ -473,8 +474,7 b' def diffs(web, tmpl, ctx, basectx, files'
473 474 for hunkrange, hunklines in hunks:
474 475 if linerange is not None and hunkrange is not None:
475 476 s1, l1, s2, l2 = hunkrange
476 lb, ub = linerange
477 if not (lb < s2 + l2 and ub > s2):
477 if not mdiff.hunkinrange((s2, l2), linerange):
478 478 continue
479 479 lines.extend(hunklines)
480 480 if lines:
@@ -117,6 +117,31 b' def splitblock(base1, lines1, base2, lin'
117 117 s1 = i1
118 118 s2 = i2
119 119
120 def hunkinrange(hunk, linerange):
121 """Return True if `hunk` defined as (start, length) is in `linerange`
122 defined as (lowerbound, upperbound).
123
124 >>> hunkinrange((5, 10), (2, 7))
125 True
126 >>> hunkinrange((5, 10), (6, 12))
127 True
128 >>> hunkinrange((5, 10), (13, 17))
129 True
130 >>> hunkinrange((5, 10), (3, 17))
131 True
132 >>> hunkinrange((5, 10), (1, 3))
133 False
134 >>> hunkinrange((5, 10), (18, 20))
135 False
136 >>> hunkinrange((5, 10), (1, 5))
137 False
138 >>> hunkinrange((5, 10), (15, 27))
139 False
140 """
141 start, length = hunk
142 lowerbound, upperbound = linerange
143 return lowerbound < start + length and start < upperbound
144
120 145 def blocksinrange(blocks, rangeb):
121 146 """filter `blocks` like (a1, a2, b1, b2) from items outside line range
122 147 `rangeb` from ``(b1, b2)`` point of view.
@@ -150,7 +175,7 b' def blocksinrange(blocks, rangeb):'
150 175 uba = a1 + (ubb - b1)
151 176 else:
152 177 uba = a2
153 if lbb < b2 and b1 < ubb:
178 if hunkinrange((b1, (b2 - b1)), rangeb):
154 179 filteredblocks.append(block)
155 180 if lba is None or uba is None or uba < lba:
156 181 raise error.Abort(_('line range exceeds file size'))
@@ -32,6 +32,7 b" testmod('mercurial.formatter')"
32 32 testmod('mercurial.hg')
33 33 testmod('mercurial.hgweb.hgwebdir_mod')
34 34 testmod('mercurial.match')
35 testmod('mercurial.mdiff')
35 36 testmod('mercurial.minirst')
36 37 testmod('mercurial.patch')
37 38 testmod('mercurial.pathutil')
General Comments 0
You need to be logged in to leave comments. Login now