Mercurial > hg
annotate hg @ 33800:f257943e47ab
repository: formalize peer interface with abstract base class
There are various interfaces for interacting with repositories
and peers. They form a contract for how one should interact with
a repo or peer object.
The contracts today aren't very well-defined or enforced. There
have been several bugs over the years where peers or repo types
have forgotten to implement certain methods. In addition, the
inheritance of some classes is wonky. For example, localrepository
doesn't inherit from an interface and the god-object nature of
that class means the repository interface isn't well-defined. Other
repository types inherit from localrepository then stub out
methods that don't make sense (e.g. statichttprepository
re-defining locking methods to fail fast).
Not having well-defined interfaces makes implementing alternate
storage backends, wire protocol transports, and repository types
difficult because it isn't clear what exactly needs to be
implemented.
This patch starts the process of attempting to establish more
order to the type system around repositories and peers.
Our first patch starts with a problem space that already has a
partial solution: peers. The peer.peerrepository class already
somewhat defines a peer interface. But it is missing a few things
and the total interface isn't well-defined because it is combined
with wireproto.wirepeer.
Our newly-established basepeer class uses the abc module to
declare an abstract base class with the properties and methods that
a generic peer must implement.
We create a new class that inherits from it. This class will hold
our other future abstract base classes / interfaces so we can expose
a unified base class/interface.
We don't yet use the new interface because subsequent additions
will break existing code without some refactoring first.
A new module (repository.py) was created to hold the interfaces.
I could have put things in peer.py. However, I have plans to
eventually add interfaces to define repository and storage types.
These almost certainly require a new module. And I figured having
all the interfaces live in one module makes sense. So I created
repository.py to be that future home.
Differential Revision: https://phab.mercurial-scm.org/D332
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Sun, 13 Aug 2017 10:58:48 -0700 |
parents | b4810bf95c03 |
children | 1900381b6a6e |
rev | line source |
---|---|
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
1 #!/usr/bin/env python |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
2 # |
1698 | 3 # mercurial - scalable distributed SCM |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
4 # |
4635
63b9d2deed48
Updated copyright notices and add "and others" to "hg version"
Thomas Arendsen Hein <thomas@intevation.de>
parents:
3877
diff
changeset
|
5 # Copyright 2005-2007 Matt Mackall <mpm@selenic.com> |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
6 # |
8225
46293a0c7e9f
updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents:
7672
diff
changeset
|
7 # This software may be used and distributed according to the terms of the |
10263 | 8 # GNU General Public License version 2 or any later version. |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
9 |
12661
10da5a1f25dd
setup/hg: always load Mercurial from where it was installed.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
10263
diff
changeset
|
10 import os |
10da5a1f25dd
setup/hg: always load Mercurial from where it was installed.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
10263
diff
changeset
|
11 import sys |
10da5a1f25dd
setup/hg: always load Mercurial from where it was installed.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
10263
diff
changeset
|
12 |
21812
73e4a02e6d23
hg: add support for HGUNICODEPEDANTRY environment variable
Augie Fackler <raf@durin42.com>
parents:
14233
diff
changeset
|
13 if os.environ.get('HGUNICODEPEDANTRY', False): |
29172
2ea9c9aa6e60
hg: limit HGUNICODEPEDANTRY to py2
timeless <timeless@mozdev.org>
parents:
21812
diff
changeset
|
14 try: |
2ea9c9aa6e60
hg: limit HGUNICODEPEDANTRY to py2
timeless <timeless@mozdev.org>
parents:
21812
diff
changeset
|
15 reload(sys) |
2ea9c9aa6e60
hg: limit HGUNICODEPEDANTRY to py2
timeless <timeless@mozdev.org>
parents:
21812
diff
changeset
|
16 sys.setdefaultencoding("undefined") |
2ea9c9aa6e60
hg: limit HGUNICODEPEDANTRY to py2
timeless <timeless@mozdev.org>
parents:
21812
diff
changeset
|
17 except NameError: |
2ea9c9aa6e60
hg: limit HGUNICODEPEDANTRY to py2
timeless <timeless@mozdev.org>
parents:
21812
diff
changeset
|
18 pass |
21812
73e4a02e6d23
hg: add support for HGUNICODEPEDANTRY environment variable
Augie Fackler <raf@durin42.com>
parents:
14233
diff
changeset
|
19 |
12661
10da5a1f25dd
setup/hg: always load Mercurial from where it was installed.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
10263
diff
changeset
|
20 libdir = '@LIBDIR@' |
10da5a1f25dd
setup/hg: always load Mercurial from where it was installed.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
10263
diff
changeset
|
21 |
10da5a1f25dd
setup/hg: always load Mercurial from where it was installed.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
10263
diff
changeset
|
22 if libdir != '@' 'LIBDIR' '@': |
10da5a1f25dd
setup/hg: always load Mercurial from where it was installed.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
10263
diff
changeset
|
23 if not os.path.isabs(libdir): |
12805
cae1c187abd4
setup/hg: handle hg being a symlink when appending relative libdir to sys.path
L. David Baron <dbaron@dbaron.org>
parents:
12661
diff
changeset
|
24 libdir = os.path.join(os.path.dirname(os.path.realpath(__file__)), |
cae1c187abd4
setup/hg: handle hg being a symlink when appending relative libdir to sys.path
L. David Baron <dbaron@dbaron.org>
parents:
12661
diff
changeset
|
25 libdir) |
12661
10da5a1f25dd
setup/hg: always load Mercurial from where it was installed.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
10263
diff
changeset
|
26 libdir = os.path.abspath(libdir) |
10da5a1f25dd
setup/hg: always load Mercurial from where it was installed.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
10263
diff
changeset
|
27 sys.path.insert(0, libdir) |
10da5a1f25dd
setup/hg: always load Mercurial from where it was installed.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
10263
diff
changeset
|
28 |
5197
55860a45bbf2
Enable demandimport only in scripts, not in importable modules (issue605)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5178
diff
changeset
|
29 # enable importing on demand to reduce startup time |
7672
523c7816c33a
Give a useful message about PYTHONPATH if startup fails
Matt Mackall <mpm@selenic.com>
parents:
5531
diff
changeset
|
30 try: |
32424
b4810bf95c03
init: turn on demandimport for Python 3.6 and above
Siddharth Agarwal <sid0@fb.com>
parents:
29235
diff
changeset
|
31 if sys.version_info[0] < 3 or sys.version_info >= (3, 6): |
b4810bf95c03
init: turn on demandimport for Python 3.6 and above
Siddharth Agarwal <sid0@fb.com>
parents:
29235
diff
changeset
|
32 import hgdemandimport; hgdemandimport.enable() |
7672
523c7816c33a
Give a useful message about PYTHONPATH if startup fails
Matt Mackall <mpm@selenic.com>
parents:
5531
diff
changeset
|
33 except ImportError: |
523c7816c33a
Give a useful message about PYTHONPATH if startup fails
Matt Mackall <mpm@selenic.com>
parents:
5531
diff
changeset
|
34 sys.stderr.write("abort: couldn't find mercurial libraries in [%s]\n" % |
523c7816c33a
Give a useful message about PYTHONPATH if startup fails
Matt Mackall <mpm@selenic.com>
parents:
5531
diff
changeset
|
35 ' '.join(sys.path)) |
523c7816c33a
Give a useful message about PYTHONPATH if startup fails
Matt Mackall <mpm@selenic.com>
parents:
5531
diff
changeset
|
36 sys.stderr.write("(check your install and PYTHONPATH)\n") |
523c7816c33a
Give a useful message about PYTHONPATH if startup fails
Matt Mackall <mpm@selenic.com>
parents:
5531
diff
changeset
|
37 sys.exit(-1) |
5197
55860a45bbf2
Enable demandimport only in scripts, not in importable modules (issue605)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5178
diff
changeset
|
38 |
5531
a3fe91b4f6eb
Change standard streams mode to binary at hg startup
Patrick Mezard <pmezard@gmail.com>
parents:
5197
diff
changeset
|
39 import mercurial.util |
5178
18a9fbb5cd78
dispatch: move command dispatching into its own module
Matt Mackall <mpm@selenic.com>
parents:
4635
diff
changeset
|
40 import mercurial.dispatch |
5531
a3fe91b4f6eb
Change standard streams mode to binary at hg startup
Patrick Mezard <pmezard@gmail.com>
parents:
5197
diff
changeset
|
41 |
a3fe91b4f6eb
Change standard streams mode to binary at hg startup
Patrick Mezard <pmezard@gmail.com>
parents:
5197
diff
changeset
|
42 for fp in (sys.stdin, sys.stdout, sys.stderr): |
14233
659f34b833b9
rename util.set_binary to setbinary
Adrian Buehlmann <adrian@cadifra.com>
parents:
12805
diff
changeset
|
43 mercurial.util.setbinary(fp) |
5531
a3fe91b4f6eb
Change standard streams mode to binary at hg startup
Patrick Mezard <pmezard@gmail.com>
parents:
5197
diff
changeset
|
44 |
5178
18a9fbb5cd78
dispatch: move command dispatching into its own module
Matt Mackall <mpm@selenic.com>
parents:
4635
diff
changeset
|
45 mercurial.dispatch.run() |