Show More
@@ -280,7 +280,11 b' class linelog(object):' | |||||
280 | self._maxrev = 0 |
|
280 | self._maxrev = 0 | |
281 | self._lastannotate = None |
|
281 | self._lastannotate = None | |
282 |
|
282 | |||
283 |
def replacelines(self, rev, a1, a2, b |
|
283 | def replacelines_vec(self, rev, a1, a2, blines): | |
|
284 | return self.replacelines(rev, a1, a2, 0, len(blines), | |||
|
285 | _internal_blines=blines) | |||
|
286 | ||||
|
287 | def replacelines(self, rev, a1, a2, b1, b2, _internal_blines=None): | |||
284 | """Replace lines [a1, a2) with lines [b1, b2).""" |
|
288 | """Replace lines [a1, a2) with lines [b1, b2).""" | |
285 | if self._lastannotate: |
|
289 | if self._lastannotate: | |
286 | # TODO(augie): make replacelines() accept a revision at |
|
290 | # TODO(augie): make replacelines() accept a revision at | |
@@ -315,7 +319,10 b' class linelog(object):' | |||||
315 | # Jump to skip the insert if we're at an older revision. |
|
319 | # Jump to skip the insert if we're at an older revision. | |
316 | appendinst(_jl(rev, tgt)) |
|
320 | appendinst(_jl(rev, tgt)) | |
317 | for linenum in pycompat.xrange(b1, b2): |
|
321 | for linenum in pycompat.xrange(b1, b2): | |
318 |
|
|
322 | if _internal_blines is None: | |
|
323 | appendinst(_line(rev, linenum)) | |||
|
324 | else: | |||
|
325 | appendinst(_line(*_internal_blines[linenum])) | |||
319 | # delete |
|
326 | # delete | |
320 | if a1 < a2: |
|
327 | if a1 < a2: | |
321 | if a2 > len(ar.lines): |
|
328 | if a2 > len(ar.lines): |
@@ -6,6 +6,7 b' import unittest' | |||||
6 |
|
6 | |||
7 | from mercurial import linelog |
|
7 | from mercurial import linelog | |
8 |
|
8 | |||
|
9 | vecratio = 3 # number of replacelines / number of replacelines_vec | |||
9 | maxlinenum = 0xffffff |
|
10 | maxlinenum = 0xffffff | |
10 | maxb1 = 0xffffff |
|
11 | maxb1 = 0xffffff | |
11 | maxdeltaa = 10 |
|
12 | maxdeltaa = 10 | |
@@ -21,9 +22,14 b' def _genedits(seed, endrev):' | |||||
21 | a2 = random.randint(a1, min(n, a1 + maxdeltaa)) |
|
22 | a2 = random.randint(a1, min(n, a1 + maxdeltaa)) | |
22 | b1 = random.randint(0, maxb1) |
|
23 | b1 = random.randint(0, maxb1) | |
23 | b2 = random.randint(b1, b1 + maxdeltab) |
|
24 | b2 = random.randint(b1, b1 + maxdeltab) | |
24 | blines = [(rev, idx) for idx in range(b1, b2)] |
|
25 | usevec = not bool(random.randint(0, vecratio)) | |
|
26 | if usevec: | |||
|
27 | blines = [(random.randint(0, rev), random.randint(0, maxlinenum)) | |||
|
28 | for _ in range(b1, b2)] | |||
|
29 | else: | |||
|
30 | blines = [(rev, bidx) for bidx in range(b1, b2)] | |||
25 | lines[a1:a2] = blines |
|
31 | lines[a1:a2] = blines | |
26 | yield lines, rev, a1, a2, b1, b2 |
|
32 | yield lines, rev, a1, a2, b1, b2, blines, usevec | |
27 |
|
33 | |||
28 | class linelogtests(unittest.TestCase): |
|
34 | class linelogtests(unittest.TestCase): | |
29 | def testlinelogencodedecode(self): |
|
35 | def testlinelogencodedecode(self): | |
@@ -159,12 +165,17 b' class linelogtests(unittest.TestCase):' | |||||
159 | numrevs = 2000 |
|
165 | numrevs = 2000 | |
160 | ll = linelog.linelog() |
|
166 | ll = linelog.linelog() | |
161 | # Populate linelog |
|
167 | # Populate linelog | |
162 |
for lines, rev, a1, a2, b1, b2 in _genedits( |
|
168 | for lines, rev, a1, a2, b1, b2, blines, usevec in _genedits( | |
163 | ll.replacelines(rev, a1, a2, b1, b2) |
|
169 | seed, numrevs): | |
|
170 | if usevec: | |||
|
171 | ll.replacelines_vec(rev, a1, a2, blines) | |||
|
172 | else: | |||
|
173 | ll.replacelines(rev, a1, a2, b1, b2) | |||
164 | ar = ll.annotate(rev) |
|
174 | ar = ll.annotate(rev) | |
165 | self.assertEqual(ll.annotateresult, lines) |
|
175 | self.assertEqual(ll.annotateresult, lines) | |
166 | # Verify we can get back these states by annotating each rev |
|
176 | # Verify we can get back these states by annotating each rev | |
167 |
for lines, rev, a1, a2, b1, b2 in _genedits( |
|
177 | for lines, rev, a1, a2, b1, b2, blines, usevec in _genedits( | |
|
178 | seed, numrevs): | |||
168 | ar = ll.annotate(rev) |
|
179 | ar = ll.annotate(rev) | |
169 | self.assertEqual([(l.rev, l.linenum) for l in ar], lines) |
|
180 | self.assertEqual([(l.rev, l.linenum) for l in ar], lines) | |
170 |
|
181 |
General Comments 0
You need to be logged in to leave comments.
Login now