comparison hgext/schemes.py @ 43077:687b865b95ad

formatting: byteify all mercurial/ and hgext/ string literals Done with python3.7 contrib/byteify-strings.py -i $(hg files 'set:mercurial/**.py - mercurial/thirdparty/** + hgext/**.py - hgext/fsmonitor/pywatchman/** - mercurial/__init__.py') black -l 80 -t py33 -S $(hg files 'set:**.py - mercurial/thirdparty/** - "contrib/python-zstandard/**" - hgext/fsmonitor/pywatchman/**') # skip-blame mass-reformatting only Differential Revision: https://phab.mercurial-scm.org/D6972
author Augie Fackler <augie@google.com>
date Sun, 06 Oct 2019 09:48:39 -0400
parents 2372284d9457
children c1ccefb513e4
comparison
equal deleted inserted replaced
43076:2372284d9457 43077:687b865b95ad
59 command = registrar.command(cmdtable) 59 command = registrar.command(cmdtable)
60 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for 60 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
61 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should 61 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
62 # be specifying the version(s) of Mercurial they are tested with, or 62 # be specifying the version(s) of Mercurial they are tested with, or
63 # leave the attribute unspecified. 63 # leave the attribute unspecified.
64 testedwith = 'ships-with-hg-core' 64 testedwith = b'ships-with-hg-core'
65 65
66 _partre = re.compile(br'\{(\d+)\}') 66 _partre = re.compile(br'\{(\d+)\}')
67 67
68 68
69 class ShortRepository(object): 69 class ShortRepository(object):
75 self.parts = max(map(int, _partre.findall(self.url))) 75 self.parts = max(map(int, _partre.findall(self.url)))
76 except ValueError: 76 except ValueError:
77 self.parts = 0 77 self.parts = 0
78 78
79 def __repr__(self): 79 def __repr__(self):
80 return '<ShortRepository: %s>' % self.scheme 80 return b'<ShortRepository: %s>' % self.scheme
81 81
82 def instance(self, ui, url, create, intents=None, createopts=None): 82 def instance(self, ui, url, create, intents=None, createopts=None):
83 url = self.resolve(url) 83 url = self.resolve(url)
84 return hg._peerlookup(url).instance( 84 return hg._peerlookup(url).instance(
85 ui, url, create, intents=intents, createopts=createopts 85 ui, url, create, intents=intents, createopts=createopts
86 ) 86 )
87 87
88 def resolve(self, url): 88 def resolve(self, url):
89 # Should this use the util.url class, or is manual parsing better? 89 # Should this use the util.url class, or is manual parsing better?
90 try: 90 try:
91 url = url.split('://', 1)[1] 91 url = url.split(b'://', 1)[1]
92 except IndexError: 92 except IndexError:
93 raise error.Abort(_("no '://' in scheme url '%s'") % url) 93 raise error.Abort(_(b"no '://' in scheme url '%s'") % url)
94 parts = url.split('/', self.parts) 94 parts = url.split(b'/', self.parts)
95 if len(parts) > self.parts: 95 if len(parts) > self.parts:
96 tail = parts[-1] 96 tail = parts[-1]
97 parts = parts[:-1] 97 parts = parts[:-1]
98 else: 98 else:
99 tail = '' 99 tail = b''
100 context = dict(('%d' % (i + 1), v) for i, v in enumerate(parts)) 100 context = dict((b'%d' % (i + 1), v) for i, v in enumerate(parts))
101 return ''.join(self.templater.process(self.url, context)) + tail 101 return b''.join(self.templater.process(self.url, context)) + tail
102 102
103 103
104 def hasdriveletter(orig, path): 104 def hasdriveletter(orig, path):
105 if path: 105 if path:
106 for scheme in schemes: 106 for scheme in schemes:
107 if path.startswith(scheme + ':'): 107 if path.startswith(scheme + b':'):
108 return False 108 return False
109 return orig(path) 109 return orig(path)
110 110
111 111
112 schemes = { 112 schemes = {
113 'py': 'http://hg.python.org/', 113 b'py': b'http://hg.python.org/',
114 'bb': 'https://bitbucket.org/', 114 b'bb': b'https://bitbucket.org/',
115 'bb+ssh': 'ssh://hg@bitbucket.org/', 115 b'bb+ssh': b'ssh://hg@bitbucket.org/',
116 'gcode': 'https://{1}.googlecode.com/hg/', 116 b'gcode': b'https://{1}.googlecode.com/hg/',
117 'kiln': 'https://{1}.kilnhg.com/Repo/', 117 b'kiln': b'https://{1}.kilnhg.com/Repo/',
118 } 118 }
119 119
120 120
121 def extsetup(ui): 121 def extsetup(ui):
122 schemes.update(dict(ui.configitems('schemes'))) 122 schemes.update(dict(ui.configitems(b'schemes')))
123 t = templater.engine(templater.parse) 123 t = templater.engine(templater.parse)
124 for scheme, url in schemes.items(): 124 for scheme, url in schemes.items():
125 if ( 125 if (
126 pycompat.iswindows 126 pycompat.iswindows
127 and len(scheme) == 1 127 and len(scheme) == 1
128 and scheme.isalpha() 128 and scheme.isalpha()
129 and os.path.exists('%s:\\' % scheme) 129 and os.path.exists(b'%s:\\' % scheme)
130 ): 130 ):
131 raise error.Abort( 131 raise error.Abort(
132 _('custom scheme %s:// conflicts with drive ' 'letter %s:\\\n') 132 _(
133 b'custom scheme %s:// conflicts with drive '
134 b'letter %s:\\\n'
135 )
133 % (scheme, scheme.upper()) 136 % (scheme, scheme.upper())
134 ) 137 )
135 hg.schemes[scheme] = ShortRepository(url, scheme, t) 138 hg.schemes[scheme] = ShortRepository(url, scheme, t)
136 139
137 extensions.wrapfunction(util, 'hasdriveletter', hasdriveletter) 140 extensions.wrapfunction(util, b'hasdriveletter', hasdriveletter)
138 141
139 142
140 @command('debugexpandscheme', norepo=True) 143 @command(b'debugexpandscheme', norepo=True)
141 def expandscheme(ui, url, **opts): 144 def expandscheme(ui, url, **opts):
142 """given a repo path, provide the scheme-expanded path 145 """given a repo path, provide the scheme-expanded path
143 """ 146 """
144 repo = hg._peerlookup(url) 147 repo = hg._peerlookup(url)
145 if isinstance(repo, ShortRepository): 148 if isinstance(repo, ShortRepository):
146 url = repo.resolve(url) 149 url = repo.resolve(url)
147 ui.write(url + '\n') 150 ui.write(url + b'\n')