Mercurial > hg
comparison hgext/fastannotate/context.py @ 46113:59fa3890d40a
node: import symbols explicitly
There is no point in lazy importing mercurial.node, it is used all over
the place anyway. So consistently import the used symbols directly.
Fix one file using symbols indirectly via mercurial.revlog.
Differential Revision: https://phab.mercurial-scm.org/D9480
author | Joerg Sonnenberger <joerg@bec.de> |
---|---|
date | Tue, 01 Dec 2020 21:54:46 +0100 |
parents | 2d49482d0dd4 |
children | 6000f5b25c9b |
comparison
equal
deleted
inserted
replaced
46112:d6afa9c149c3 | 46113:59fa3890d40a |
---|---|
15 from mercurial.pycompat import ( | 15 from mercurial.pycompat import ( |
16 getattr, | 16 getattr, |
17 open, | 17 open, |
18 setattr, | 18 setattr, |
19 ) | 19 ) |
20 from mercurial.node import ( | |
21 bin, | |
22 hex, | |
23 short, | |
24 ) | |
20 from mercurial import ( | 25 from mercurial import ( |
21 error, | 26 error, |
22 linelog as linelogmod, | 27 linelog as linelogmod, |
23 lock as lockmod, | 28 lock as lockmod, |
24 mdiff, | 29 mdiff, |
25 node, | |
26 pycompat, | 30 pycompat, |
27 scmutil, | 31 scmutil, |
28 util, | 32 util, |
29 ) | 33 ) |
30 from mercurial.utils import ( | 34 from mercurial.utils import ( |
148 | 152 |
149 def hashdiffopts(diffopts): | 153 def hashdiffopts(diffopts): |
150 diffoptstr = stringutil.pprint( | 154 diffoptstr = stringutil.pprint( |
151 sorted((k, getattr(diffopts, k)) for k in mdiff.diffopts.defaults) | 155 sorted((k, getattr(diffopts, k)) for k in mdiff.diffopts.defaults) |
152 ) | 156 ) |
153 return node.hex(hashutil.sha1(diffoptstr).digest())[:6] | 157 return hex(hashutil.sha1(diffoptstr).digest())[:6] |
154 | 158 |
155 | 159 |
156 _defaultdiffopthash = hashdiffopts(mdiff.defaultopts) | 160 _defaultdiffopthash = hashdiffopts(mdiff.defaultopts) |
157 | 161 |
158 | 162 |
306 # the fast path test requires commit hash, convert rev number to hash, | 310 # the fast path test requires commit hash, convert rev number to hash, |
307 # so it may hit the fast path. note: in the "fctx" mode, the "annotate" | 311 # so it may hit the fast path. note: in the "fctx" mode, the "annotate" |
308 # command could give us a revision number even if the user passes a | 312 # command could give us a revision number even if the user passes a |
309 # commit hash. | 313 # commit hash. |
310 if isinstance(rev, int): | 314 if isinstance(rev, int): |
311 rev = node.hex(self.repo.changelog.node(rev)) | 315 rev = hex(self.repo.changelog.node(rev)) |
312 | 316 |
313 # fast path: if rev is in the main branch already | 317 # fast path: if rev is in the main branch already |
314 directly, revfctx = self.canannotatedirectly(rev) | 318 directly, revfctx = self.canannotatedirectly(rev) |
315 if directly: | 319 if directly: |
316 if self.ui.debugflag: | 320 if self.ui.debugflag: |
491 from rev. | 495 from rev. |
492 """ | 496 """ |
493 result = True | 497 result = True |
494 f = None | 498 f = None |
495 if not isinstance(rev, int) and rev is not None: | 499 if not isinstance(rev, int) and rev is not None: |
496 hsh = {20: bytes, 40: node.bin}.get(len(rev), lambda x: None)(rev) | 500 hsh = {20: bytes, 40: bin}.get(len(rev), lambda x: None)(rev) |
497 if hsh is not None and (hsh, self.path) in self.revmap: | 501 if hsh is not None and (hsh, self.path) in self.revmap: |
498 f = hsh | 502 f = hsh |
499 if f is None: | 503 if f is None: |
500 adjustctx = b'linkrev' if self._perfhack else True | 504 adjustctx = b'linkrev' if self._perfhack else True |
501 f = self._resolvefctx(rev, adjustctx=adjustctx, resolverev=True) | 505 f = self._resolvefctx(rev, adjustctx=adjustctx, resolverev=True) |
596 hsh = annotateresult[idxs[0]][0] | 600 hsh = annotateresult[idxs[0]][0] |
597 if self.ui.debugflag: | 601 if self.ui.debugflag: |
598 self.ui.debug( | 602 self.ui.debug( |
599 b'fastannotate: reading %s line #%d ' | 603 b'fastannotate: reading %s line #%d ' |
600 b'to resolve lines %r\n' | 604 b'to resolve lines %r\n' |
601 % (node.short(hsh), linenum, idxs) | 605 % (short(hsh), linenum, idxs) |
602 ) | 606 ) |
603 fctx = self._resolvefctx(hsh, revmap.rev2path(rev)) | 607 fctx = self._resolvefctx(hsh, revmap.rev2path(rev)) |
604 lines = mdiff.splitnewlines(fctx.data()) | 608 lines = mdiff.splitnewlines(fctx.data()) |
605 revlines[rev] = lines | 609 revlines[rev] = lines |
606 for idx in idxs: | 610 for idx in idxs: |
608 assert all(x is not None for x in result) | 612 assert all(x is not None for x in result) |
609 return result | 613 return result |
610 | 614 |
611 # run the annotate and the lines should match to the file content | 615 # run the annotate and the lines should match to the file content |
612 self.ui.debug( | 616 self.ui.debug( |
613 b'fastannotate: annotate %s to resolve lines\n' | 617 b'fastannotate: annotate %s to resolve lines\n' % short(hsh) |
614 % node.short(hsh) | |
615 ) | 618 ) |
616 linelog.annotate(rev) | 619 linelog.annotate(rev) |
617 fctx = self._resolvefctx(hsh, revmap.rev2path(rev)) | 620 fctx = self._resolvefctx(hsh, revmap.rev2path(rev)) |
618 annotated = linelog.annotateresult | 621 annotated = linelog.annotateresult |
619 lines = mdiff.splitnewlines(fctx.data()) | 622 lines = mdiff.splitnewlines(fctx.data()) |
638 hsh = f | 641 hsh = f |
639 else: | 642 else: |
640 hsh = f.node() | 643 hsh = f.node() |
641 llrev = self.revmap.hsh2rev(hsh) | 644 llrev = self.revmap.hsh2rev(hsh) |
642 if not llrev: | 645 if not llrev: |
643 raise faerror.CorruptedFileError( | 646 raise faerror.CorruptedFileError(b'%s is not in revmap' % hex(hsh)) |
644 b'%s is not in revmap' % node.hex(hsh) | |
645 ) | |
646 if (self.revmap.rev2flag(llrev) & revmapmod.sidebranchflag) != 0: | 647 if (self.revmap.rev2flag(llrev) & revmapmod.sidebranchflag) != 0: |
647 raise faerror.CorruptedFileError( | 648 raise faerror.CorruptedFileError( |
648 b'%s is not in revmap mainbranch' % node.hex(hsh) | 649 b'%s is not in revmap mainbranch' % hex(hsh) |
649 ) | 650 ) |
650 self.linelog.annotate(llrev) | 651 self.linelog.annotate(llrev) |
651 result = [ | 652 result = [ |
652 (self.revmap.rev2hsh(r), l) for r, l in self.linelog.annotateresult | 653 (self.revmap.rev2hsh(r), l) for r, l in self.linelog.annotateresult |
653 ] | 654 ] |