annotate hgext/schemes.py @ 52293:77b38c86915d

ci: add a small script one can run to purge older pipeline We have over ten thousands old pipeline that take a huge space and that I suspect to be the source of some slowdown in merge request. However it seems that the only way to clear them is manually and through the API, so lets do it. The script was run today.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Tue, 12 Nov 2024 12:45:23 +0100
parents f4733654f144
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9964
e600ad9bc257 schemes extension
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
1 # Copyright 2009, Alexander Solovyov <piranha@piranha.org.ua>
e600ad9bc257 schemes extension
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
2 #
e600ad9bc257 schemes extension
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
3 # This software may be used and distributed according to the terms of the
10263
25e572394f5c Update license to GPLv2+
Matt Mackall <mpm@selenic.com>
parents: 10070
diff changeset
4 # GNU General Public License version 2 or any later version.
9964
e600ad9bc257 schemes extension
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
5
e600ad9bc257 schemes extension
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
6 """extend schemes with shortcuts to repository swarms
e600ad9bc257 schemes extension
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
7
e600ad9bc257 schemes extension
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
8 This extension allows you to specify shortcuts for parent URLs with a
e600ad9bc257 schemes extension
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
9 lot of repositories to act like a scheme, for example::
e600ad9bc257 schemes extension
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
10
e600ad9bc257 schemes extension
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
11 [schemes]
e600ad9bc257 schemes extension
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
12 py = http://code.python.org/hg/
e600ad9bc257 schemes extension
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
13
e600ad9bc257 schemes extension
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
14 After that you can use it like::
e600ad9bc257 schemes extension
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
15
e600ad9bc257 schemes extension
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
16 hg clone py://trunk/
e600ad9bc257 schemes extension
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
17
e600ad9bc257 schemes extension
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
18 Additionally there is support for some more complex schemas, for
e600ad9bc257 schemes extension
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
19 example used by Google Code::
e600ad9bc257 schemes extension
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
20
e600ad9bc257 schemes extension
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
21 [schemes]
e600ad9bc257 schemes extension
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
22 gcode = http://{1}.googlecode.com/hg/
e600ad9bc257 schemes extension
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
23
e600ad9bc257 schemes extension
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
24 The syntax is taken from Mercurial templates, and you have unlimited
e600ad9bc257 schemes extension
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
25 number of variables, starting with ``{1}`` and continuing with
e600ad9bc257 schemes extension
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
26 ``{2}``, ``{3}`` and so on. This variables will receive parts of URL
e600ad9bc257 schemes extension
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
27 supplied, split by ``/``. Anything not specified as ``{part}`` will be
e600ad9bc257 schemes extension
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
28 just appended to an URL.
e600ad9bc257 schemes extension
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
29
e600ad9bc257 schemes extension
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
30 For convenience, the extension adds these schemes by default::
e600ad9bc257 schemes extension
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
31
e600ad9bc257 schemes extension
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
32 [schemes]
e600ad9bc257 schemes extension
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
33 py = http://hg.python.org/
e600ad9bc257 schemes extension
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
34 bb = https://bitbucket.org/
e600ad9bc257 schemes extension
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
35 bb+ssh = ssh://hg@bitbucket.org/
e600ad9bc257 schemes extension
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
36 gcode = https://{1}.googlecode.com/hg/
10777
bdc3256a318e schemes: add Kiln On Demand to default schemes
Benjamin Pollack <benjamin@bitquabit.com>
parents: 10282
diff changeset
37 kiln = https://{1}.kilnhg.com/Repo/
9964
e600ad9bc257 schemes extension
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
38
9965
963ed04a8fde schemes: fixed typos in module docstring
Martin Geisler <mg@lazybytes.net>
parents: 9964
diff changeset
39 You can override a predefined scheme by defining a new scheme with the
963ed04a8fde schemes: fixed typos in module docstring
Martin Geisler <mg@lazybytes.net>
parents: 9964
diff changeset
40 same name.
9964
e600ad9bc257 schemes extension
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
41 """
e600ad9bc257 schemes extension
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
42
51863
f4733654f144 typing: add `from __future__ import annotations` to most files
Matt Harbison <matt_harbison@yahoo.com>
parents: 50791
diff changeset
43 from __future__ import annotations
f4733654f144 typing: add `from __future__ import annotations` to most files
Matt Harbison <matt_harbison@yahoo.com>
parents: 50791
diff changeset
44
28379
27a9032374a7 schemas: use absolute_import
timeless <timeless@mozdev.org>
parents: 27982
diff changeset
45 import os
27a9032374a7 schemas: use absolute_import
timeless <timeless@mozdev.org>
parents: 27982
diff changeset
46 import re
29205
a0939666b836 py3: move up symbol imports to enforce import-checker rules
Yuya Nishihara <yuya@tcha.org>
parents: 28379
diff changeset
47
a0939666b836 py3: move up symbol imports to enforce import-checker rules
Yuya Nishihara <yuya@tcha.org>
parents: 28379
diff changeset
48 from mercurial.i18n import _
28379
27a9032374a7 schemas: use absolute_import
timeless <timeless@mozdev.org>
parents: 27982
diff changeset
49 from mercurial import (
27a9032374a7 schemas: use absolute_import
timeless <timeless@mozdev.org>
parents: 27982
diff changeset
50 error,
27a9032374a7 schemas: use absolute_import
timeless <timeless@mozdev.org>
parents: 27982
diff changeset
51 extensions,
27a9032374a7 schemas: use absolute_import
timeless <timeless@mozdev.org>
parents: 27982
diff changeset
52 hg,
30640
7a3e67bfa417 py3: replace os.name with pycompat.osname (part 2 of 2)
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29841
diff changeset
53 pycompat,
32337
46ba2cdda476 registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents: 31288
diff changeset
54 registrar,
28379
27a9032374a7 schemas: use absolute_import
timeless <timeless@mozdev.org>
parents: 27982
diff changeset
55 templater,
46907
ffd3e823a7e5 urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45942
diff changeset
56 )
ffd3e823a7e5 urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45942
diff changeset
57 from mercurial.utils import (
ffd3e823a7e5 urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45942
diff changeset
58 urlutil,
28379
27a9032374a7 schemas: use absolute_import
timeless <timeless@mozdev.org>
parents: 27982
diff changeset
59 )
9964
e600ad9bc257 schemes extension
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
60
27982
bf1d5c223ac0 schemes: add debugexpandscheme command, resolving a scheme to canonical form
Jason R. Coombs <jaraco@jaraco.com>
parents: 27981
diff changeset
61 cmdtable = {}
32337
46ba2cdda476 registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents: 31288
diff changeset
62 command = registrar.command(cmdtable)
29841
d5883fd055c6 extensions: change magic "shipped with hg" string
Augie Fackler <augie@google.com>
parents: 29205
diff changeset
63 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
25186
80c5b2666a96 extensions: document that `testedwith = 'internal'` is special
Augie Fackler <augie@google.com>
parents: 18910
diff changeset
64 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
80c5b2666a96 extensions: document that `testedwith = 'internal'` is special
Augie Fackler <augie@google.com>
parents: 18910
diff changeset
65 # be specifying the version(s) of Mercurial they are tested with, or
80c5b2666a96 extensions: document that `testedwith = 'internal'` is special
Augie Fackler <augie@google.com>
parents: 18910
diff changeset
66 # leave the attribute unspecified.
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
67 testedwith = b'ships-with-hg-core'
16743
38caf405d010 hgext: mark all first-party extensions as such
Augie Fackler <raf@durin42.com>
parents: 15609
diff changeset
68
44022
c1ccefb513e4 cleanup: drop redundant character escapes outside of `[]`
Matt Harbison <matt_harbison@yahoo.com>
parents: 43077
diff changeset
69 _partre = re.compile(br'{(\d+)\}')
9964
e600ad9bc257 schemes extension
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
70
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39549
diff changeset
71
48946
642e31cb55f0 py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
72 class ShortRepository:
9964
e600ad9bc257 schemes extension
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
73 def __init__(self, url, scheme, templater):
e600ad9bc257 schemes extension
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
74 self.scheme = scheme
e600ad9bc257 schemes extension
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
75 self.templater = templater
e600ad9bc257 schemes extension
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
76 self.url = url
e600ad9bc257 schemes extension
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
77 try:
31181
150cd5125722 schemes: move re construction to module-level and python3-ify
Augie Fackler <raf@durin42.com>
parents: 30640
diff changeset
78 self.parts = max(map(int, _partre.findall(self.url)))
9964
e600ad9bc257 schemes extension
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
79 except ValueError:
e600ad9bc257 schemes extension
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
80 self.parts = 0
e600ad9bc257 schemes extension
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
81
e600ad9bc257 schemes extension
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
82 def __repr__(self):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
83 return b'<ShortRepository: %s>' % self.scheme
9964
e600ad9bc257 schemes extension
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
84
49757
5f71fff8dc74 peer: pass the `path` object to `make_peer`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49750
diff changeset
85 def make_peer(self, ui, path, *args, **kwargs):
5f71fff8dc74 peer: pass the `path` object to `make_peer`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49750
diff changeset
86 new_url = self.resolve(path.rawloc)
5f71fff8dc74 peer: pass the `path` object to `make_peer`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49750
diff changeset
87 path = path.copy(new_raw_location=new_url)
5f71fff8dc74 peer: pass the `path` object to `make_peer`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49750
diff changeset
88 cls = hg.peer_schemes.get(path.url.scheme)
49750
f075a9463ee7 peer: use a dedicated name for the `peer` constructor
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49749
diff changeset
89 if cls is not None:
49757
5f71fff8dc74 peer: pass the `path` object to `make_peer`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49750
diff changeset
90 return cls.make_peer(ui, path, *args, **kwargs)
49750
f075a9463ee7 peer: use a dedicated name for the `peer` constructor
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49749
diff changeset
91 return None
f075a9463ee7 peer: use a dedicated name for the `peer` constructor
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49749
diff changeset
92
39549
089fc0db0954 hg: allow extra arguments to be passed to repo creation (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38354
diff changeset
93 def instance(self, ui, url, create, intents=None, createopts=None):
27981
d630eac3a5db schemes: extract scheme expansion as its own method on ShortRepository
Jason R. Coombs <jaraco@jaraco.com>
parents: 26587
diff changeset
94 url = self.resolve(url)
49749
be3fcd9e5e52 peer: dissolve `_peerlookup` into its last two callers
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49689
diff changeset
95 u = urlutil.url(url)
be3fcd9e5e52 peer: dissolve `_peerlookup` into its last two callers
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49689
diff changeset
96 scheme = u.scheme or b'file'
be3fcd9e5e52 peer: dissolve `_peerlookup` into its last two callers
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49689
diff changeset
97 if scheme in hg.peer_schemes:
be3fcd9e5e52 peer: dissolve `_peerlookup` into its last two callers
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49689
diff changeset
98 cls = hg.peer_schemes[scheme]
be3fcd9e5e52 peer: dissolve `_peerlookup` into its last two callers
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49689
diff changeset
99 elif scheme in hg.repo_schemes:
be3fcd9e5e52 peer: dissolve `_peerlookup` into its last two callers
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49689
diff changeset
100 cls = hg.repo_schemes[scheme]
be3fcd9e5e52 peer: dissolve `_peerlookup` into its last two callers
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49689
diff changeset
101 else:
be3fcd9e5e52 peer: dissolve `_peerlookup` into its last two callers
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49689
diff changeset
102 cls = hg.LocalFactory
be3fcd9e5e52 peer: dissolve `_peerlookup` into its last two callers
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49689
diff changeset
103 return cls.instance(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39549
diff changeset
104 ui, url, create, intents=intents, createopts=createopts
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39549
diff changeset
105 )
27981
d630eac3a5db schemes: extract scheme expansion as its own method on ShortRepository
Jason R. Coombs <jaraco@jaraco.com>
parents: 26587
diff changeset
106
d630eac3a5db schemes: extract scheme expansion as its own method on ShortRepository
Jason R. Coombs <jaraco@jaraco.com>
parents: 26587
diff changeset
107 def resolve(self, url):
46907
ffd3e823a7e5 urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45942
diff changeset
108 # Should this use the urlutil.url class, or is manual parsing better?
18910
b52404a914a9 scheme: don't crash on invalid URLs
Mads Kiilerich <madski@unity3d.com>
parents: 17425
diff changeset
109 try:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
110 url = url.split(b'://', 1)[1]
18910
b52404a914a9 scheme: don't crash on invalid URLs
Mads Kiilerich <madski@unity3d.com>
parents: 17425
diff changeset
111 except IndexError:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
112 raise error.Abort(_(b"no '://' in scheme url '%s'") % url)
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
113 parts = url.split(b'/', self.parts)
9964
e600ad9bc257 schemes extension
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
114 if len(parts) > self.parts:
e600ad9bc257 schemes extension
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
115 tail = parts[-1]
e600ad9bc257 schemes extension
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
116 parts = parts[:-1]
e600ad9bc257 schemes extension
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
117 else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
118 tail = b''
44452
9d2b2df2c2ba cleanup: run pyupgrade on our source tree to clean up varying things
Augie Fackler <augie@google.com>
parents: 44022
diff changeset
119 context = {b'%d' % (i + 1): v for i, v in enumerate(parts)}
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
120 return b''.join(self.templater.process(self.url, context)) + tail
9964
e600ad9bc257 schemes extension
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
121
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39549
diff changeset
122
13827
f1823b9f073b url: nuke some newly-introduced underbars in identifiers
Matt Mackall <mpm@selenic.com>
parents: 13822
diff changeset
123 def hasdriveletter(orig, path):
15609
8f4bad72d8b1 util: fix url.__str__() for windows file URLs
Patrick Mezard <pmezard@gmail.com>
parents: 14606
diff changeset
124 if path:
8f4bad72d8b1 util: fix url.__str__() for windows file URLs
Patrick Mezard <pmezard@gmail.com>
parents: 14606
diff changeset
125 for scheme in schemes:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
126 if path.startswith(scheme + b':'):
15609
8f4bad72d8b1 util: fix url.__str__() for windows file URLs
Patrick Mezard <pmezard@gmail.com>
parents: 14606
diff changeset
127 return False
13822
fbf32a6c903e schemes: prevent one letter schemes from being interpreted as drive letters
Brodie Rao <brodie@bitheap.org>
parents: 10777
diff changeset
128 return orig(path)
fbf32a6c903e schemes: prevent one letter schemes from being interpreted as drive letters
Brodie Rao <brodie@bitheap.org>
parents: 10777
diff changeset
129
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39549
diff changeset
130
9964
e600ad9bc257 schemes extension
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
131 schemes = {
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
132 b'py': b'http://hg.python.org/',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
133 b'bb': b'https://bitbucket.org/',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
134 b'bb+ssh': b'ssh://hg@bitbucket.org/',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
135 b'gcode': b'https://{1}.googlecode.com/hg/',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
136 b'kiln': b'https://{1}.kilnhg.com/Repo/',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39549
diff changeset
137 }
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39549
diff changeset
138
9964
e600ad9bc257 schemes extension
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
139
49850
bcc45b33efb2 schemes: fix a broken check for drive letter conflicts
Matt Harbison <matt_harbison@yahoo.com>
parents: 49757
diff changeset
140 def _check_drive_letter(scheme: bytes) -> None:
49689
1863584f2fba scheme: move the drive letter checking in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49688
diff changeset
141 """check if a scheme conflict with a Windows drive letter"""
1863584f2fba scheme: move the drive letter checking in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49688
diff changeset
142 if (
1863584f2fba scheme: move the drive letter checking in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49688
diff changeset
143 pycompat.iswindows
1863584f2fba scheme: move the drive letter checking in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49688
diff changeset
144 and len(scheme) == 1
1863584f2fba scheme: move the drive letter checking in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49688
diff changeset
145 and scheme.isalpha()
1863584f2fba scheme: move the drive letter checking in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49688
diff changeset
146 and os.path.exists(b'%s:\\' % scheme)
1863584f2fba scheme: move the drive letter checking in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49688
diff changeset
147 ):
1863584f2fba scheme: move the drive letter checking in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49688
diff changeset
148 msg = _(b'custom scheme %s:// conflicts with drive letter %s:\\\n')
1863584f2fba scheme: move the drive letter checking in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49688
diff changeset
149 msg %= (scheme, scheme.upper())
1863584f2fba scheme: move the drive letter checking in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49688
diff changeset
150 raise error.Abort(msg)
1863584f2fba scheme: move the drive letter checking in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49688
diff changeset
151
1863584f2fba scheme: move the drive letter checking in its own function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49688
diff changeset
152
9964
e600ad9bc257 schemes extension
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
153 def extsetup(ui):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
154 schemes.update(dict(ui.configitems(b'schemes')))
38354
e637dc0b3b1f templater: parse template string to tree by templater class
Yuya Nishihara <yuya@tcha.org>
parents: 37717
diff changeset
155 t = templater.engine(templater.parse)
9964
e600ad9bc257 schemes extension
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
156 for scheme, url in schemes.items():
49850
bcc45b33efb2 schemes: fix a broken check for drive letter conflicts
Matt Harbison <matt_harbison@yahoo.com>
parents: 49757
diff changeset
157 _check_drive_letter(scheme)
49688
f73f02ef8cb6 peer-or-repo: split the scheme between repo and peer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48946
diff changeset
158 url_scheme = urlutil.url(url).scheme
f73f02ef8cb6 peer-or-repo: split the scheme between repo and peer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48946
diff changeset
159 if url_scheme in hg.peer_schemes:
f73f02ef8cb6 peer-or-repo: split the scheme between repo and peer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48946
diff changeset
160 hg.peer_schemes[scheme] = ShortRepository(url, scheme, t)
f73f02ef8cb6 peer-or-repo: split the scheme between repo and peer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48946
diff changeset
161 else:
f73f02ef8cb6 peer-or-repo: split the scheme between repo and peer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48946
diff changeset
162 hg.repo_schemes[scheme] = ShortRepository(url, scheme, t)
13822
fbf32a6c903e schemes: prevent one letter schemes from being interpreted as drive letters
Brodie Rao <brodie@bitheap.org>
parents: 10777
diff changeset
163
50791
d51a76b5262b wrapfunction: use sysstr instead of bytes as argument in "schemes"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49850
diff changeset
164 extensions.wrapfunction(urlutil, 'hasdriveletter', hasdriveletter)
27982
bf1d5c223ac0 schemes: add debugexpandscheme command, resolving a scheme to canonical form
Jason R. Coombs <jaraco@jaraco.com>
parents: 27981
diff changeset
165
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39549
diff changeset
166
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
167 @command(b'debugexpandscheme', norepo=True)
27982
bf1d5c223ac0 schemes: add debugexpandscheme command, resolving a scheme to canonical form
Jason R. Coombs <jaraco@jaraco.com>
parents: 27981
diff changeset
168 def expandscheme(ui, url, **opts):
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 44452
diff changeset
169 """given a repo path, provide the scheme-expanded path"""
49688
f73f02ef8cb6 peer-or-repo: split the scheme between repo and peer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48946
diff changeset
170 scheme = urlutil.url(url).scheme
f73f02ef8cb6 peer-or-repo: split the scheme between repo and peer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48946
diff changeset
171 if scheme in hg.peer_schemes:
f73f02ef8cb6 peer-or-repo: split the scheme between repo and peer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48946
diff changeset
172 cls = hg.peer_schemes[scheme]
f73f02ef8cb6 peer-or-repo: split the scheme between repo and peer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48946
diff changeset
173 else:
f73f02ef8cb6 peer-or-repo: split the scheme between repo and peer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48946
diff changeset
174 cls = hg.repo_schemes.get(scheme)
f73f02ef8cb6 peer-or-repo: split the scheme between repo and peer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48946
diff changeset
175 if cls is not None and isinstance(cls, ShortRepository):
f73f02ef8cb6 peer-or-repo: split the scheme between repo and peer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48946
diff changeset
176 url = cls.resolve(url)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
177 ui.write(url + b'\n')