comparison hgext/absorb.py @ 49284:d44e3c45f0e4

py3: replace `pycompat.xrange` by `range`
author Manuel Jacob <me@manueljacob.de>
date Sun, 29 May 2022 15:17:27 +0200
parents 3cd57e2be49b
children c166b212bdee
comparison
equal deleted inserted replaced
49283:44b26349127b 49284:d44e3c45f0e4
422 if rev > 1: 422 if rev > 1:
423 fixuprev = rev + 1 423 fixuprev = rev + 1
424 newfixups.append((fixuprev, a1, a2, b1, b2)) 424 newfixups.append((fixuprev, a1, a2, b1, b2))
425 elif a2 - a1 == b2 - b1 or b1 == b2: 425 elif a2 - a1 == b2 - b1 or b1 == b2:
426 # 1:1 line mapping, or chunk was deleted 426 # 1:1 line mapping, or chunk was deleted
427 for i in pycompat.xrange(a1, a2): 427 for i in range(a1, a2):
428 rev, linenum = annotated[i] 428 rev, linenum = annotated[i]
429 if rev > 1: 429 if rev > 1:
430 if b1 == b2: # deletion, simply remove that single line 430 if b1 == b2: # deletion, simply remove that single line
431 nb1 = nb2 = 0 431 nb1 = nb2 = 0
432 else: # 1:1 line mapping, change the corresponding rev 432 else: # 1:1 line mapping, change the corresponding rev
449 """calculate the initial linelog based on self.content{,line}s. 449 """calculate the initial linelog based on self.content{,line}s.
450 this is similar to running a partial "annotate". 450 this is similar to running a partial "annotate".
451 """ 451 """
452 llog = linelog.linelog() 452 llog = linelog.linelog()
453 a, alines = b'', [] 453 a, alines = b'', []
454 for i in pycompat.xrange(len(self.contents)): 454 for i in range(len(self.contents)):
455 b, blines = self.contents[i], self.contentlines[i] 455 b, blines = self.contents[i], self.contentlines[i]
456 llrev = i * 2 + 1 456 llrev = i * 2 + 1
457 chunks = self._alldiffchunks(a, b, alines, blines) 457 chunks = self._alldiffchunks(a, b, alines, blines)
458 for a1, a2, b1, b2 in reversed(list(chunks)): 458 for a1, a2, b1, b2 in reversed(list(chunks)):
459 llog.replacelines(llrev, a1, a2, b1, b2) 459 llog.replacelines(llrev, a1, a2, b1, b2)
461 return llog 461 return llog
462 462
463 def _checkoutlinelog(self): 463 def _checkoutlinelog(self):
464 """() -> [str]. check out file contents from linelog""" 464 """() -> [str]. check out file contents from linelog"""
465 contents = [] 465 contents = []
466 for i in pycompat.xrange(len(self.contents)): 466 for i in range(len(self.contents)):
467 rev = (i + 1) * 2 467 rev = (i + 1) * 2
468 self.linelog.annotate(rev) 468 self.linelog.annotate(rev)
469 content = b''.join(map(self._getline, self.linelog.annotateresult)) 469 content = b''.join(map(self._getline, self.linelog.annotateresult))
470 contents.append(content) 470 contents.append(content)
471 return contents 471 return contents
603 # this is not optimized for perf but _showchanges only gets executed 603 # this is not optimized for perf but _showchanges only gets executed
604 # with an extra command-line flag. 604 # with an extra command-line flag.
605 a1, a2, b1, b2 = chunk 605 a1, a2, b1, b2 = chunk
606 aidxs, bidxs = [0] * (a2 - a1), [0] * (b2 - b1) 606 aidxs, bidxs = [0] * (a2 - a1), [0] * (b2 - b1)
607 for idx, fa1, fa2, fb1, fb2 in fixups: 607 for idx, fa1, fa2, fb1, fb2 in fixups:
608 for i in pycompat.xrange(fa1, fa2): 608 for i in range(fa1, fa2):
609 aidxs[i - a1] = (max(idx, 1) - 1) // 2 609 aidxs[i - a1] = (max(idx, 1) - 1) // 2
610 for i in pycompat.xrange(fb1, fb2): 610 for i in range(fb1, fb2):
611 bidxs[i - b1] = (max(idx, 1) - 1) // 2 611 bidxs[i - b1] = (max(idx, 1) - 1) // 2
612 612
613 fm.startitem() 613 fm.startitem()
614 fm.write( 614 fm.write(
615 b'hunk', 615 b'hunk',
635 line, 635 line,
636 label=linelabel, 636 label=linelabel,
637 ) 637 )
638 fm.data(path=self.path, linetype=linetype) 638 fm.data(path=self.path, linetype=linetype)
639 639
640 for i in pycompat.xrange(a1, a2): 640 for i in range(a1, a2):
641 writeline( 641 writeline(
642 aidxs[i - a1], 642 aidxs[i - a1],
643 b'-', 643 b'-',
644 trim(alines[i]), 644 trim(alines[i]),
645 b'deleted', 645 b'deleted',
646 b'diff.deleted', 646 b'diff.deleted',
647 ) 647 )
648 for i in pycompat.xrange(b1, b2): 648 for i in range(b1, b2):
649 writeline( 649 writeline(
650 bidxs[i - b1], 650 bidxs[i - b1],
651 b'+', 651 b'+',
652 trim(blines[i]), 652 trim(blines[i]),
653 b'inserted', 653 b'inserted',