Mercurial > hg-stable
comparison hgext/absorb.py @ 38959:a5c8c5476339
absorb: use pycompat to get xrange
Differential Revision: https://phab.mercurial-scm.org/D4045
author | Augie Fackler <augie@google.com> |
---|---|
date | Wed, 01 Aug 2018 18:24:43 -0400 |
parents | dc4750b2a04e |
children | e930df0f9a55 |
comparison
equal
deleted
inserted
replaced
38958:dc4750b2a04e | 38959:a5c8c5476339 |
---|---|
41 mdiff, | 41 mdiff, |
42 node, | 42 node, |
43 obsolete, | 43 obsolete, |
44 patch, | 44 patch, |
45 phases, | 45 phases, |
46 pycompat, | |
46 registrar, | 47 registrar, |
47 repair, | 48 repair, |
48 scmutil, | 49 scmutil, |
49 util, | 50 util, |
50 ) | 51 ) |
388 if rev > 1: | 389 if rev > 1: |
389 fixuprev = rev + 1 | 390 fixuprev = rev + 1 |
390 newfixups.append((fixuprev, a1, a2, b1, b2)) | 391 newfixups.append((fixuprev, a1, a2, b1, b2)) |
391 elif a2 - a1 == b2 - b1 or b1 == b2: | 392 elif a2 - a1 == b2 - b1 or b1 == b2: |
392 # 1:1 line mapping, or chunk was deleted | 393 # 1:1 line mapping, or chunk was deleted |
393 for i in xrange(a1, a2): | 394 for i in pycompat.xrange(a1, a2): |
394 rev, linenum = annotated[i] | 395 rev, linenum = annotated[i] |
395 if rev > 1: | 396 if rev > 1: |
396 if b1 == b2: # deletion, simply remove that single line | 397 if b1 == b2: # deletion, simply remove that single line |
397 nb1 = nb2 = 0 | 398 nb1 = nb2 = 0 |
398 else: # 1:1 line mapping, change the corresponding rev | 399 else: # 1:1 line mapping, change the corresponding rev |
415 """calculate the initial linelog based on self.content{,line}s. | 416 """calculate the initial linelog based on self.content{,line}s. |
416 this is similar to running a partial "annotate". | 417 this is similar to running a partial "annotate". |
417 """ | 418 """ |
418 llog = linelog.linelog() | 419 llog = linelog.linelog() |
419 a, alines = '', [] | 420 a, alines = '', [] |
420 for i in xrange(len(self.contents)): | 421 for i in pycompat.xrange(len(self.contents)): |
421 b, blines = self.contents[i], self.contentlines[i] | 422 b, blines = self.contents[i], self.contentlines[i] |
422 llrev = i * 2 + 1 | 423 llrev = i * 2 + 1 |
423 chunks = self._alldiffchunks(a, b, alines, blines) | 424 chunks = self._alldiffchunks(a, b, alines, blines) |
424 for a1, a2, b1, b2 in reversed(list(chunks)): | 425 for a1, a2, b1, b2 in reversed(list(chunks)): |
425 llog.replacelines(llrev, a1, a2, b1, b2) | 426 llog.replacelines(llrev, a1, a2, b1, b2) |
427 return llog | 428 return llog |
428 | 429 |
429 def _checkoutlinelog(self): | 430 def _checkoutlinelog(self): |
430 """() -> [str]. check out file contents from linelog""" | 431 """() -> [str]. check out file contents from linelog""" |
431 contents = [] | 432 contents = [] |
432 for i in xrange(len(self.contents)): | 433 for i in pycompat.xrange(len(self.contents)): |
433 rev = (i + 1) * 2 | 434 rev = (i + 1) * 2 |
434 self.linelog.annotate(rev) | 435 self.linelog.annotate(rev) |
435 content = ''.join(map(self._getline, self.linelog.annotateresult)) | 436 content = ''.join(map(self._getline, self.linelog.annotateresult)) |
436 contents.append(content) | 437 contents.append(content) |
437 return contents | 438 return contents |
552 # this is not optimized for perf but _showchanges only gets executed | 553 # this is not optimized for perf but _showchanges only gets executed |
553 # with an extra command-line flag. | 554 # with an extra command-line flag. |
554 a1, a2, b1, b2 = chunk | 555 a1, a2, b1, b2 = chunk |
555 aidxs, bidxs = [0] * (a2 - a1), [0] * (b2 - b1) | 556 aidxs, bidxs = [0] * (a2 - a1), [0] * (b2 - b1) |
556 for idx, fa1, fa2, fb1, fb2 in fixups: | 557 for idx, fa1, fa2, fb1, fb2 in fixups: |
557 for i in xrange(fa1, fa2): | 558 for i in pycompat.xrange(fa1, fa2): |
558 aidxs[i - a1] = (max(idx, 1) - 1) // 2 | 559 aidxs[i - a1] = (max(idx, 1) - 1) // 2 |
559 for i in xrange(fb1, fb2): | 560 for i in pycompat.xrange(fb1, fb2): |
560 bidxs[i - b1] = (max(idx, 1) - 1) // 2 | 561 bidxs[i - b1] = (max(idx, 1) - 1) // 2 |
561 | 562 |
562 buf = [] # [(idx, content)] | 563 buf = [] # [(idx, content)] |
563 buf.append((0, label('@@ -%d,%d +%d,%d @@' | 564 buf.append((0, label('@@ -%d,%d +%d,%d @@' |
564 % (a1, a2 - a1, b1, b2 - b1), 'diff.hunk'))) | 565 % (a1, a2 - a1, b1, b2 - b1), 'diff.hunk'))) |
565 buf += [(aidxs[i - a1], label('-' + alines[i], 'diff.deleted')) | 566 buf += [(aidxs[i - a1], label('-' + alines[i], 'diff.deleted')) |
566 for i in xrange(a1, a2)] | 567 for i in pycompat.xrange(a1, a2)] |
567 buf += [(bidxs[i - b1], label('+' + blines[i], 'diff.inserted')) | 568 buf += [(bidxs[i - b1], label('+' + blines[i], 'diff.inserted')) |
568 for i in xrange(b1, b2)] | 569 for i in pycompat.xrange(b1, b2)] |
569 for idx, line in buf: | 570 for idx, line in buf: |
570 shortnode = idx and node.short(self.fctxs[idx].node()) or '' | 571 shortnode = idx and node.short(self.fctxs[idx].node()) or '' |
571 ui.write(ui.label(shortnode[0:7].ljust(8), 'absorb.node') + | 572 ui.write(ui.label(shortnode[0:7].ljust(8), 'absorb.node') + |
572 line + '\n') | 573 line + '\n') |
573 | 574 |