Mercurial > hg
annotate hgext/sqlitestore.py @ 52032:09a54892b7ee
mergestate: reduce the number of attribute lookups
This code is called a lot during updates, this is a very small but also very
easy thing to do.
author | Raphaël Gomès <rgomes@octobus.net> |
---|---|
date | Wed, 21 Aug 2024 09:48:14 +0200 |
parents | f4733654f144 |
children |
rev | line source |
---|---|
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1 # sqlitestore.py - Storage backend that uses SQLite |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2 # |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3 # Copyright 2018 Gregory Szorc <gregory.szorc@gmail.com> |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
4 # |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
5 # This software may be used and distributed according to the terms of the |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
6 # GNU General Public License version 2 or any later version. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
7 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
8 """store repository data in SQLite (EXPERIMENTAL) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
9 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
10 The sqlitestore extension enables the storage of repository data in SQLite. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
11 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
12 This extension is HIGHLY EXPERIMENTAL. There are NO BACKWARDS COMPATIBILITY |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
13 GUARANTEES. This means that repositories created with this extension may |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
14 only be usable with the exact version of this extension/Mercurial that was |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
15 used. The extension attempts to enforce this in order to prevent repository |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
16 corruption. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
17 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
18 In addition, several features are not yet supported or have known bugs: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
19 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
20 * Only some data is stored in SQLite. Changeset, manifest, and other repository |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
21 data is not yet stored in SQLite. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
22 * Transactions are not robust. If the process is aborted at the right time |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
23 during transaction close/rollback, the repository could be in an inconsistent |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
24 state. This problem will diminish once all repository data is tracked by |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
25 SQLite. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
26 * Bundle repositories do not work (the ability to use e.g. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
27 `hg -R <bundle-file> log` to automatically overlay a bundle on top of the |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
28 existing repository). |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
29 * Various other features don't work. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
30 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
31 This extension should work for basic clone/pull, update, and commit workflows. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
32 Some history rewriting operations may fail due to lack of support for bundle |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
33 repositories. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
34 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
35 To use, activate the extension and set the ``storage.new-repo-backend`` config |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
36 option to ``sqlite`` to enable new repositories to use SQLite for storage. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
37 """ |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
38 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
39 # To run the test suite with repos using SQLite by default, execute the |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
40 # following: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
41 # |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
42 # HGREPOFEATURES="sqlitestore" run-tests.py \ |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
43 # --extra-config-opt extensions.sqlitestore= \ |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
44 # --extra-config-opt storage.new-repo-backend=sqlite |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
45 |
51863
f4733654f144
typing: add `from __future__ import annotations` to most files
Matt Harbison <matt_harbison@yahoo.com>
parents:
51729
diff
changeset
|
46 from __future__ import annotations |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
47 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
48 import sqlite3 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
49 import struct |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
50 import threading |
51729
278af66e6595
typing: induce pytype to use the standard `attr` instead of the vendored copy
Matt Harbison <matt_harbison@yahoo.com>
parents:
51703
diff
changeset
|
51 import typing |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
52 import zlib |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
53 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
54 from mercurial.i18n import _ |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
55 from mercurial.node import ( |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
56 nullrev, |
46780
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46715
diff
changeset
|
57 sha1nodeconstants, |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
58 short, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
59 ) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
60 from mercurial.thirdparty import attr |
51729
278af66e6595
typing: induce pytype to use the standard `attr` instead of the vendored copy
Matt Harbison <matt_harbison@yahoo.com>
parents:
51703
diff
changeset
|
61 |
278af66e6595
typing: induce pytype to use the standard `attr` instead of the vendored copy
Matt Harbison <matt_harbison@yahoo.com>
parents:
51703
diff
changeset
|
62 # Force pytype to use the non-vendored package |
278af66e6595
typing: induce pytype to use the standard `attr` instead of the vendored copy
Matt Harbison <matt_harbison@yahoo.com>
parents:
51703
diff
changeset
|
63 if typing.TYPE_CHECKING: |
278af66e6595
typing: induce pytype to use the standard `attr` instead of the vendored copy
Matt Harbison <matt_harbison@yahoo.com>
parents:
51703
diff
changeset
|
64 # noinspection PyPackageRequirements |
278af66e6595
typing: induce pytype to use the standard `attr` instead of the vendored copy
Matt Harbison <matt_harbison@yahoo.com>
parents:
51703
diff
changeset
|
65 import attr |
278af66e6595
typing: induce pytype to use the standard `attr` instead of the vendored copy
Matt Harbison <matt_harbison@yahoo.com>
parents:
51703
diff
changeset
|
66 |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
67 from mercurial import ( |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
68 ancestor, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
69 dagop, |
40410
3b782669561d
py3: make sure we pass sysstr in sqlite3.connect()
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
40392
diff
changeset
|
70 encoding, |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
71 error, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
72 extensions, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
73 localrepo, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
74 mdiff, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
75 pycompat, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
76 registrar, |
45372
77b8588dd84e
requirements: introduce new requirements related module
Pulkit Goyal <7895pulkit@gmail.com>
parents:
44062
diff
changeset
|
77 requirements, |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
78 util, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
79 verify, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
80 ) |
42813
268662aac075
interfaces: create a new folder for interfaces and move repository.py in it
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42772
diff
changeset
|
81 from mercurial.interfaces import ( |
268662aac075
interfaces: create a new folder for interfaces and move repository.py in it
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42772
diff
changeset
|
82 repository, |
42814
2c4f656c8e9f
interfaceutil: move to interfaces/
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42813
diff
changeset
|
83 util as interfaceutil, |
42813
268662aac075
interfaces: create a new folder for interfaces and move repository.py in it
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42772
diff
changeset
|
84 ) |
44062
2d49482d0dd4
hgext: replace references to hashlib.sha1 with hashutil.sha1
Augie Fackler <augie@google.com>
parents:
43507
diff
changeset
|
85 from mercurial.utils import ( |
2d49482d0dd4
hgext: replace references to hashlib.sha1 with hashutil.sha1
Augie Fackler <augie@google.com>
parents:
43507
diff
changeset
|
86 hashutil, |
2d49482d0dd4
hgext: replace references to hashlib.sha1 with hashutil.sha1
Augie Fackler <augie@google.com>
parents:
43507
diff
changeset
|
87 storageutil, |
2d49482d0dd4
hgext: replace references to hashlib.sha1 with hashutil.sha1
Augie Fackler <augie@google.com>
parents:
43507
diff
changeset
|
88 ) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
89 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
90 try: |
49849
de9ffb82ef4d
typing: suppress a bunch of potential import-error cases in extensions
Matt Harbison <matt_harbison@yahoo.com>
parents:
49845
diff
changeset
|
91 from mercurial import zstd # pytype: disable=import-error |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
92 |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
93 zstd.__version__ |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
94 except ImportError: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
95 zstd = None |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
96 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
97 configtable = {} |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
98 configitem = registrar.configitem(configtable) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
99 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
100 # experimental config: storage.sqlite.compression |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
101 configitem( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
102 b'storage', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
103 b'sqlite.compression', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
104 default=b'zstd' if zstd else b'zlib', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
105 experimental=True, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
106 ) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
107 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
108 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
109 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
110 # be specifying the version(s) of Mercurial they are tested with, or |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
111 # leave the attribute unspecified. |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
112 testedwith = b'ships-with-hg-core' |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
113 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
114 REQUIREMENT = b'exp-sqlite-001' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
115 REQUIREMENT_ZSTD = b'exp-sqlite-comp-001=zstd' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
116 REQUIREMENT_ZLIB = b'exp-sqlite-comp-001=zlib' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
117 REQUIREMENT_NONE = b'exp-sqlite-comp-001=none' |
40390
7e3b6c4f01a2
localrepo: support marking repos as having shallow file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40389
diff
changeset
|
118 REQUIREMENT_SHALLOW_FILES = b'exp-sqlite-shallow-files' |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
119 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
120 CURRENT_SCHEMA_VERSION = 1 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
121 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
122 COMPRESSION_NONE = 1 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
123 COMPRESSION_ZSTD = 2 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
124 COMPRESSION_ZLIB = 3 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
125 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
126 FLAG_CENSORED = 1 |
40392
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
127 FLAG_MISSING_P1 = 2 |
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
128 FLAG_MISSING_P2 = 4 |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
129 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
130 CREATE_SCHEMA = [ |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
131 # Deltas are stored as content-indexed blobs. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
132 # compression column holds COMPRESSION_* constant for how the |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
133 # delta is encoded. |
43507
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
134 'CREATE TABLE delta (' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
135 ' id INTEGER PRIMARY KEY, ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
136 ' compression INTEGER NOT NULL, ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
137 ' hash BLOB UNIQUE ON CONFLICT ABORT, ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
138 ' delta BLOB NOT NULL ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
139 ')', |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
140 # Tracked paths are denormalized to integers to avoid redundant |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
141 # storage of the path name. |
43507
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
142 'CREATE TABLE filepath (' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
143 ' id INTEGER PRIMARY KEY, ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
144 ' path BLOB NOT NULL ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
145 ')', |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
146 'CREATE UNIQUE INDEX filepath_path ON filepath (path)', |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
147 # We have a single table for all file revision data. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
148 # Each file revision is uniquely described by a (path, rev) and |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
149 # (path, node). |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
150 # |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
151 # Revision data is stored as a pointer to the delta producing this |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
152 # revision and the file revision whose delta should be applied before |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
153 # that one. One can reconstruct the delta chain by recursively following |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
154 # the delta base revision pointers until one encounters NULL. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
155 # |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
156 # flags column holds bitwise integer flags controlling storage options. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
157 # These flags are defined by the FLAG_* constants. |
43507
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
158 'CREATE TABLE fileindex (' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
159 ' id INTEGER PRIMARY KEY, ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
160 ' pathid INTEGER REFERENCES filepath(id), ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
161 ' revnum INTEGER NOT NULL, ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
162 ' p1rev INTEGER NOT NULL, ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
163 ' p2rev INTEGER NOT NULL, ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
164 ' linkrev INTEGER NOT NULL, ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
165 ' flags INTEGER NOT NULL, ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
166 ' deltaid INTEGER REFERENCES delta(id), ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
167 ' deltabaseid INTEGER REFERENCES fileindex(id), ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
168 ' node BLOB NOT NULL ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
169 ')', |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
170 'CREATE UNIQUE INDEX fileindex_pathrevnum ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
171 ' ON fileindex (pathid, revnum)', |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
172 'CREATE UNIQUE INDEX fileindex_pathnode ON fileindex (pathid, node)', |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
173 # Provide a view over all file data for convenience. |
43507
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
174 'CREATE VIEW filedata AS ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
175 'SELECT ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
176 ' fileindex.id AS id, ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
177 ' filepath.id AS pathid, ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
178 ' filepath.path AS path, ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
179 ' fileindex.revnum AS revnum, ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
180 ' fileindex.node AS node, ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
181 ' fileindex.p1rev AS p1rev, ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
182 ' fileindex.p2rev AS p2rev, ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
183 ' fileindex.linkrev AS linkrev, ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
184 ' fileindex.flags AS flags, ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
185 ' fileindex.deltaid AS deltaid, ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
186 ' fileindex.deltabaseid AS deltabaseid ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
187 'FROM filepath, fileindex ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
188 'WHERE fileindex.pathid=filepath.id', |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
189 'PRAGMA user_version=%d' % CURRENT_SCHEMA_VERSION, |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
190 ] |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
191 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
192 |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
193 def resolvedeltachain(db, pathid, node, revisioncache, stoprids, zstddctx=None): |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
194 """Resolve a delta chain for a file node.""" |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
195 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
196 # TODO the "not in ({stops})" here is possibly slowing down the query |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
197 # because it needs to perform the lookup on every recursive invocation. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
198 # This could possibly be faster if we created a temporary query with |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
199 # baseid "poisoned" to null and limited the recursive filter to |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
200 # "is not null". |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
201 res = db.execute( |
43507
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
202 'WITH RECURSIVE ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
203 ' deltachain(deltaid, baseid) AS (' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
204 ' SELECT deltaid, deltabaseid FROM fileindex ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
205 ' WHERE pathid=? AND node=? ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
206 ' UNION ALL ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
207 ' SELECT fileindex.deltaid, deltabaseid ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
208 ' FROM fileindex, deltachain ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
209 ' WHERE ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
210 ' fileindex.id=deltachain.baseid ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
211 ' AND deltachain.baseid IS NOT NULL ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
212 ' AND fileindex.id NOT IN ({stops}) ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
213 ' ) ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
214 'SELECT deltachain.baseid, compression, delta ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
215 'FROM deltachain, delta ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
216 'WHERE delta.id=deltachain.deltaid'.format( |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
217 stops=','.join(['?'] * len(stoprids)) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
218 ), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
219 tuple([pathid, node] + list(stoprids.keys())), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
220 ) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
221 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
222 deltas = [] |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
223 lastdeltabaseid = None |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
224 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
225 for deltabaseid, compression, delta in res: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
226 lastdeltabaseid = deltabaseid |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
227 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
228 if compression == COMPRESSION_ZSTD: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
229 delta = zstddctx.decompress(delta) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
230 elif compression == COMPRESSION_NONE: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
231 delta = delta |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
232 elif compression == COMPRESSION_ZLIB: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
233 delta = zlib.decompress(delta) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
234 else: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
235 raise SQLiteStoreError( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
236 b'unhandled compression type: %d' % compression |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
237 ) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
238 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
239 deltas.append(delta) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
240 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
241 if lastdeltabaseid in stoprids: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
242 basetext = revisioncache[stoprids[lastdeltabaseid]] |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
243 else: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
244 basetext = deltas.pop() |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
245 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
246 deltas.reverse() |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
247 fulltext = mdiff.patches(basetext, deltas) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
248 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
249 # SQLite returns buffer instances for blob columns on Python 2. This |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
250 # type can propagate through the delta application layer. Because |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
251 # downstream callers assume revisions are bytes, cast as needed. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
252 if not isinstance(fulltext, bytes): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
253 fulltext = bytes(delta) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
254 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
255 return fulltext |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
256 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
257 |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
258 def insertdelta(db, compression, hash, delta): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
259 try: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
260 return db.execute( |
43507
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
261 'INSERT INTO delta (compression, hash, delta) VALUES (?, ?, ?)', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
262 (compression, hash, delta), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
263 ).lastrowid |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
264 except sqlite3.IntegrityError: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
265 return db.execute( |
43507
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
266 'SELECT id FROM delta WHERE hash=?', (hash,) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
267 ).fetchone()[0] |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
268 |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
269 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
270 class SQLiteStoreError(error.StorageError): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
271 pass |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
272 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
273 |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
274 @attr.s |
48946
642e31cb55f0
py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
275 class revisionentry: |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
276 rid = attr.ib() |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
277 rev = attr.ib() |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
278 node = attr.ib() |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
279 p1rev = attr.ib() |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
280 p2rev = attr.ib() |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
281 p1node = attr.ib() |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
282 p2node = attr.ib() |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
283 linkrev = attr.ib() |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
284 flags = attr.ib() |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
285 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
286 |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
287 @interfaceutil.implementer(repository.irevisiondelta) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
288 @attr.s(slots=True) |
48946
642e31cb55f0
py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
289 class sqliterevisiondelta: |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
290 node = attr.ib() |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
291 p1node = attr.ib() |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
292 p2node = attr.ib() |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
293 basenode = attr.ib() |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
294 flags = attr.ib() |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
295 baserevisionsize = attr.ib() |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
296 revision = attr.ib() |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
297 delta = attr.ib() |
46712
e8c11a2c96c0
delta: add sidedata field to revision delta
Raphaël Gomès <rgomes@octobus.net>
parents:
46711
diff
changeset
|
298 sidedata = attr.ib() |
47077
119790e1c67c
cg4: introduce protocol flag to signify the presence of sidedata
Raphaël Gomès <rgomes@octobus.net>
parents:
47012
diff
changeset
|
299 protocol_flags = attr.ib() |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
300 linknode = attr.ib(default=None) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
301 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
302 |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
303 @interfaceutil.implementer(repository.iverifyproblem) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
304 @attr.s(frozen=True) |
48946
642e31cb55f0
py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
305 class sqliteproblem: |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
306 warning = attr.ib(default=None) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
307 error = attr.ib(default=None) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
308 node = attr.ib(default=None) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
309 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
310 |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
311 @interfaceutil.implementer(repository.ifilestorage) |
48946
642e31cb55f0
py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
312 class sqlitefilestore: |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
313 """Implements storage for an individual tracked path.""" |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
314 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
315 def __init__(self, db, path, compression): |
46780
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46715
diff
changeset
|
316 self.nullid = sha1nodeconstants.nullid |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
317 self._db = db |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
318 self._path = path |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
319 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
320 self._pathid = None |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
321 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
322 # revnum -> node |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
323 self._revtonode = {} |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
324 # node -> revnum |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
325 self._nodetorev = {} |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
326 # node -> data structure |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
327 self._revisions = {} |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
328 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
329 self._revisioncache = util.lrucachedict(10) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
330 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
331 self._compengine = compression |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
332 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
333 if compression == b'zstd': |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
334 self._cctx = zstd.ZstdCompressor(level=3) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
335 self._dctx = zstd.ZstdDecompressor() |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
336 else: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
337 self._cctx = None |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
338 self._dctx = None |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
339 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
340 self._refreshindex() |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
341 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
342 def _refreshindex(self): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
343 self._revtonode = {} |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
344 self._nodetorev = {} |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
345 self._revisions = {} |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
346 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
347 res = list( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
348 self._db.execute( |
43507
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
349 'SELECT id FROM filepath WHERE path=?', (self._path,) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
350 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
351 ) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
352 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
353 if not res: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
354 self._pathid = None |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
355 return |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
356 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
357 self._pathid = res[0][0] |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
358 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
359 res = self._db.execute( |
43507
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
360 'SELECT id, revnum, node, p1rev, p2rev, linkrev, flags ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
361 'FROM fileindex ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
362 'WHERE pathid=? ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
363 'ORDER BY revnum ASC', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
364 (self._pathid,), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
365 ) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
366 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
367 for i, row in enumerate(res): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
368 rid, rev, node, p1rev, p2rev, linkrev, flags = row |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
369 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
370 if i != rev: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
371 raise SQLiteStoreError( |
43117
8ff1ecfadcd1
cleanup: join string literals that are already on one line
Martin von Zweigbergk <martinvonz@google.com>
parents:
43077
diff
changeset
|
372 _(b'sqlite database has inconsistent revision numbers') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
373 ) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
374 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
375 if p1rev == nullrev: |
47012
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46780
diff
changeset
|
376 p1node = sha1nodeconstants.nullid |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
377 else: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
378 p1node = self._revtonode[p1rev] |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
379 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
380 if p2rev == nullrev: |
47012
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46780
diff
changeset
|
381 p2node = sha1nodeconstants.nullid |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
382 else: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
383 p2node = self._revtonode[p2rev] |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
384 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
385 entry = revisionentry( |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
386 rid=rid, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
387 rev=rev, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
388 node=node, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
389 p1rev=p1rev, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
390 p2rev=p2rev, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
391 p1node=p1node, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
392 p2node=p2node, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
393 linkrev=linkrev, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
394 flags=flags, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
395 ) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
396 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
397 self._revtonode[rev] = node |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
398 self._nodetorev[node] = rev |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
399 self._revisions[node] = entry |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
400 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
401 # Start of ifileindex interface. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
402 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
403 def __len__(self): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
404 return len(self._revisions) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
405 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
406 def __iter__(self): |
49284
d44e3c45f0e4
py3: replace `pycompat.xrange` by `range`
Manuel Jacob <me@manueljacob.de>
parents:
48946
diff
changeset
|
407 return iter(range(len(self._revisions))) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
408 |
40387
f1a39128da95
filelog: add a hasnode() method (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40326
diff
changeset
|
409 def hasnode(self, node): |
47012
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46780
diff
changeset
|
410 if node == sha1nodeconstants.nullid: |
40387
f1a39128da95
filelog: add a hasnode() method (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40326
diff
changeset
|
411 return False |
f1a39128da95
filelog: add a hasnode() method (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40326
diff
changeset
|
412 |
f1a39128da95
filelog: add a hasnode() method (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40326
diff
changeset
|
413 return node in self._nodetorev |
f1a39128da95
filelog: add a hasnode() method (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40326
diff
changeset
|
414 |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
415 def revs(self, start=0, stop=None): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
416 return storageutil.iterrevs( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
417 len(self._revisions), start=start, stop=stop |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
418 ) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
419 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
420 def parents(self, node): |
47012
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46780
diff
changeset
|
421 if node == sha1nodeconstants.nullid: |
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46780
diff
changeset
|
422 return sha1nodeconstants.nullid, sha1nodeconstants.nullid |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
423 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
424 if node not in self._revisions: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
425 raise error.LookupError(node, self._path, _(b'no node')) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
426 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
427 entry = self._revisions[node] |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
428 return entry.p1node, entry.p2node |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
429 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
430 def parentrevs(self, rev): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
431 if rev == nullrev: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
432 return nullrev, nullrev |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
433 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
434 if rev not in self._revtonode: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
435 raise IndexError(rev) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
436 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
437 entry = self._revisions[self._revtonode[rev]] |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
438 return entry.p1rev, entry.p2rev |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
439 |
49789
df750b81272f
sqlitestore: add an `ancestors` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49284
diff
changeset
|
440 def ancestors(self, revs, stoprev=0, inclusive=False): |
df750b81272f
sqlitestore: add an `ancestors` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49284
diff
changeset
|
441 """Generate the ancestors of 'revs' in reverse revision order. |
df750b81272f
sqlitestore: add an `ancestors` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49284
diff
changeset
|
442 Does not generate revs lower than stoprev. |
df750b81272f
sqlitestore: add an `ancestors` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49284
diff
changeset
|
443 |
df750b81272f
sqlitestore: add an `ancestors` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49284
diff
changeset
|
444 See the documentation for ancestor.lazyancestors for more details.""" |
df750b81272f
sqlitestore: add an `ancestors` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49284
diff
changeset
|
445 |
df750b81272f
sqlitestore: add an `ancestors` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49284
diff
changeset
|
446 # first, make sure start revisions aren't filtered |
df750b81272f
sqlitestore: add an `ancestors` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49284
diff
changeset
|
447 revs = list(revs) |
df750b81272f
sqlitestore: add an `ancestors` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49284
diff
changeset
|
448 checkrev = self.node |
df750b81272f
sqlitestore: add an `ancestors` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49284
diff
changeset
|
449 for r in revs: |
df750b81272f
sqlitestore: add an `ancestors` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49284
diff
changeset
|
450 checkrev(r) |
df750b81272f
sqlitestore: add an `ancestors` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49284
diff
changeset
|
451 |
df750b81272f
sqlitestore: add an `ancestors` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49284
diff
changeset
|
452 return ancestor.lazyancestors( |
df750b81272f
sqlitestore: add an `ancestors` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49284
diff
changeset
|
453 self.parentrevs, |
df750b81272f
sqlitestore: add an `ancestors` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49284
diff
changeset
|
454 revs, |
df750b81272f
sqlitestore: add an `ancestors` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49284
diff
changeset
|
455 stoprev=stoprev, |
df750b81272f
sqlitestore: add an `ancestors` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49284
diff
changeset
|
456 inclusive=inclusive, |
df750b81272f
sqlitestore: add an `ancestors` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49284
diff
changeset
|
457 ) |
df750b81272f
sqlitestore: add an `ancestors` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49284
diff
changeset
|
458 |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
459 def rev(self, node): |
47012
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46780
diff
changeset
|
460 if node == sha1nodeconstants.nullid: |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
461 return nullrev |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
462 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
463 if node not in self._nodetorev: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
464 raise error.LookupError(node, self._path, _(b'no node')) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
465 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
466 return self._nodetorev[node] |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
467 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
468 def node(self, rev): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
469 if rev == nullrev: |
47012
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46780
diff
changeset
|
470 return sha1nodeconstants.nullid |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
471 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
472 if rev not in self._revtonode: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
473 raise IndexError(rev) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
474 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
475 return self._revtonode[rev] |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
476 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
477 def lookup(self, node): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
478 return storageutil.fileidlookup(self, node, self._path) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
479 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
480 def linkrev(self, rev): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
481 if rev == nullrev: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
482 return nullrev |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
483 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
484 if rev not in self._revtonode: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
485 raise IndexError(rev) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
486 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
487 entry = self._revisions[self._revtonode[rev]] |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
488 return entry.linkrev |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
489 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
490 def iscensored(self, rev): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
491 if rev == nullrev: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
492 return False |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
493 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
494 if rev not in self._revtonode: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
495 raise IndexError(rev) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
496 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
497 return self._revisions[self._revtonode[rev]].flags & FLAG_CENSORED |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
498 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
499 def commonancestorsheads(self, node1, node2): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
500 rev1 = self.rev(node1) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
501 rev2 = self.rev(node2) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
502 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
503 ancestors = ancestor.commonancestorsheads(self.parentrevs, rev1, rev2) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
504 return pycompat.maplist(self.node, ancestors) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
505 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
506 def descendants(self, revs): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
507 # TODO we could implement this using a recursive SQL query, which |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
508 # might be faster. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
509 return dagop.descendantrevs(revs, self.revs, self.parentrevs) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
510 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
511 def heads(self, start=None, stop=None): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
512 if start is None and stop is None: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
513 if not len(self): |
47012
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46780
diff
changeset
|
514 return [sha1nodeconstants.nullid] |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
515 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
516 startrev = self.rev(start) if start is not None else nullrev |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
517 stoprevs = {self.rev(n) for n in stop or []} |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
518 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
519 revs = dagop.headrevssubset( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
520 self.revs, self.parentrevs, startrev=startrev, stoprevs=stoprevs |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
521 ) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
522 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
523 return [self.node(rev) for rev in revs] |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
524 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
525 def children(self, node): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
526 rev = self.rev(node) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
527 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
528 res = self._db.execute( |
43507
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
529 'SELECT' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
530 ' node ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
531 ' FROM filedata ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
532 ' WHERE path=? AND (p1rev=? OR p2rev=?) ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
533 ' ORDER BY revnum ASC', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
534 (self._path, rev, rev), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
535 ) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
536 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
537 return [row[0] for row in res] |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
538 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
539 # End of ifileindex interface. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
540 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
541 # Start of ifiledata interface. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
542 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
543 def size(self, rev): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
544 if rev == nullrev: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
545 return 0 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
546 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
547 if rev not in self._revtonode: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
548 raise IndexError(rev) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
549 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
550 node = self._revtonode[rev] |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
551 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
552 if self.renamed(node): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
553 return len(self.read(node)) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
554 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
555 return len(self.revision(node)) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
556 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
557 def revision(self, node, raw=False, _verifyhash=True): |
47012
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46780
diff
changeset
|
558 if node in (sha1nodeconstants.nullid, nullrev): |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
559 return b'' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
560 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
561 if isinstance(node, int): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
562 node = self.node(node) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
563 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
564 if node not in self._nodetorev: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
565 raise error.LookupError(node, self._path, _(b'no node')) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
566 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
567 if node in self._revisioncache: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
568 return self._revisioncache[node] |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
569 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
570 # Because we have a fulltext revision cache, we are able to |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
571 # short-circuit delta chain traversal and decompression as soon as |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
572 # we encounter a revision in the cache. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
573 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
574 stoprids = {self._revisions[n].rid: n for n in self._revisioncache} |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
575 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
576 if not stoprids: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
577 stoprids[-1] = None |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
578 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
579 fulltext = resolvedeltachain( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
580 self._db, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
581 self._pathid, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
582 node, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
583 self._revisioncache, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
584 stoprids, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
585 zstddctx=self._dctx, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
586 ) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
587 |
40392
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
588 # Don't verify hashes if parent nodes were rewritten, as the hash |
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
589 # wouldn't verify. |
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
590 if self._revisions[node].flags & (FLAG_MISSING_P1 | FLAG_MISSING_P2): |
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
591 _verifyhash = False |
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
592 |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
593 if _verifyhash: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
594 self._checkhash(fulltext, node) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
595 self._revisioncache[node] = fulltext |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
596 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
597 return fulltext |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
598 |
42722
c9f3f4c8999a
rawdata: implement `rawdata` for `sqlitestore` too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
40460
diff
changeset
|
599 def rawdata(self, *args, **kwargs): |
c9f3f4c8999a
rawdata: implement `rawdata` for `sqlitestore` too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
40460
diff
changeset
|
600 return self.revision(*args, **kwargs) |
c9f3f4c8999a
rawdata: implement `rawdata` for `sqlitestore` too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
40460
diff
changeset
|
601 |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
602 def read(self, node): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
603 return storageutil.filtermetadata(self.revision(node)) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
604 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
605 def renamed(self, node): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
606 return storageutil.filerevisioncopied(self, node) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
607 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
608 def cmp(self, node, fulltext): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
609 return not storageutil.filedataequivalent(self, node, fulltext) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
610 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
611 def emitrevisions( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
612 self, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
613 nodes, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
614 nodesorder=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
615 revisiondata=False, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
616 assumehaveparentrevisions=False, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
617 deltamode=repository.CG_DELTAMODE_STD, |
46715
45f0d5297698
changegroupv4: add sidedata helpers
Raphaël Gomès <rgomes@octobus.net>
parents:
46712
diff
changeset
|
618 sidedata_helpers=None, |
49609
9cac281eb9c0
debug: add an option to display statistic about a bundling operation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49284
diff
changeset
|
619 debug_info=None, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
620 ): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
621 if nodesorder not in (b'nodes', b'storage', b'linear', None): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
622 raise error.ProgrammingError( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
623 b'unhandled value for nodesorder: %s' % nodesorder |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
624 ) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
625 |
47012
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46780
diff
changeset
|
626 nodes = [n for n in nodes if n != sha1nodeconstants.nullid] |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
627 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
628 if not nodes: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
629 return |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
630 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
631 # TODO perform in a single query. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
632 res = self._db.execute( |
43507
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
633 'SELECT revnum, deltaid FROM fileindex ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
634 'WHERE pathid=? ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
635 ' AND node in (%s)' % (','.join(['?'] * len(nodes))), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
636 tuple([self._pathid] + nodes), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
637 ) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
638 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
639 deltabases = {} |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
640 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
641 for rev, deltaid in res: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
642 res = self._db.execute( |
43507
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
643 'SELECT revnum from fileindex WHERE pathid=? AND deltaid=?', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
644 (self._pathid, deltaid), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
645 ) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
646 deltabases[rev] = res.fetchone()[0] |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
647 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
648 # TODO define revdifffn so we can use delta from storage. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
649 for delta in storageutil.emitrevisions( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
650 self, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
651 nodes, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
652 nodesorder, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
653 sqliterevisiondelta, |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
654 deltaparentfn=deltabases.__getitem__, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
655 revisiondata=revisiondata, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
656 assumehaveparentrevisions=assumehaveparentrevisions, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
657 deltamode=deltamode, |
46715
45f0d5297698
changegroupv4: add sidedata helpers
Raphaël Gomès <rgomes@octobus.net>
parents:
46712
diff
changeset
|
658 sidedata_helpers=sidedata_helpers, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
659 ): |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
660 yield delta |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
661 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
662 # End of ifiledata interface. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
663 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
664 # Start of ifilemutation interface. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
665 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
666 def add(self, filedata, meta, transaction, linkrev, p1, p2): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
667 if meta or filedata.startswith(b'\x01\n'): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
668 filedata = storageutil.packmeta(meta, filedata) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
669 |
46508
f7b61ad3c64a
revlog: change addrevision to return the new revision, not node
Joerg Sonnenberger <joerg@bec.de>
parents:
45788
diff
changeset
|
670 rev = self.addrevision(filedata, transaction, linkrev, p1, p2) |
f7b61ad3c64a
revlog: change addrevision to return the new revision, not node
Joerg Sonnenberger <joerg@bec.de>
parents:
45788
diff
changeset
|
671 return self.node(rev) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
672 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
673 def addrevision( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
674 self, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
675 revisiondata, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
676 transaction, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
677 linkrev, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
678 p1, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
679 p2, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
680 node=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
681 flags=0, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
682 cachedelta=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
683 ): |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
684 if flags: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
685 raise SQLiteStoreError(_(b'flags not supported on revisions')) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
686 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
687 validatehash = node is not None |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
688 node = node or storageutil.hashrevisionsha1(revisiondata, p1, p2) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
689 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
690 if validatehash: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
691 self._checkhash(revisiondata, node, p1, p2) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
692 |
46508
f7b61ad3c64a
revlog: change addrevision to return the new revision, not node
Joerg Sonnenberger <joerg@bec.de>
parents:
45788
diff
changeset
|
693 rev = self._nodetorev.get(node) |
f7b61ad3c64a
revlog: change addrevision to return the new revision, not node
Joerg Sonnenberger <joerg@bec.de>
parents:
45788
diff
changeset
|
694 if rev is not None: |
f7b61ad3c64a
revlog: change addrevision to return the new revision, not node
Joerg Sonnenberger <joerg@bec.de>
parents:
45788
diff
changeset
|
695 return rev |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
696 |
46508
f7b61ad3c64a
revlog: change addrevision to return the new revision, not node
Joerg Sonnenberger <joerg@bec.de>
parents:
45788
diff
changeset
|
697 rev = self._addrawrevision( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
698 node, revisiondata, transaction, linkrev, p1, p2 |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
699 ) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
700 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
701 self._revisioncache[node] = revisiondata |
46508
f7b61ad3c64a
revlog: change addrevision to return the new revision, not node
Joerg Sonnenberger <joerg@bec.de>
parents:
45788
diff
changeset
|
702 return rev |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
703 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
704 def addgroup( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
705 self, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
706 deltas, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
707 linkmapper, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
708 transaction, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
709 addrevisioncb=None, |
45788
a5206e71c536
revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents:
45372
diff
changeset
|
710 duplicaterevisioncb=None, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
711 maybemissingparents=False, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
712 ): |
45788
a5206e71c536
revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents:
45372
diff
changeset
|
713 empty = True |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
714 |
46711
a41565bef69f
changegroup: add v4 changegroup for revlog v2 exchange
Raphaël Gomès <rgomes@octobus.net>
parents:
46509
diff
changeset
|
715 for ( |
a41565bef69f
changegroup: add v4 changegroup for revlog v2 exchange
Raphaël Gomès <rgomes@octobus.net>
parents:
46509
diff
changeset
|
716 node, |
a41565bef69f
changegroup: add v4 changegroup for revlog v2 exchange
Raphaël Gomès <rgomes@octobus.net>
parents:
46509
diff
changeset
|
717 p1, |
a41565bef69f
changegroup: add v4 changegroup for revlog v2 exchange
Raphaël Gomès <rgomes@octobus.net>
parents:
46509
diff
changeset
|
718 p2, |
a41565bef69f
changegroup: add v4 changegroup for revlog v2 exchange
Raphaël Gomès <rgomes@octobus.net>
parents:
46509
diff
changeset
|
719 linknode, |
a41565bef69f
changegroup: add v4 changegroup for revlog v2 exchange
Raphaël Gomès <rgomes@octobus.net>
parents:
46509
diff
changeset
|
720 deltabase, |
a41565bef69f
changegroup: add v4 changegroup for revlog v2 exchange
Raphaël Gomès <rgomes@octobus.net>
parents:
46509
diff
changeset
|
721 delta, |
a41565bef69f
changegroup: add v4 changegroup for revlog v2 exchange
Raphaël Gomès <rgomes@octobus.net>
parents:
46509
diff
changeset
|
722 wireflags, |
a41565bef69f
changegroup: add v4 changegroup for revlog v2 exchange
Raphaël Gomès <rgomes@octobus.net>
parents:
46509
diff
changeset
|
723 sidedata, |
a41565bef69f
changegroup: add v4 changegroup for revlog v2 exchange
Raphaël Gomès <rgomes@octobus.net>
parents:
46509
diff
changeset
|
724 ) in deltas: |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
725 storeflags = 0 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
726 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
727 if wireflags & repository.REVISION_FLAG_CENSORED: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
728 storeflags |= FLAG_CENSORED |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
729 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
730 if wireflags & ~repository.REVISION_FLAG_CENSORED: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
731 raise SQLiteStoreError(b'unhandled revision flag') |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
732 |
40392
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
733 if maybemissingparents: |
47012
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46780
diff
changeset
|
734 if p1 != sha1nodeconstants.nullid and not self.hasnode(p1): |
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46780
diff
changeset
|
735 p1 = sha1nodeconstants.nullid |
40392
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
736 storeflags |= FLAG_MISSING_P1 |
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
737 |
47012
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46780
diff
changeset
|
738 if p2 != sha1nodeconstants.nullid and not self.hasnode(p2): |
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46780
diff
changeset
|
739 p2 = sha1nodeconstants.nullid |
40392
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
740 storeflags |= FLAG_MISSING_P2 |
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
741 |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
742 baserev = self.rev(deltabase) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
743 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
744 # If base is censored, delta must be full replacement in a single |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
745 # patch operation. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
746 if baserev != nullrev and self.iscensored(baserev): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
747 hlen = struct.calcsize(b'>lll') |
42772
5c2e8a661418
rawdata: update callers in sqlitestore
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42760
diff
changeset
|
748 oldlen = len(self.rawdata(deltabase, _verifyhash=False)) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
749 newlen = len(delta) - hlen |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
750 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
751 if delta[:hlen] != mdiff.replacediffheader(oldlen, newlen): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
752 raise error.CensoredBaseError(self._path, deltabase) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
753 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
754 if not (storeflags & FLAG_CENSORED) and storageutil.deltaiscensored( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
755 delta, baserev, lambda x: len(self.rawdata(x)) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
756 ): |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
757 storeflags |= FLAG_CENSORED |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
758 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
759 linkrev = linkmapper(linknode) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
760 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
761 if node in self._revisions: |
40392
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
762 # Possibly reset parents to make them proper. |
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
763 entry = self._revisions[node] |
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
764 |
47012
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46780
diff
changeset
|
765 if ( |
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46780
diff
changeset
|
766 entry.flags & FLAG_MISSING_P1 |
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46780
diff
changeset
|
767 and p1 != sha1nodeconstants.nullid |
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46780
diff
changeset
|
768 ): |
40392
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
769 entry.p1node = p1 |
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
770 entry.p1rev = self._nodetorev[p1] |
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
771 entry.flags &= ~FLAG_MISSING_P1 |
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
772 |
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
773 self._db.execute( |
43507
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
774 'UPDATE fileindex SET p1rev=?, flags=? WHERE id=?', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
775 (self._nodetorev[p1], entry.flags, entry.rid), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
776 ) |
40392
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
777 |
47012
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46780
diff
changeset
|
778 if ( |
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46780
diff
changeset
|
779 entry.flags & FLAG_MISSING_P2 |
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46780
diff
changeset
|
780 and p2 != sha1nodeconstants.nullid |
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46780
diff
changeset
|
781 ): |
40392
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
782 entry.p2node = p2 |
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
783 entry.p2rev = self._nodetorev[p2] |
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
784 entry.flags &= ~FLAG_MISSING_P2 |
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
785 |
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
786 self._db.execute( |
43507
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
787 'UPDATE fileindex SET p2rev=?, flags=? WHERE id=?', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
788 (self._nodetorev[p1], entry.flags, entry.rid), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
789 ) |
40392
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
790 |
45788
a5206e71c536
revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents:
45372
diff
changeset
|
791 if duplicaterevisioncb: |
46509
7a93b7b3dc2d
revlog: change addgroup callbacks to take revision numbers
Joerg Sonnenberger <joerg@bec.de>
parents:
46508
diff
changeset
|
792 duplicaterevisioncb(self, self.rev(node)) |
45788
a5206e71c536
revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents:
45372
diff
changeset
|
793 empty = False |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
794 continue |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
795 |
47012
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46780
diff
changeset
|
796 if deltabase == sha1nodeconstants.nullid: |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
797 text = mdiff.patch(b'', delta) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
798 storedelta = None |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
799 else: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
800 text = None |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
801 storedelta = (deltabase, delta) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
802 |
46509
7a93b7b3dc2d
revlog: change addgroup callbacks to take revision numbers
Joerg Sonnenberger <joerg@bec.de>
parents:
46508
diff
changeset
|
803 rev = self._addrawrevision( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
804 node, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
805 text, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
806 transaction, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
807 linkrev, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
808 p1, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
809 p2, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
810 storedelta=storedelta, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
811 flags=storeflags, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
812 ) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
813 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
814 if addrevisioncb: |
46509
7a93b7b3dc2d
revlog: change addgroup callbacks to take revision numbers
Joerg Sonnenberger <joerg@bec.de>
parents:
46508
diff
changeset
|
815 addrevisioncb(self, rev) |
45788
a5206e71c536
revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents:
45372
diff
changeset
|
816 empty = False |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
817 |
45788
a5206e71c536
revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents:
45372
diff
changeset
|
818 return not empty |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
819 |
51270
ceeb8fa23cc8
censor: accept multiple revision in a single call
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50797
diff
changeset
|
820 def censorrevision(self, tr, censor_nodes, tombstone=b''): |
ceeb8fa23cc8
censor: accept multiple revision in a single call
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50797
diff
changeset
|
821 for node in censor_nodes: |
ceeb8fa23cc8
censor: accept multiple revision in a single call
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50797
diff
changeset
|
822 self._censor_one_revision(tr, node, tombstone=tombstone) |
ceeb8fa23cc8
censor: accept multiple revision in a single call
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50797
diff
changeset
|
823 |
ceeb8fa23cc8
censor: accept multiple revision in a single call
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50797
diff
changeset
|
824 def _censor_one_revision(self, tr, censornode, tombstone): |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
825 tombstone = storageutil.packmeta({b'censored': tombstone}, b'') |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
826 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
827 # This restriction is cargo culted from revlogs and makes no sense for |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
828 # SQLite, since columns can be resized at will. |
42772
5c2e8a661418
rawdata: update callers in sqlitestore
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42760
diff
changeset
|
829 if len(tombstone) > len(self.rawdata(censornode)): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
830 raise error.Abort( |
43117
8ff1ecfadcd1
cleanup: join string literals that are already on one line
Martin von Zweigbergk <martinvonz@google.com>
parents:
43077
diff
changeset
|
831 _(b'censor tombstone must be no longer than censored data') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
832 ) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
833 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
834 # We need to replace the censored revision's data with the tombstone. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
835 # But replacing that data will have implications for delta chains that |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
836 # reference it. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
837 # |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
838 # While "better," more complex strategies are possible, we do something |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
839 # simple: we find delta chain children of the censored revision and we |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
840 # replace those incremental deltas with fulltexts of their corresponding |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
841 # revision. Then we delete the now-unreferenced delta and original |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
842 # revision and insert a replacement. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
843 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
844 # Find the delta to be censored. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
845 censoreddeltaid = self._db.execute( |
43507
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
846 'SELECT deltaid FROM fileindex WHERE id=?', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
847 (self._revisions[censornode].rid,), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
848 ).fetchone()[0] |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
849 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
850 # Find all its delta chain children. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
851 # TODO once we support storing deltas for !files, we'll need to look |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
852 # for those delta chains too. |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
853 rows = list( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
854 self._db.execute( |
43507
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
855 'SELECT id, pathid, node FROM fileindex ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
856 'WHERE deltabaseid=? OR deltaid=?', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
857 (censoreddeltaid, censoreddeltaid), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
858 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
859 ) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
860 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
861 for row in rows: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
862 rid, pathid, node = row |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
863 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
864 fulltext = resolvedeltachain( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
865 self._db, pathid, node, {}, {-1: None}, zstddctx=self._dctx |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
866 ) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
867 |
44062
2d49482d0dd4
hgext: replace references to hashlib.sha1 with hashutil.sha1
Augie Fackler <augie@google.com>
parents:
43507
diff
changeset
|
868 deltahash = hashutil.sha1(fulltext).digest() |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
869 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
870 if self._compengine == b'zstd': |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
871 deltablob = self._cctx.compress(fulltext) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
872 compression = COMPRESSION_ZSTD |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
873 elif self._compengine == b'zlib': |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
874 deltablob = zlib.compress(fulltext) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
875 compression = COMPRESSION_ZLIB |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
876 elif self._compengine == b'none': |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
877 deltablob = fulltext |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
878 compression = COMPRESSION_NONE |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
879 else: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
880 raise error.ProgrammingError( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
881 b'unhandled compression engine: %s' % self._compengine |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
882 ) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
883 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
884 if len(deltablob) >= len(fulltext): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
885 deltablob = fulltext |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
886 compression = COMPRESSION_NONE |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
887 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
888 deltaid = insertdelta(self._db, compression, deltahash, deltablob) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
889 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
890 self._db.execute( |
43507
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
891 'UPDATE fileindex SET deltaid=?, deltabaseid=NULL ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
892 'WHERE id=?', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
893 (deltaid, rid), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
894 ) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
895 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
896 # Now create the tombstone delta and replace the delta on the censored |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
897 # node. |
44062
2d49482d0dd4
hgext: replace references to hashlib.sha1 with hashutil.sha1
Augie Fackler <augie@google.com>
parents:
43507
diff
changeset
|
898 deltahash = hashutil.sha1(tombstone).digest() |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
899 tombstonedeltaid = insertdelta( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
900 self._db, COMPRESSION_NONE, deltahash, tombstone |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
901 ) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
902 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
903 flags = self._revisions[censornode].flags |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
904 flags |= FLAG_CENSORED |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
905 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
906 self._db.execute( |
43507
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
907 'UPDATE fileindex SET flags=?, deltaid=?, deltabaseid=NULL ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
908 'WHERE pathid=? AND node=?', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
909 (flags, tombstonedeltaid, self._pathid, censornode), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
910 ) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
911 |
43507
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
912 self._db.execute('DELETE FROM delta WHERE id=?', (censoreddeltaid,)) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
913 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
914 self._refreshindex() |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
915 self._revisioncache.clear() |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
916 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
917 def getstrippoint(self, minlink): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
918 return storageutil.resolvestripinfo( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
919 minlink, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
920 len(self) - 1, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
921 [self.rev(n) for n in self.heads()], |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
922 self.linkrev, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
923 self.parentrevs, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
924 ) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
925 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
926 def strip(self, minlink, transaction): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
927 if not len(self): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
928 return |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
929 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
930 rev, _ignored = self.getstrippoint(minlink) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
931 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
932 if rev == len(self): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
933 return |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
934 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
935 for rev in self.revs(rev): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
936 self._db.execute( |
43507
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
937 'DELETE FROM fileindex WHERE pathid=? AND node=?', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
938 (self._pathid, self.node(rev)), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
939 ) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
940 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
941 # TODO how should we garbage collect data in delta table? |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
942 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
943 self._refreshindex() |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
944 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
945 # End of ifilemutation interface. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
946 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
947 # Start of ifilestorage interface. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
948 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
949 def files(self): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
950 return [] |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
951 |
46712
e8c11a2c96c0
delta: add sidedata field to revision delta
Raphaël Gomès <rgomes@octobus.net>
parents:
46711
diff
changeset
|
952 def sidedata(self, nodeorrev, _df=None): |
e8c11a2c96c0
delta: add sidedata field to revision delta
Raphaël Gomès <rgomes@octobus.net>
parents:
46711
diff
changeset
|
953 # Not supported for now |
e8c11a2c96c0
delta: add sidedata field to revision delta
Raphaël Gomès <rgomes@octobus.net>
parents:
46711
diff
changeset
|
954 return {} |
e8c11a2c96c0
delta: add sidedata field to revision delta
Raphaël Gomès <rgomes@octobus.net>
parents:
46711
diff
changeset
|
955 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
956 def storageinfo( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
957 self, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
958 exclusivefiles=False, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
959 sharedfiles=False, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
960 revisionscount=False, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
961 trackedsize=False, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
962 storedsize=False, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
963 ): |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
964 d = {} |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
965 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
966 if exclusivefiles: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
967 d[b'exclusivefiles'] = [] |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
968 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
969 if sharedfiles: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
970 # TODO list sqlite file(s) here. |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
971 d[b'sharedfiles'] = [] |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
972 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
973 if revisionscount: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
974 d[b'revisionscount'] = len(self) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
975 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
976 if trackedsize: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
977 d[b'trackedsize'] = sum( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
978 len(self.revision(node)) for node in self._nodetorev |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
979 ) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
980 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
981 if storedsize: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
982 # TODO implement this? |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
983 d[b'storedsize'] = None |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
984 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
985 return d |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
986 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
987 def verifyintegrity(self, state): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
988 state[b'skipread'] = set() |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
989 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
990 for rev in self: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
991 node = self.node(rev) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
992 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
993 try: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
994 self.revision(node) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
995 except Exception as e: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
996 yield sqliteproblem( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
997 error=_(b'unpacking %s: %s') % (short(node), e), node=node |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
998 ) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
999 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1000 state[b'skipread'].add(node) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1001 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1002 # End of ifilestorage interface. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1003 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1004 def _checkhash(self, fulltext, node, p1=None, p2=None): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1005 if p1 is None and p2 is None: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1006 p1, p2 = self.parents(node) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1007 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1008 if node == storageutil.hashrevisionsha1(fulltext, p1, p2): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1009 return |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1010 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1011 try: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1012 del self._revisioncache[node] |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1013 except KeyError: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1014 pass |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1015 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1016 if storageutil.iscensoredtext(fulltext): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1017 raise error.CensoredNodeError(self._path, node, fulltext) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1018 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1019 raise SQLiteStoreError(_(b'integrity check failed on %s') % self._path) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1020 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1021 def _addrawrevision( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1022 self, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1023 node, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1024 revisiondata, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1025 transaction, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1026 linkrev, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1027 p1, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1028 p2, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1029 storedelta=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1030 flags=0, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1031 ): |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1032 if self._pathid is None: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1033 res = self._db.execute( |
43507
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
1034 'INSERT INTO filepath (path) VALUES (?)', (self._path,) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1035 ) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1036 self._pathid = res.lastrowid |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1037 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1038 # For simplicity, always store a delta against p1. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1039 # TODO we need a lot more logic here to make behavior reasonable. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1040 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1041 if storedelta: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1042 deltabase, delta = storedelta |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1043 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1044 if isinstance(deltabase, int): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1045 deltabase = self.node(deltabase) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1046 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1047 else: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1048 assert revisiondata is not None |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1049 deltabase = p1 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1050 |
47012
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46780
diff
changeset
|
1051 if deltabase == sha1nodeconstants.nullid: |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1052 delta = revisiondata |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1053 else: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1054 delta = mdiff.textdiff( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1055 self.revision(self.rev(deltabase)), revisiondata |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1056 ) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1057 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1058 # File index stores a pointer to its delta and the parent delta. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1059 # The parent delta is stored via a pointer to the fileindex PK. |
47012
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46780
diff
changeset
|
1060 if deltabase == sha1nodeconstants.nullid: |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1061 baseid = None |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1062 else: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1063 baseid = self._revisions[deltabase].rid |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1064 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1065 # Deltas are stored with a hash of their content. This allows |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1066 # us to de-duplicate. The table is configured to ignore conflicts |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1067 # and it is faster to just insert and silently noop than to look |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1068 # first. |
44062
2d49482d0dd4
hgext: replace references to hashlib.sha1 with hashutil.sha1
Augie Fackler <augie@google.com>
parents:
43507
diff
changeset
|
1069 deltahash = hashutil.sha1(delta).digest() |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1070 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1071 if self._compengine == b'zstd': |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1072 deltablob = self._cctx.compress(delta) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1073 compression = COMPRESSION_ZSTD |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1074 elif self._compengine == b'zlib': |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1075 deltablob = zlib.compress(delta) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1076 compression = COMPRESSION_ZLIB |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1077 elif self._compengine == b'none': |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1078 deltablob = delta |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1079 compression = COMPRESSION_NONE |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1080 else: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1081 raise error.ProgrammingError( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1082 b'unhandled compression engine: %s' % self._compengine |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1083 ) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1084 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1085 # Don't store compressed data if it isn't practical. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1086 if len(deltablob) >= len(delta): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1087 deltablob = delta |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1088 compression = COMPRESSION_NONE |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1089 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1090 deltaid = insertdelta(self._db, compression, deltahash, deltablob) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1091 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1092 rev = len(self) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1093 |
47012
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46780
diff
changeset
|
1094 if p1 == sha1nodeconstants.nullid: |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1095 p1rev = nullrev |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1096 else: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1097 p1rev = self._nodetorev[p1] |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1098 |
47012
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46780
diff
changeset
|
1099 if p2 == sha1nodeconstants.nullid: |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1100 p2rev = nullrev |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1101 else: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1102 p2rev = self._nodetorev[p2] |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1103 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1104 rid = self._db.execute( |
43507
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
1105 'INSERT INTO fileindex (' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
1106 ' pathid, revnum, node, p1rev, p2rev, linkrev, flags, ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
1107 ' deltaid, deltabaseid) ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
1108 ' VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1109 ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1110 self._pathid, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1111 rev, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1112 node, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1113 p1rev, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1114 p2rev, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1115 linkrev, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1116 flags, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1117 deltaid, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1118 baseid, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1119 ), |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1120 ).lastrowid |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1121 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1122 entry = revisionentry( |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1123 rid=rid, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1124 rev=rev, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1125 node=node, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1126 p1rev=p1rev, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1127 p2rev=p2rev, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1128 p1node=p1, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1129 p2node=p2, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1130 linkrev=linkrev, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1131 flags=flags, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1132 ) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1133 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1134 self._nodetorev[node] = rev |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1135 self._revtonode[rev] = node |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1136 self._revisions[node] = entry |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1137 |
46508
f7b61ad3c64a
revlog: change addrevision to return the new revision, not node
Joerg Sonnenberger <joerg@bec.de>
parents:
45788
diff
changeset
|
1138 return rev |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1139 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1140 |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1141 class sqliterepository(localrepo.localrepository): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1142 def cancopy(self): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1143 return False |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1144 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1145 def transaction(self, *args, **kwargs): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1146 current = self.currenttransaction() |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1147 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1148 tr = super(sqliterepository, self).transaction(*args, **kwargs) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1149 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1150 if current: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1151 return tr |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1152 |
43507
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
1153 self._dbconn.execute('BEGIN TRANSACTION') |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1154 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1155 def committransaction(_): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1156 self._dbconn.commit() |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1157 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1158 tr.addfinalize(b'sqlitestore', committransaction) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1159 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1160 return tr |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1161 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1162 @property |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1163 def _dbconn(self): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1164 # SQLite connections can only be used on the thread that created |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1165 # them. In most cases, this "just works." However, hgweb uses |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1166 # multiple threads. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1167 tid = threading.current_thread().ident |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1168 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1169 if self._db: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1170 if self._db[0] == tid: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1171 return self._db[1] |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1172 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1173 db = makedb(self.svfs.join(b'db.sqlite')) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1174 self._db = (tid, db) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1175 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1176 return db |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1177 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1178 |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1179 def makedb(path): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1180 """Construct a database handle for a database at path.""" |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1181 |
40410
3b782669561d
py3: make sure we pass sysstr in sqlite3.connect()
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
40392
diff
changeset
|
1182 db = sqlite3.connect(encoding.strfromlocal(path)) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1183 db.text_factory = bytes |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1184 |
43507
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
1185 res = db.execute('PRAGMA user_version').fetchone()[0] |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1186 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1187 # New database. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1188 if res == 0: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1189 for statement in CREATE_SCHEMA: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1190 db.execute(statement) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1191 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1192 db.commit() |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1193 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1194 elif res == CURRENT_SCHEMA_VERSION: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1195 pass |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1196 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1197 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1198 raise error.Abort(_(b'sqlite database has unrecognized version')) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1199 |
43507
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
1200 db.execute('PRAGMA journal_mode=WAL') |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1201 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1202 return db |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1203 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1204 |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1205 def featuresetup(ui, supported): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1206 supported.add(REQUIREMENT) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1207 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1208 if zstd: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1209 supported.add(REQUIREMENT_ZSTD) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1210 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1211 supported.add(REQUIREMENT_ZLIB) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1212 supported.add(REQUIREMENT_NONE) |
40390
7e3b6c4f01a2
localrepo: support marking repos as having shallow file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40389
diff
changeset
|
1213 supported.add(REQUIREMENT_SHALLOW_FILES) |
45372
77b8588dd84e
requirements: introduce new requirements related module
Pulkit Goyal <7895pulkit@gmail.com>
parents:
44062
diff
changeset
|
1214 supported.add(requirements.NARROW_REQUIREMENT) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1215 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1216 |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1217 def newreporequirements(orig, ui, createopts): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1218 if createopts[b'backend'] != b'sqlite': |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1219 return orig(ui, createopts) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1220 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1221 # This restriction can be lifted once we have more confidence. |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1222 if b'sharedrepo' in createopts: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1223 raise error.Abort( |
43117
8ff1ecfadcd1
cleanup: join string literals that are already on one line
Martin von Zweigbergk <martinvonz@google.com>
parents:
43077
diff
changeset
|
1224 _(b'shared repositories not supported with SQLite store') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1225 ) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1226 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1227 # This filtering is out of an abundance of caution: we want to ensure |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1228 # we honor creation options and we do that by annotating exactly the |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1229 # creation options we recognize. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1230 known = { |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1231 b'narrowfiles', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1232 b'backend', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1233 b'shallowfilestore', |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1234 } |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1235 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1236 unsupported = set(createopts) - known |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1237 if unsupported: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1238 raise error.Abort( |
43117
8ff1ecfadcd1
cleanup: join string literals that are already on one line
Martin von Zweigbergk <martinvonz@google.com>
parents:
43077
diff
changeset
|
1239 _(b'SQLite store does not support repo creation option: %s') |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1240 % b', '.join(sorted(unsupported)) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1241 ) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1242 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1243 # Since we're a hybrid store that still relies on revlogs, we fall back |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1244 # to using the revlogv1 backend's storage requirements then adding our |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1245 # own requirement. |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1246 createopts[b'backend'] = b'revlogv1' |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1247 requirements = orig(ui, createopts) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1248 requirements.add(REQUIREMENT) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1249 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1250 compression = ui.config(b'storage', b'sqlite.compression') |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1251 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1252 if compression == b'zstd' and not zstd: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1253 raise error.Abort( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1254 _( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1255 b'storage.sqlite.compression set to "zstd" but ' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1256 b'zstandard compression not available to this ' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1257 b'Mercurial install' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1258 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1259 ) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1260 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1261 if compression == b'zstd': |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1262 requirements.add(REQUIREMENT_ZSTD) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1263 elif compression == b'zlib': |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1264 requirements.add(REQUIREMENT_ZLIB) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1265 elif compression == b'none': |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1266 requirements.add(REQUIREMENT_NONE) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1267 else: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1268 raise error.Abort( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1269 _( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1270 b'unknown compression engine defined in ' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1271 b'storage.sqlite.compression: %s' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1272 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1273 % compression |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1274 ) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1275 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1276 if createopts.get(b'shallowfilestore'): |
40390
7e3b6c4f01a2
localrepo: support marking repos as having shallow file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40389
diff
changeset
|
1277 requirements.add(REQUIREMENT_SHALLOW_FILES) |
7e3b6c4f01a2
localrepo: support marking repos as having shallow file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40389
diff
changeset
|
1278 |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1279 return requirements |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1280 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1281 |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1282 @interfaceutil.implementer(repository.ilocalrepositoryfilestorage) |
48946
642e31cb55f0
py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
1283 class sqlitefilestorage: |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1284 """Repository file storage backed by SQLite.""" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1285 |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1286 def file(self, path): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1287 if path[0] == b'/': |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1288 path = path[1:] |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1289 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1290 if REQUIREMENT_ZSTD in self.requirements: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1291 compression = b'zstd' |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1292 elif REQUIREMENT_ZLIB in self.requirements: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1293 compression = b'zlib' |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1294 elif REQUIREMENT_NONE in self.requirements: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1295 compression = b'none' |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1296 else: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1297 raise error.Abort( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1298 _( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1299 b'unable to determine what compression engine ' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1300 b'to use for SQLite storage' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1301 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1302 ) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1303 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1304 return sqlitefilestore(self._dbconn, path, compression) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1305 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1306 |
40390
7e3b6c4f01a2
localrepo: support marking repos as having shallow file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40389
diff
changeset
|
1307 def makefilestorage(orig, requirements, features, **kwargs): |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1308 """Produce a type conforming to ``ilocalrepositoryfilestorage``.""" |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1309 if REQUIREMENT in requirements: |
40390
7e3b6c4f01a2
localrepo: support marking repos as having shallow file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40389
diff
changeset
|
1310 if REQUIREMENT_SHALLOW_FILES in requirements: |
7e3b6c4f01a2
localrepo: support marking repos as having shallow file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40389
diff
changeset
|
1311 features.add(repository.REPO_FEATURE_SHALLOW_FILE_STORAGE) |
7e3b6c4f01a2
localrepo: support marking repos as having shallow file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40389
diff
changeset
|
1312 |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1313 return sqlitefilestorage |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1314 else: |
40390
7e3b6c4f01a2
localrepo: support marking repos as having shallow file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40389
diff
changeset
|
1315 return orig(requirements=requirements, features=features, **kwargs) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1316 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1317 |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1318 def makemain(orig, ui, requirements, **kwargs): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1319 if REQUIREMENT in requirements: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1320 if REQUIREMENT_ZSTD in requirements and not zstd: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1321 raise error.Abort( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1322 _( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1323 b'repository uses zstandard compression, which ' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1324 b'is not available to this Mercurial install' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1325 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1326 ) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1327 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1328 return sqliterepository |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1329 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1330 return orig(requirements=requirements, **kwargs) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1331 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1332 |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1333 def verifierinit(orig, self, *args, **kwargs): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1334 orig(self, *args, **kwargs) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1335 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1336 # We don't care that files in the store don't align with what is |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1337 # advertised. So suppress these warnings. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1338 self.warnorphanstorefiles = False |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1339 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1340 |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1341 def extsetup(ui): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1342 localrepo.featuresetupfuncs.add(featuresetup) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1343 extensions.wrapfunction( |
50797
4c6151b69085
wrapfunction: use sysstr instead of bytes as argument in "sqlitestore"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50793
diff
changeset
|
1344 localrepo, 'newreporequirements', newreporequirements |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1345 ) |
50793
1fbae268ecae
wrapfunction: use sysstr instead of bytes as argument in "sqlitestore"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49849
diff
changeset
|
1346 extensions.wrapfunction(localrepo, 'makefilestorage', makefilestorage) |
1fbae268ecae
wrapfunction: use sysstr instead of bytes as argument in "sqlitestore"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49849
diff
changeset
|
1347 extensions.wrapfunction(localrepo, 'makemain', makemain) |
1fbae268ecae
wrapfunction: use sysstr instead of bytes as argument in "sqlitestore"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49849
diff
changeset
|
1348 extensions.wrapfunction(verify.verifier, '__init__', verifierinit) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1349 |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1350 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1351 def reposetup(ui, repo): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1352 if isinstance(repo, sqliterepository): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1353 repo._db = None |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1354 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1355 # TODO check for bundlerepository? |