Details
Details
- Reviewers
indygreg - Group Reviewers
hg-reviewers - Commits
- rHGa5c8c5476339: absorb: use pycompat to get xrange
Diff Detail
Diff Detail
- Repository
- rHG Mercurial
- Lint
Lint Skipped - Unit
Unit Tests Skipped
indygreg |
hg-reviewers |
Lint Skipped |
Unit Tests Skipped |
Path | Packages | |||
---|---|---|---|---|
M | hgext/absorb.py (15 lines) |
Commit | Parents | Author | Summary | Date |
---|---|---|---|---|
Augie Fackler | Aug 1 2018, 6:24 PM |
error, | error, | ||||
extensions, | extensions, | ||||
linelog, | linelog, | ||||
mdiff, | mdiff, | ||||
node, | node, | ||||
obsolete, | obsolete, | ||||
patch, | patch, | ||||
phases, | phases, | ||||
pycompat, | |||||
registrar, | registrar, | ||||
repair, | repair, | ||||
scmutil, | scmutil, | ||||
util, | util, | ||||
) | ) | ||||
from mercurial.utils import ( | from mercurial.utils import ( | ||||
stringutil, | stringutil, | ||||
) | ) | ||||
if len(involvedrevs) == 1 and self._iscontinuous(a1, a2 - 1, True): | if len(involvedrevs) == 1 and self._iscontinuous(a1, a2 - 1, True): | ||||
# chunk belongs to a single revision | # chunk belongs to a single revision | ||||
rev = involvedrevs[0] | rev = involvedrevs[0] | ||||
if rev > 1: | if rev > 1: | ||||
fixuprev = rev + 1 | fixuprev = rev + 1 | ||||
newfixups.append((fixuprev, a1, a2, b1, b2)) | newfixups.append((fixuprev, a1, a2, b1, b2)) | ||||
elif a2 - a1 == b2 - b1 or b1 == b2: | elif a2 - a1 == b2 - b1 or b1 == b2: | ||||
# 1:1 line mapping, or chunk was deleted | # 1:1 line mapping, or chunk was deleted | ||||
for i in xrange(a1, a2): | for i in pycompat.xrange(a1, a2): | ||||
rev, linenum = annotated[i] | rev, linenum = annotated[i] | ||||
if rev > 1: | if rev > 1: | ||||
if b1 == b2: # deletion, simply remove that single line | if b1 == b2: # deletion, simply remove that single line | ||||
nb1 = nb2 = 0 | nb1 = nb2 = 0 | ||||
else: # 1:1 line mapping, change the corresponding rev | else: # 1:1 line mapping, change the corresponding rev | ||||
nb1 = b1 + i - a1 | nb1 = b1 + i - a1 | ||||
nb2 = nb1 + 1 | nb2 = nb1 + 1 | ||||
fixuprev = rev + 1 | fixuprev = rev + 1 | ||||
yield chunk | yield chunk | ||||
def _buildlinelog(self): | def _buildlinelog(self): | ||||
"""calculate the initial linelog based on self.content{,line}s. | """calculate the initial linelog based on self.content{,line}s. | ||||
this is similar to running a partial "annotate". | this is similar to running a partial "annotate". | ||||
""" | """ | ||||
llog = linelog.linelog() | llog = linelog.linelog() | ||||
a, alines = '', [] | a, alines = '', [] | ||||
for i in xrange(len(self.contents)): | for i in pycompat.xrange(len(self.contents)): | ||||
b, blines = self.contents[i], self.contentlines[i] | b, blines = self.contents[i], self.contentlines[i] | ||||
llrev = i * 2 + 1 | llrev = i * 2 + 1 | ||||
chunks = self._alldiffchunks(a, b, alines, blines) | chunks = self._alldiffchunks(a, b, alines, blines) | ||||
for a1, a2, b1, b2 in reversed(list(chunks)): | for a1, a2, b1, b2 in reversed(list(chunks)): | ||||
llog.replacelines(llrev, a1, a2, b1, b2) | llog.replacelines(llrev, a1, a2, b1, b2) | ||||
a, alines = b, blines | a, alines = b, blines | ||||
return llog | return llog | ||||
def _checkoutlinelog(self): | def _checkoutlinelog(self): | ||||
"""() -> [str]. check out file contents from linelog""" | """() -> [str]. check out file contents from linelog""" | ||||
contents = [] | contents = [] | ||||
for i in xrange(len(self.contents)): | for i in pycompat.xrange(len(self.contents)): | ||||
rev = (i + 1) * 2 | rev = (i + 1) * 2 | ||||
self.linelog.annotate(rev) | self.linelog.annotate(rev) | ||||
content = ''.join(map(self._getline, self.linelog.annotateresult)) | content = ''.join(map(self._getline, self.linelog.annotateresult)) | ||||
contents.append(content) | contents.append(content) | ||||
return contents | return contents | ||||
def _checkoutlinelogwithedits(self): | def _checkoutlinelogwithedits(self): | ||||
"""() -> [str]. prompt all lines for edit""" | """() -> [str]. prompt all lines for edit""" | ||||
line = line[:-1] | line = line[:-1] | ||||
return ui.label(line, label) | return ui.label(line, label) | ||||
# this is not optimized for perf but _showchanges only gets executed | # this is not optimized for perf but _showchanges only gets executed | ||||
# with an extra command-line flag. | # with an extra command-line flag. | ||||
a1, a2, b1, b2 = chunk | a1, a2, b1, b2 = chunk | ||||
aidxs, bidxs = [0] * (a2 - a1), [0] * (b2 - b1) | aidxs, bidxs = [0] * (a2 - a1), [0] * (b2 - b1) | ||||
for idx, fa1, fa2, fb1, fb2 in fixups: | for idx, fa1, fa2, fb1, fb2 in fixups: | ||||
for i in xrange(fa1, fa2): | for i in pycompat.xrange(fa1, fa2): | ||||
aidxs[i - a1] = (max(idx, 1) - 1) // 2 | aidxs[i - a1] = (max(idx, 1) - 1) // 2 | ||||
for i in xrange(fb1, fb2): | for i in pycompat.xrange(fb1, fb2): | ||||
bidxs[i - b1] = (max(idx, 1) - 1) // 2 | bidxs[i - b1] = (max(idx, 1) - 1) // 2 | ||||
buf = [] # [(idx, content)] | buf = [] # [(idx, content)] | ||||
buf.append((0, label('@@ -%d,%d +%d,%d @@' | buf.append((0, label('@@ -%d,%d +%d,%d @@' | ||||
% (a1, a2 - a1, b1, b2 - b1), 'diff.hunk'))) | % (a1, a2 - a1, b1, b2 - b1), 'diff.hunk'))) | ||||
buf += [(aidxs[i - a1], label('-' + alines[i], 'diff.deleted')) | buf += [(aidxs[i - a1], label('-' + alines[i], 'diff.deleted')) | ||||
for i in xrange(a1, a2)] | for i in pycompat.xrange(a1, a2)] | ||||
buf += [(bidxs[i - b1], label('+' + blines[i], 'diff.inserted')) | buf += [(bidxs[i - b1], label('+' + blines[i], 'diff.inserted')) | ||||
for i in xrange(b1, b2)] | for i in pycompat.xrange(b1, b2)] | ||||
for idx, line in buf: | for idx, line in buf: | ||||
shortnode = idx and node.short(self.fctxs[idx].node()) or '' | shortnode = idx and node.short(self.fctxs[idx].node()) or '' | ||||
ui.write(ui.label(shortnode[0:7].ljust(8), 'absorb.node') + | ui.write(ui.label(shortnode[0:7].ljust(8), 'absorb.node') + | ||||
line + '\n') | line + '\n') | ||||
class fixupstate(object): | class fixupstate(object): | ||||
"""state needed to run absorb | """state needed to run absorb | ||||