comparison mercurial/subrepo.py @ 46114: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 89a2afe31e82
children d6601547f22b a4c19a162615
comparison
equal deleted inserted replaced
46113:d6afa9c149c3 46114:59fa3890d40a
16 import sys 16 import sys
17 import tarfile 17 import tarfile
18 import xml.dom.minidom 18 import xml.dom.minidom
19 19
20 from .i18n import _ 20 from .i18n import _
21 from .node import (
22 bin,
23 hex,
24 nullid,
25 short,
26 )
21 from . import ( 27 from . import (
22 cmdutil, 28 cmdutil,
23 encoding, 29 encoding,
24 error, 30 error,
25 exchange, 31 exchange,
26 logcmdutil, 32 logcmdutil,
27 match as matchmod, 33 match as matchmod,
28 merge as merge, 34 merge as merge,
29 node,
30 pathutil, 35 pathutil,
31 phases, 36 phases,
32 pycompat, 37 pycompat,
33 scmutil, 38 scmutil,
34 subrepoutil, 39 subrepoutil,
59 return path 64 return path
60 65
61 66
62 def _getstorehashcachename(remotepath): 67 def _getstorehashcachename(remotepath):
63 '''get a unique filename for the store hash cache of a remote repository''' 68 '''get a unique filename for the store hash cache of a remote repository'''
64 return node.hex(hashutil.sha1(_expandedabspath(remotepath)).digest())[0:12] 69 return hex(hashutil.sha1(_expandedabspath(remotepath)).digest())[0:12]
65 70
66 71
67 class SubrepoAbort(error.Abort): 72 class SubrepoAbort(error.Abort):
68 """Exception class used to avoid handling a subrepo error more than once""" 73 """Exception class used to avoid handling a subrepo error more than once"""
69 74
506 # sort the files that will be hashed in increasing (likely) file size 511 # sort the files that will be hashed in increasing (likely) file size
507 filelist = (b'bookmarks', b'store/phaseroots', b'store/00changelog.i') 512 filelist = (b'bookmarks', b'store/phaseroots', b'store/00changelog.i')
508 yield b'# %s\n' % _expandedabspath(remotepath) 513 yield b'# %s\n' % _expandedabspath(remotepath)
509 vfs = self._repo.vfs 514 vfs = self._repo.vfs
510 for relname in filelist: 515 for relname in filelist:
511 filehash = node.hex(hashutil.sha1(vfs.tryread(relname)).digest()) 516 filehash = hex(hashutil.sha1(vfs.tryread(relname)).digest())
512 yield b'%s = %s\n' % (relname, filehash) 517 yield b'%s = %s\n' % (relname, filehash)
513 518
514 @propertycache 519 @propertycache
515 def _cachestorehashvfs(self): 520 def _cachestorehashvfs(self):
516 return vfsmod.vfs(self._repo.vfs.join(b'cache/storehash')) 521 return vfsmod.vfs(self._repo.vfs.join(b'cache/storehash'))
599 return scmutil.status([], [], [], [], [], [], []) 604 return scmutil.status([], [], [], [], [], [], [])
600 605
601 @annotatesubrepoerror 606 @annotatesubrepoerror
602 def diff(self, ui, diffopts, node2, match, prefix, **opts): 607 def diff(self, ui, diffopts, node2, match, prefix, **opts):
603 try: 608 try:
604 node1 = node.bin(self._state[1]) 609 node1 = bin(self._state[1])
605 # We currently expect node2 to come from substate and be 610 # We currently expect node2 to come from substate and be
606 # in hex format 611 # in hex format
607 if node2 is not None: 612 if node2 is not None:
608 node2 = node.bin(node2) 613 node2 = bin(node2)
609 logcmdutil.diffordiffstat( 614 logcmdutil.diffordiffstat(
610 ui, 615 ui,
611 self._repo, 616 self._repo,
612 diffopts, 617 diffopts,
613 self._repo[node1], 618 self._repo[node1],
667 return self._repo[b'.'].hex() 672 return self._repo[b'.'].hex()
668 self.ui.debug(b"committing subrepo %s\n" % subrelpath(self)) 673 self.ui.debug(b"committing subrepo %s\n" % subrelpath(self))
669 n = self._repo.commit(text, user, date) 674 n = self._repo.commit(text, user, date)
670 if not n: 675 if not n:
671 return self._repo[b'.'].hex() # different version checked out 676 return self._repo[b'.'].hex() # different version checked out
672 return node.hex(n) 677 return hex(n)
673 678
674 @annotatesubrepoerror 679 @annotatesubrepoerror
675 def phase(self, state): 680 def phase(self, state):
676 return self._repo[state or b'.'].phase() 681 return self._repo[state or b'.'].phase()
677 682
678 @annotatesubrepoerror 683 @annotatesubrepoerror
679 def remove(self): 684 def remove(self):
680 # we can't fully delete the repository as it may contain 685 # we can't fully delete the repository as it may contain
681 # local-only history 686 # local-only history
682 self.ui.note(_(b'removing subrepo %s\n') % subrelpath(self)) 687 self.ui.note(_(b'removing subrepo %s\n') % subrelpath(self))
683 hg.clean(self._repo, node.nullid, False) 688 hg.clean(self._repo, nullid, False)
684 689
685 def _get(self, state): 690 def _get(self, state):
686 source, revision, kind = state 691 source, revision, kind = state
687 parentrepo = self._repo._subparent 692 parentrepo = self._repo._subparent
688 693
1017 if ctx.hidden(): 1022 if ctx.hidden():
1018 # Since hidden revisions aren't pushed/pulled, it seems worth an 1023 # Since hidden revisions aren't pushed/pulled, it seems worth an
1019 # explicit warning. 1024 # explicit warning.
1020 msg = _(b"subrepo '%s' is hidden in revision %s") % ( 1025 msg = _(b"subrepo '%s' is hidden in revision %s") % (
1021 self._relpath, 1026 self._relpath,
1022 node.short(self._ctx.node()), 1027 short(self._ctx.node()),
1023 ) 1028 )
1024 1029
1025 if onpush: 1030 if onpush:
1026 raise error.Abort(msg) 1031 raise error.Abort(msg)
1027 else: 1032 else:
1030 except error.RepoLookupError: 1035 except error.RepoLookupError:
1031 # A missing subrepo revision may be a case of needing to pull it, so 1036 # A missing subrepo revision may be a case of needing to pull it, so
1032 # don't treat this as an error for `hg verify`. 1037 # don't treat this as an error for `hg verify`.
1033 msg = _(b"subrepo '%s' not found in revision %s") % ( 1038 msg = _(b"subrepo '%s' not found in revision %s") % (
1034 self._relpath, 1039 self._relpath,
1035 node.short(self._ctx.node()), 1040 short(self._ctx.node()),
1036 ) 1041 )
1037 1042
1038 if onpush: 1043 if onpush:
1039 raise error.Abort(msg) 1044 raise error.Abort(msg)
1040 else: 1045 else: