Mercurial > hg
annotate hgext/sqlitestore.py @ 46296:eec8899407f4
shelve: also create class representing whole directory of shelves
It's a little annoying to have to create and pass in a vfs into
`listshelves()`. This patch attempts to start addressing that by
creating a class that represents a directory containing shelves (the
directory can be either `.hg/shelved/` or `.hg/shelve-backup/`).
Differential Revision: https://phab.mercurial-scm.org/D9743
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Tue, 12 Jan 2021 09:02:47 -0800 |
parents | a5206e71c536 |
children | f7b61ad3c64a |
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 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
46 from __future__ import absolute_import |
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 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
51 import zlib |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
52 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
53 from mercurial.i18n import _ |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
54 from mercurial.node import ( |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
55 nullid, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
56 nullrev, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
57 short, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
58 ) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
59 from mercurial.thirdparty import attr |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
60 from mercurial import ( |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
61 ancestor, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
62 dagop, |
40410
3b782669561d
py3: make sure we pass sysstr in sqlite3.connect()
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
40392
diff
changeset
|
63 encoding, |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
64 error, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
65 extensions, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
66 localrepo, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
67 mdiff, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
68 pycompat, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
69 registrar, |
45372
77b8588dd84e
requirements: introduce new requirements related module
Pulkit Goyal <7895pulkit@gmail.com>
parents:
44062
diff
changeset
|
70 requirements, |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
71 util, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
72 verify, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
73 ) |
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
|
74 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
|
75 repository, |
42814
2c4f656c8e9f
interfaceutil: move to interfaces/
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
42813
diff
changeset
|
76 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
|
77 ) |
44062
2d49482d0dd4
hgext: replace references to hashlib.sha1 with hashutil.sha1
Augie Fackler <augie@google.com>
parents:
43507
diff
changeset
|
78 from mercurial.utils import ( |
2d49482d0dd4
hgext: replace references to hashlib.sha1 with hashutil.sha1
Augie Fackler <augie@google.com>
parents:
43507
diff
changeset
|
79 hashutil, |
2d49482d0dd4
hgext: replace references to hashlib.sha1 with hashutil.sha1
Augie Fackler <augie@google.com>
parents:
43507
diff
changeset
|
80 storageutil, |
2d49482d0dd4
hgext: replace references to hashlib.sha1 with hashutil.sha1
Augie Fackler <augie@google.com>
parents:
43507
diff
changeset
|
81 ) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
82 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
83 try: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
84 from mercurial import zstd |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
85 |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
86 zstd.__version__ |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
87 except ImportError: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
88 zstd = None |
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 configtable = {} |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
91 configitem = registrar.configitem(configtable) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
92 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
93 # experimental config: storage.sqlite.compression |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
94 configitem( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
95 b'storage', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
96 b'sqlite.compression', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
97 default=b'zstd' if zstd else b'zlib', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
98 experimental=True, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
99 ) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
100 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
101 # 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
|
102 # 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
|
103 # 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
|
104 # leave the attribute unspecified. |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
105 testedwith = b'ships-with-hg-core' |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
106 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
107 REQUIREMENT = b'exp-sqlite-001' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
108 REQUIREMENT_ZSTD = b'exp-sqlite-comp-001=zstd' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
109 REQUIREMENT_ZLIB = b'exp-sqlite-comp-001=zlib' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
110 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
|
111 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
|
112 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
113 CURRENT_SCHEMA_VERSION = 1 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
114 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
115 COMPRESSION_NONE = 1 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
116 COMPRESSION_ZSTD = 2 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
117 COMPRESSION_ZLIB = 3 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
118 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
119 FLAG_CENSORED = 1 |
40392
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
120 FLAG_MISSING_P1 = 2 |
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
121 FLAG_MISSING_P2 = 4 |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
122 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
123 CREATE_SCHEMA = [ |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
124 # Deltas are stored as content-indexed blobs. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
125 # compression column holds COMPRESSION_* constant for how the |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
126 # delta is encoded. |
43507
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
127 'CREATE TABLE delta (' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
128 ' id INTEGER PRIMARY KEY, ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
129 ' compression INTEGER NOT NULL, ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
130 ' hash BLOB UNIQUE ON CONFLICT ABORT, ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
131 ' delta BLOB NOT NULL ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
132 ')', |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
133 # 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
|
134 # storage of the path name. |
43507
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
135 'CREATE TABLE filepath (' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
136 ' id INTEGER PRIMARY KEY, ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
137 ' path BLOB NOT NULL ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
138 ')', |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
139 '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
|
140 # 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
|
141 # 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
|
142 # (path, node). |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
143 # |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
144 # 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
|
145 # 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
|
146 # 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
|
147 # 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
|
148 # |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
149 # 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
|
150 # 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
|
151 'CREATE TABLE fileindex (' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
152 ' id INTEGER PRIMARY KEY, ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
153 ' pathid INTEGER REFERENCES filepath(id), ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
154 ' revnum INTEGER NOT NULL, ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
155 ' p1rev INTEGER NOT NULL, ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
156 ' p2rev INTEGER NOT NULL, ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
157 ' linkrev INTEGER NOT NULL, ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
158 ' flags INTEGER NOT NULL, ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
159 ' deltaid INTEGER REFERENCES delta(id), ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
160 ' deltabaseid INTEGER REFERENCES fileindex(id), ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
161 ' node BLOB NOT NULL ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
162 ')', |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
163 'CREATE UNIQUE INDEX fileindex_pathrevnum ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
164 ' ON fileindex (pathid, revnum)', |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
165 '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
|
166 # 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
|
167 'CREATE VIEW filedata AS ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
168 'SELECT ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
169 ' fileindex.id AS id, ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
170 ' filepath.id AS pathid, ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
171 ' filepath.path AS path, ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
172 ' fileindex.revnum AS revnum, ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
173 ' fileindex.node AS node, ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
174 ' fileindex.p1rev AS p1rev, ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
175 ' fileindex.p2rev AS p2rev, ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
176 ' fileindex.linkrev AS linkrev, ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
177 ' fileindex.flags AS flags, ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
178 ' fileindex.deltaid AS deltaid, ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
179 ' fileindex.deltabaseid AS deltabaseid ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
180 'FROM filepath, fileindex ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
181 'WHERE fileindex.pathid=filepath.id', |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
182 'PRAGMA user_version=%d' % CURRENT_SCHEMA_VERSION, |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
183 ] |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
184 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
185 |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
186 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
|
187 """Resolve a delta chain for a file node.""" |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
188 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
189 # 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
|
190 # 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
|
191 # 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
|
192 # 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
|
193 # "is not null". |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
194 res = db.execute( |
43507
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
195 'WITH RECURSIVE ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
196 ' deltachain(deltaid, baseid) AS (' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
197 ' SELECT deltaid, deltabaseid FROM fileindex ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
198 ' WHERE pathid=? AND node=? ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
199 ' UNION ALL ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
200 ' SELECT fileindex.deltaid, deltabaseid ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
201 ' FROM fileindex, deltachain ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
202 ' WHERE ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
203 ' fileindex.id=deltachain.baseid ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
204 ' AND deltachain.baseid IS NOT NULL ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
205 ' AND fileindex.id NOT IN ({stops}) ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
206 ' ) ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
207 'SELECT deltachain.baseid, compression, delta ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
208 'FROM deltachain, delta ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
209 'WHERE delta.id=deltachain.deltaid'.format( |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
210 stops=','.join(['?'] * len(stoprids)) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
211 ), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
212 tuple([pathid, node] + list(stoprids.keys())), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
213 ) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
214 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
215 deltas = [] |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
216 lastdeltabaseid = None |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
217 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
218 for deltabaseid, compression, delta in res: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
219 lastdeltabaseid = deltabaseid |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
220 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
221 if compression == COMPRESSION_ZSTD: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
222 delta = zstddctx.decompress(delta) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
223 elif compression == COMPRESSION_NONE: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
224 delta = delta |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
225 elif compression == COMPRESSION_ZLIB: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
226 delta = zlib.decompress(delta) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
227 else: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
228 raise SQLiteStoreError( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
229 b'unhandled compression type: %d' % compression |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
230 ) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
231 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
232 deltas.append(delta) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
233 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
234 if lastdeltabaseid in stoprids: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
235 basetext = revisioncache[stoprids[lastdeltabaseid]] |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
236 else: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
237 basetext = deltas.pop() |
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.reverse() |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
240 fulltext = mdiff.patches(basetext, deltas) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
241 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
242 # 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
|
243 # 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
|
244 # 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
|
245 if not isinstance(fulltext, bytes): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
246 fulltext = bytes(delta) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
247 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
248 return fulltext |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
249 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
250 |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
251 def insertdelta(db, compression, hash, delta): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
252 try: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
253 return db.execute( |
43507
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
254 'INSERT INTO delta (compression, hash, delta) VALUES (?, ?, ?)', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
255 (compression, hash, delta), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
256 ).lastrowid |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
257 except sqlite3.IntegrityError: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
258 return db.execute( |
43507
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
259 'SELECT id FROM delta WHERE hash=?', (hash,) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
260 ).fetchone()[0] |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
261 |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
262 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
263 class SQLiteStoreError(error.StorageError): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
264 pass |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
265 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
266 |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
267 @attr.s |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
268 class revisionentry(object): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
269 rid = attr.ib() |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
270 rev = attr.ib() |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
271 node = attr.ib() |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
272 p1rev = attr.ib() |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
273 p2rev = attr.ib() |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
274 p1node = attr.ib() |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
275 p2node = attr.ib() |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
276 linkrev = attr.ib() |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
277 flags = attr.ib() |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
278 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
279 |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
280 @interfaceutil.implementer(repository.irevisiondelta) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
281 @attr.s(slots=True) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
282 class sqliterevisiondelta(object): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
283 node = attr.ib() |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
284 p1node = attr.ib() |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
285 p2node = attr.ib() |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
286 basenode = attr.ib() |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
287 flags = attr.ib() |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
288 baserevisionsize = attr.ib() |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
289 revision = attr.ib() |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
290 delta = attr.ib() |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
291 linknode = attr.ib(default=None) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
292 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
293 |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
294 @interfaceutil.implementer(repository.iverifyproblem) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
295 @attr.s(frozen=True) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
296 class sqliteproblem(object): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
297 warning = attr.ib(default=None) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
298 error = attr.ib(default=None) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
299 node = attr.ib(default=None) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
300 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
301 |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
302 @interfaceutil.implementer(repository.ifilestorage) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
303 class sqlitefilestore(object): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
304 """Implements storage for an individual tracked path.""" |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
305 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
306 def __init__(self, db, path, compression): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
307 self._db = db |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
308 self._path = path |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
309 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
310 self._pathid = None |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
311 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
312 # revnum -> node |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
313 self._revtonode = {} |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
314 # node -> revnum |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
315 self._nodetorev = {} |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
316 # node -> data structure |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
317 self._revisions = {} |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
318 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
319 self._revisioncache = util.lrucachedict(10) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
320 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
321 self._compengine = compression |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
322 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
323 if compression == b'zstd': |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
324 self._cctx = zstd.ZstdCompressor(level=3) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
325 self._dctx = zstd.ZstdDecompressor() |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
326 else: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
327 self._cctx = None |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
328 self._dctx = None |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
329 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
330 self._refreshindex() |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
331 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
332 def _refreshindex(self): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
333 self._revtonode = {} |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
334 self._nodetorev = {} |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
335 self._revisions = {} |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
336 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
337 res = list( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
338 self._db.execute( |
43507
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
339 'SELECT id FROM filepath WHERE path=?', (self._path,) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
340 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
341 ) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
342 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
343 if not res: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
344 self._pathid = None |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
345 return |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
346 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
347 self._pathid = res[0][0] |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
348 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
349 res = self._db.execute( |
43507
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
350 '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
|
351 'FROM fileindex ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
352 'WHERE pathid=? ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
353 'ORDER BY revnum ASC', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
354 (self._pathid,), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
355 ) |
40326
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 for i, row in enumerate(res): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
358 rid, rev, node, p1rev, p2rev, linkrev, flags = row |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
359 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
360 if i != rev: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
361 raise SQLiteStoreError( |
43117
8ff1ecfadcd1
cleanup: join string literals that are already on one line
Martin von Zweigbergk <martinvonz@google.com>
parents:
43077
diff
changeset
|
362 _(b'sqlite database has inconsistent revision numbers') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
363 ) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
364 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
365 if p1rev == nullrev: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
366 p1node = nullid |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
367 else: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
368 p1node = self._revtonode[p1rev] |
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 p2rev == nullrev: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
371 p2node = nullid |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
372 else: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
373 p2node = self._revtonode[p2rev] |
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 entry = revisionentry( |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
376 rid=rid, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
377 rev=rev, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
378 node=node, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
379 p1rev=p1rev, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
380 p2rev=p2rev, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
381 p1node=p1node, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
382 p2node=p2node, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
383 linkrev=linkrev, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
384 flags=flags, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
385 ) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
386 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
387 self._revtonode[rev] = node |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
388 self._nodetorev[node] = rev |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
389 self._revisions[node] = entry |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
390 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
391 # Start of ifileindex interface. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
392 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
393 def __len__(self): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
394 return len(self._revisions) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
395 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
396 def __iter__(self): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
397 return iter(pycompat.xrange(len(self._revisions))) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
398 |
40387
f1a39128da95
filelog: add a hasnode() method (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40326
diff
changeset
|
399 def hasnode(self, node): |
f1a39128da95
filelog: add a hasnode() method (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40326
diff
changeset
|
400 if node == nullid: |
f1a39128da95
filelog: add a hasnode() method (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40326
diff
changeset
|
401 return False |
f1a39128da95
filelog: add a hasnode() method (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40326
diff
changeset
|
402 |
f1a39128da95
filelog: add a hasnode() method (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40326
diff
changeset
|
403 return node in self._nodetorev |
f1a39128da95
filelog: add a hasnode() method (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40326
diff
changeset
|
404 |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
405 def revs(self, start=0, stop=None): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
406 return storageutil.iterrevs( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
407 len(self._revisions), start=start, stop=stop |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
408 ) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
409 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
410 def parents(self, node): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
411 if node == nullid: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
412 return nullid, nullid |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
413 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
414 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
|
415 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
|
416 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
417 entry = self._revisions[node] |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
418 return entry.p1node, entry.p2node |
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 parentrevs(self, rev): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
421 if rev == nullrev: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
422 return nullrev, nullrev |
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 rev not in self._revtonode: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
425 raise IndexError(rev) |
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[self._revtonode[rev]] |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
428 return entry.p1rev, entry.p2rev |
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 rev(self, node): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
431 if node == nullid: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
432 return 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 node not in self._nodetorev: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
435 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
|
436 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
437 return self._nodetorev[node] |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
438 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
439 def node(self, rev): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
440 if rev == nullrev: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
441 return nullid |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
442 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
443 if rev not in self._revtonode: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
444 raise IndexError(rev) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
445 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
446 return self._revtonode[rev] |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
447 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
448 def lookup(self, node): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
449 return storageutil.fileidlookup(self, node, self._path) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
450 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
451 def linkrev(self, rev): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
452 if rev == nullrev: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
453 return nullrev |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
454 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
455 if rev not in self._revtonode: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
456 raise IndexError(rev) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
457 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
458 entry = self._revisions[self._revtonode[rev]] |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
459 return entry.linkrev |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
460 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
461 def iscensored(self, rev): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
462 if rev == nullrev: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
463 return False |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
464 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
465 if rev not in self._revtonode: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
466 raise IndexError(rev) |
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 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
|
469 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
470 def commonancestorsheads(self, node1, node2): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
471 rev1 = self.rev(node1) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
472 rev2 = self.rev(node2) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
473 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
474 ancestors = ancestor.commonancestorsheads(self.parentrevs, rev1, rev2) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
475 return pycompat.maplist(self.node, ancestors) |
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 descendants(self, revs): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
478 # 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
|
479 # might be faster. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
480 return dagop.descendantrevs(revs, self.revs, self.parentrevs) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
481 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
482 def heads(self, start=None, stop=None): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
483 if start is None and stop is None: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
484 if not len(self): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
485 return [nullid] |
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 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
|
488 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
|
489 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
490 revs = dagop.headrevssubset( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
491 self.revs, self.parentrevs, startrev=startrev, stoprevs=stoprevs |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
492 ) |
40326
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 return [self.node(rev) for rev in revs] |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
495 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
496 def children(self, node): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
497 rev = self.rev(node) |
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 res = self._db.execute( |
43507
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
500 'SELECT' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
501 ' node ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
502 ' FROM filedata ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
503 ' WHERE path=? AND (p1rev=? OR p2rev=?) ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
504 ' ORDER BY revnum ASC', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
505 (self._path, rev, rev), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
506 ) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
507 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
508 return [row[0] for row in res] |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
509 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
510 # End of ifileindex interface. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
511 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
512 # Start of ifiledata interface. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
513 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
514 def size(self, rev): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
515 if rev == nullrev: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
516 return 0 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
517 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
518 if rev not in self._revtonode: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
519 raise IndexError(rev) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
520 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
521 node = self._revtonode[rev] |
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 if self.renamed(node): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
524 return len(self.read(node)) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
525 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
526 return len(self.revision(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 def revision(self, node, raw=False, _verifyhash=True): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
529 if node in (nullid, nullrev): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
530 return b'' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
531 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
532 if isinstance(node, int): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
533 node = self.node(node) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
534 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
535 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
|
536 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
|
537 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
538 if node in self._revisioncache: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
539 return self._revisioncache[node] |
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 # 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
|
542 # 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
|
543 # we encounter a revision in the cache. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
544 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
545 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
|
546 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
547 if not stoprids: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
548 stoprids[-1] = None |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
549 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
550 fulltext = resolvedeltachain( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
551 self._db, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
552 self._pathid, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
553 node, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
554 self._revisioncache, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
555 stoprids, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
556 zstddctx=self._dctx, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
557 ) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
558 |
40392
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
559 # 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
|
560 # wouldn't verify. |
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
561 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
|
562 _verifyhash = False |
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
563 |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
564 if _verifyhash: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
565 self._checkhash(fulltext, node) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
566 self._revisioncache[node] = fulltext |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
567 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
568 return fulltext |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
569 |
42722
c9f3f4c8999a
rawdata: implement `rawdata` for `sqlitestore` too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
40460
diff
changeset
|
570 def rawdata(self, *args, **kwargs): |
c9f3f4c8999a
rawdata: implement `rawdata` for `sqlitestore` too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
40460
diff
changeset
|
571 return self.revision(*args, **kwargs) |
c9f3f4c8999a
rawdata: implement `rawdata` for `sqlitestore` too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
40460
diff
changeset
|
572 |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
573 def read(self, node): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
574 return storageutil.filtermetadata(self.revision(node)) |
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 def renamed(self, node): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
577 return storageutil.filerevisioncopied(self, node) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
578 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
579 def cmp(self, node, fulltext): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
580 return not storageutil.filedataequivalent(self, node, fulltext) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
581 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
582 def emitrevisions( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
583 self, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
584 nodes, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
585 nodesorder=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
586 revisiondata=False, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
587 assumehaveparentrevisions=False, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
588 deltamode=repository.CG_DELTAMODE_STD, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
589 ): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
590 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
|
591 raise error.ProgrammingError( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
592 b'unhandled value for nodesorder: %s' % nodesorder |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
593 ) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
594 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
595 nodes = [n for n in nodes if n != nullid] |
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 if not nodes: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
598 return |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
599 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
600 # TODO perform in a single query. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
601 res = self._db.execute( |
43507
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
602 'SELECT revnum, deltaid FROM fileindex ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
603 'WHERE pathid=? ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
604 ' AND node in (%s)' % (','.join(['?'] * len(nodes))), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
605 tuple([self._pathid] + nodes), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
606 ) |
40326
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 deltabases = {} |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
609 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
610 for rev, deltaid in res: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
611 res = self._db.execute( |
43507
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
612 'SELECT revnum from fileindex WHERE pathid=? AND deltaid=?', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
613 (self._pathid, deltaid), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
614 ) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
615 deltabases[rev] = res.fetchone()[0] |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
616 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
617 # 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
|
618 for delta in storageutil.emitrevisions( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
619 self, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
620 nodes, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
621 nodesorder, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
622 sqliterevisiondelta, |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
623 deltaparentfn=deltabases.__getitem__, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
624 revisiondata=revisiondata, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
625 assumehaveparentrevisions=assumehaveparentrevisions, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
626 deltamode=deltamode, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
627 ): |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
628 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
629 yield delta |
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 # End of ifiledata interface. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
632 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
633 # Start of ifilemutation interface. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
634 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
635 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
|
636 if meta or filedata.startswith(b'\x01\n'): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
637 filedata = storageutil.packmeta(meta, filedata) |
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 return self.addrevision(filedata, transaction, linkrev, p1, p2) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
640 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
641 def addrevision( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
642 self, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
643 revisiondata, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
644 transaction, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
645 linkrev, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
646 p1, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
647 p2, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
648 node=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
649 flags=0, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
650 cachedelta=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
651 ): |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
652 if flags: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
653 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
|
654 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
655 validatehash = node is not None |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
656 node = node or storageutil.hashrevisionsha1(revisiondata, p1, p2) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
657 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
658 if validatehash: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
659 self._checkhash(revisiondata, node, p1, p2) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
660 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
661 if node in self._nodetorev: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
662 return node |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
663 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
664 node = self._addrawrevision( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
665 node, revisiondata, transaction, linkrev, p1, p2 |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
666 ) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
667 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
668 self._revisioncache[node] = revisiondata |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
669 return node |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
670 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
671 def addgroup( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
672 self, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
673 deltas, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
674 linkmapper, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
675 transaction, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
676 addrevisioncb=None, |
45788
a5206e71c536
revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents:
45372
diff
changeset
|
677 duplicaterevisioncb=None, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
678 maybemissingparents=False, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
679 ): |
45788
a5206e71c536
revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents:
45372
diff
changeset
|
680 empty = True |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
681 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
682 for node, p1, p2, linknode, deltabase, delta, wireflags in deltas: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
683 storeflags = 0 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
684 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
685 if wireflags & repository.REVISION_FLAG_CENSORED: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
686 storeflags |= FLAG_CENSORED |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
687 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
688 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
|
689 raise SQLiteStoreError(b'unhandled revision flag') |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
690 |
40392
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
691 if maybemissingparents: |
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
692 if p1 != nullid and not self.hasnode(p1): |
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
693 p1 = nullid |
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
694 storeflags |= FLAG_MISSING_P1 |
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
695 |
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
696 if p2 != nullid and not self.hasnode(p2): |
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
697 p2 = nullid |
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
698 storeflags |= FLAG_MISSING_P2 |
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
699 |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
700 baserev = self.rev(deltabase) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
701 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
702 # 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
|
703 # patch operation. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
704 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
|
705 hlen = struct.calcsize(b'>lll') |
42772
5c2e8a661418
rawdata: update callers in sqlitestore
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42760
diff
changeset
|
706 oldlen = len(self.rawdata(deltabase, _verifyhash=False)) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
707 newlen = len(delta) - hlen |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
708 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
709 if delta[:hlen] != mdiff.replacediffheader(oldlen, newlen): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
710 raise error.CensoredBaseError(self._path, deltabase) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
711 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
712 if not (storeflags & FLAG_CENSORED) and storageutil.deltaiscensored( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
713 delta, baserev, lambda x: len(self.rawdata(x)) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
714 ): |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
715 storeflags |= FLAG_CENSORED |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
716 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
717 linkrev = linkmapper(linknode) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
718 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
719 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
|
720 # 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
|
721 entry = self._revisions[node] |
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
722 |
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
723 if entry.flags & FLAG_MISSING_P1 and p1 != nullid: |
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
724 entry.p1node = p1 |
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
725 entry.p1rev = self._nodetorev[p1] |
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
726 entry.flags &= ~FLAG_MISSING_P1 |
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
727 |
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
728 self._db.execute( |
43507
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
729 'UPDATE fileindex SET p1rev=?, flags=? WHERE id=?', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
730 (self._nodetorev[p1], entry.flags, entry.rid), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
731 ) |
40392
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
732 |
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
733 if entry.flags & FLAG_MISSING_P2 and p2 != nullid: |
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
734 entry.p2node = p2 |
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
735 entry.p2rev = self._nodetorev[p2] |
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
736 entry.flags &= ~FLAG_MISSING_P2 |
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
737 |
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
738 self._db.execute( |
43507
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
739 'UPDATE fileindex SET p2rev=?, flags=? WHERE id=?', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
740 (self._nodetorev[p1], entry.flags, entry.rid), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
741 ) |
40392
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
742 |
45788
a5206e71c536
revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents:
45372
diff
changeset
|
743 if duplicaterevisioncb: |
a5206e71c536
revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents:
45372
diff
changeset
|
744 duplicaterevisioncb(self, node) |
a5206e71c536
revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents:
45372
diff
changeset
|
745 empty = False |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
746 continue |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
747 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
748 if deltabase == nullid: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
749 text = mdiff.patch(b'', delta) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
750 storedelta = None |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
751 else: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
752 text = None |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
753 storedelta = (deltabase, delta) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
754 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
755 self._addrawrevision( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
756 node, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
757 text, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
758 transaction, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
759 linkrev, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
760 p1, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
761 p2, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
762 storedelta=storedelta, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
763 flags=storeflags, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
764 ) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
765 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
766 if addrevisioncb: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
767 addrevisioncb(self, node) |
45788
a5206e71c536
revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents:
45372
diff
changeset
|
768 empty = False |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
769 |
45788
a5206e71c536
revlog: extend addgroup() with callback for duplicates
Joerg Sonnenberger <joerg@bec.de>
parents:
45372
diff
changeset
|
770 return not empty |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
771 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
772 def censorrevision(self, tr, censornode, tombstone=b''): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
773 tombstone = storageutil.packmeta({b'censored': tombstone}, b'') |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
774 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
775 # 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
|
776 # 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
|
777 if len(tombstone) > len(self.rawdata(censornode)): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
778 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
|
779 _(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
|
780 ) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
781 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
782 # 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
|
783 # 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
|
784 # reference it. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
785 # |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
786 # 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
|
787 # 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
|
788 # 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
|
789 # 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
|
790 # revision and insert a replacement. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
791 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
792 # Find the delta to be censored. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
793 censoreddeltaid = self._db.execute( |
43507
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
794 'SELECT deltaid FROM fileindex WHERE id=?', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
795 (self._revisions[censornode].rid,), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
796 ).fetchone()[0] |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
797 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
798 # Find all its delta chain children. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
799 # 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
|
800 # for those delta chains too. |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
801 rows = list( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
802 self._db.execute( |
43507
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
803 'SELECT id, pathid, node FROM fileindex ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
804 'WHERE deltabaseid=? OR deltaid=?', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
805 (censoreddeltaid, censoreddeltaid), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
806 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
807 ) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
808 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
809 for row in rows: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
810 rid, pathid, node = row |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
811 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
812 fulltext = resolvedeltachain( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
813 self._db, pathid, node, {}, {-1: None}, zstddctx=self._dctx |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
814 ) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
815 |
44062
2d49482d0dd4
hgext: replace references to hashlib.sha1 with hashutil.sha1
Augie Fackler <augie@google.com>
parents:
43507
diff
changeset
|
816 deltahash = hashutil.sha1(fulltext).digest() |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
817 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
818 if self._compengine == b'zstd': |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
819 deltablob = self._cctx.compress(fulltext) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
820 compression = COMPRESSION_ZSTD |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
821 elif self._compengine == b'zlib': |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
822 deltablob = zlib.compress(fulltext) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
823 compression = COMPRESSION_ZLIB |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
824 elif self._compengine == b'none': |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
825 deltablob = fulltext |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
826 compression = COMPRESSION_NONE |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
827 else: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
828 raise error.ProgrammingError( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
829 b'unhandled compression engine: %s' % self._compengine |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
830 ) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
831 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
832 if len(deltablob) >= len(fulltext): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
833 deltablob = fulltext |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
834 compression = COMPRESSION_NONE |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
835 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
836 deltaid = insertdelta(self._db, compression, deltahash, deltablob) |
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 self._db.execute( |
43507
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
839 'UPDATE fileindex SET deltaid=?, deltabaseid=NULL ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
840 'WHERE id=?', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
841 (deltaid, rid), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
842 ) |
40326
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 # 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
|
845 # node. |
44062
2d49482d0dd4
hgext: replace references to hashlib.sha1 with hashutil.sha1
Augie Fackler <augie@google.com>
parents:
43507
diff
changeset
|
846 deltahash = hashutil.sha1(tombstone).digest() |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
847 tombstonedeltaid = insertdelta( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
848 self._db, COMPRESSION_NONE, deltahash, tombstone |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
849 ) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
850 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
851 flags = self._revisions[censornode].flags |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
852 flags |= FLAG_CENSORED |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
853 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
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 'UPDATE fileindex SET flags=?, deltaid=?, deltabaseid=NULL ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
856 'WHERE pathid=? AND node=?', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
857 (flags, tombstonedeltaid, self._pathid, censornode), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
858 ) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
859 |
43507
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
860 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
|
861 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
862 self._refreshindex() |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
863 self._revisioncache.clear() |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
864 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
865 def getstrippoint(self, minlink): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
866 return storageutil.resolvestripinfo( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
867 minlink, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
868 len(self) - 1, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
869 [self.rev(n) for n in self.heads()], |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
870 self.linkrev, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
871 self.parentrevs, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
872 ) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
873 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
874 def strip(self, minlink, transaction): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
875 if not len(self): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
876 return |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
877 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
878 rev, _ignored = self.getstrippoint(minlink) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
879 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
880 if rev == len(self): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
881 return |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
882 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
883 for rev in self.revs(rev): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
884 self._db.execute( |
43507
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
885 'DELETE FROM fileindex WHERE pathid=? AND node=?', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
886 (self._pathid, self.node(rev)), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
887 ) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
888 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
889 # 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
|
890 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
891 self._refreshindex() |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
892 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
893 # End of ifilemutation interface. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
894 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
895 # Start of ifilestorage interface. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
896 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
897 def files(self): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
898 return [] |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
899 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
900 def storageinfo( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
901 self, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
902 exclusivefiles=False, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
903 sharedfiles=False, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
904 revisionscount=False, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
905 trackedsize=False, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
906 storedsize=False, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
907 ): |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
908 d = {} |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
909 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
910 if exclusivefiles: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
911 d[b'exclusivefiles'] = [] |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
912 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
913 if sharedfiles: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
914 # 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
|
915 d[b'sharedfiles'] = [] |
40326
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 if revisionscount: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
918 d[b'revisionscount'] = len(self) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
919 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
920 if trackedsize: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
921 d[b'trackedsize'] = sum( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
922 len(self.revision(node)) for node in self._nodetorev |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
923 ) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
924 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
925 if storedsize: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
926 # TODO implement this? |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
927 d[b'storedsize'] = None |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
928 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
929 return d |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
930 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
931 def verifyintegrity(self, state): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
932 state[b'skipread'] = set() |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
933 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
934 for rev in self: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
935 node = self.node(rev) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
936 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
937 try: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
938 self.revision(node) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
939 except Exception as e: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
940 yield sqliteproblem( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
941 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
|
942 ) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
943 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
944 state[b'skipread'].add(node) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
945 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
946 # End of ifilestorage interface. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
947 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
948 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
|
949 if p1 is None and p2 is None: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
950 p1, p2 = self.parents(node) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
951 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
952 if node == storageutil.hashrevisionsha1(fulltext, p1, p2): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
953 return |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
954 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
955 try: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
956 del self._revisioncache[node] |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
957 except KeyError: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
958 pass |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
959 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
960 if storageutil.iscensoredtext(fulltext): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
961 raise error.CensoredNodeError(self._path, node, fulltext) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
962 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
963 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
|
964 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
965 def _addrawrevision( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
966 self, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
967 node, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
968 revisiondata, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
969 transaction, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
970 linkrev, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
971 p1, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
972 p2, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
973 storedelta=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
974 flags=0, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
975 ): |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
976 if self._pathid is None: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
977 res = self._db.execute( |
43507
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
978 'INSERT INTO filepath (path) VALUES (?)', (self._path,) |
43076
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 self._pathid = res.lastrowid |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
981 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
982 # For simplicity, always store a delta against p1. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
983 # 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
|
984 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
985 if storedelta: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
986 deltabase, delta = storedelta |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
987 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
988 if isinstance(deltabase, int): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
989 deltabase = self.node(deltabase) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
990 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
991 else: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
992 assert revisiondata is not None |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
993 deltabase = p1 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
994 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
995 if deltabase == nullid: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
996 delta = revisiondata |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
997 else: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
998 delta = mdiff.textdiff( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
999 self.revision(self.rev(deltabase)), revisiondata |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1000 ) |
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 # 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
|
1003 # The parent delta is stored via a pointer to the fileindex PK. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1004 if deltabase == nullid: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1005 baseid = None |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1006 else: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1007 baseid = self._revisions[deltabase].rid |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1008 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1009 # 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
|
1010 # 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
|
1011 # 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
|
1012 # first. |
44062
2d49482d0dd4
hgext: replace references to hashlib.sha1 with hashutil.sha1
Augie Fackler <augie@google.com>
parents:
43507
diff
changeset
|
1013 deltahash = hashutil.sha1(delta).digest() |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1014 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1015 if self._compengine == b'zstd': |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1016 deltablob = self._cctx.compress(delta) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1017 compression = COMPRESSION_ZSTD |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1018 elif self._compengine == b'zlib': |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1019 deltablob = zlib.compress(delta) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1020 compression = COMPRESSION_ZLIB |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1021 elif self._compengine == b'none': |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1022 deltablob = delta |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1023 compression = COMPRESSION_NONE |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1024 else: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1025 raise error.ProgrammingError( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1026 b'unhandled compression engine: %s' % self._compengine |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1027 ) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1028 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1029 # 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
|
1030 if len(deltablob) >= len(delta): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1031 deltablob = delta |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1032 compression = COMPRESSION_NONE |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1033 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1034 deltaid = insertdelta(self._db, compression, deltahash, deltablob) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1035 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1036 rev = len(self) |
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 if p1 == nullid: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1039 p1rev = nullrev |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1040 else: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1041 p1rev = self._nodetorev[p1] |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1042 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1043 if p2 == nullid: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1044 p2rev = nullrev |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1045 else: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1046 p2rev = self._nodetorev[p2] |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1047 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1048 rid = self._db.execute( |
43507
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
1049 'INSERT INTO fileindex (' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
1050 ' pathid, revnum, node, p1rev, p2rev, linkrev, flags, ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
1051 ' deltaid, deltabaseid) ' |
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
1052 ' VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1053 ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1054 self._pathid, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1055 rev, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1056 node, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1057 p1rev, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1058 p2rev, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1059 linkrev, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1060 flags, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1061 deltaid, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1062 baseid, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1063 ), |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1064 ).lastrowid |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1065 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1066 entry = revisionentry( |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1067 rid=rid, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1068 rev=rev, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1069 node=node, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1070 p1rev=p1rev, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1071 p2rev=p2rev, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1072 p1node=p1, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1073 p2node=p2, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1074 linkrev=linkrev, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1075 flags=flags, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1076 ) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1077 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1078 self._nodetorev[node] = rev |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1079 self._revtonode[rev] = node |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1080 self._revisions[node] = entry |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1081 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1082 return node |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1083 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1084 |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1085 class sqliterepository(localrepo.localrepository): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1086 def cancopy(self): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1087 return False |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1088 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1089 def transaction(self, *args, **kwargs): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1090 current = self.currenttransaction() |
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 tr = super(sqliterepository, self).transaction(*args, **kwargs) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1093 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1094 if current: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1095 return tr |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1096 |
43507
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
1097 self._dbconn.execute('BEGIN TRANSACTION') |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1098 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1099 def committransaction(_): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1100 self._dbconn.commit() |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1101 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1102 tr.addfinalize(b'sqlitestore', committransaction) |
40326
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 return tr |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1105 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1106 @property |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1107 def _dbconn(self): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1108 # 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
|
1109 # 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
|
1110 # multiple threads. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1111 tid = threading.current_thread().ident |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1112 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1113 if self._db: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1114 if self._db[0] == tid: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1115 return self._db[1] |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1116 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1117 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
|
1118 self._db = (tid, db) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1119 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1120 return db |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1121 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1122 |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1123 def makedb(path): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1124 """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
|
1125 |
40410
3b782669561d
py3: make sure we pass sysstr in sqlite3.connect()
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
40392
diff
changeset
|
1126 db = sqlite3.connect(encoding.strfromlocal(path)) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1127 db.text_factory = bytes |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1128 |
43507
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
1129 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
|
1130 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1131 # New database. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1132 if res == 0: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1133 for statement in CREATE_SCHEMA: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1134 db.execute(statement) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1135 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1136 db.commit() |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1137 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1138 elif res == CURRENT_SCHEMA_VERSION: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1139 pass |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1140 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1141 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1142 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
|
1143 |
43507
adde839cc54f
sqlitestore: remove superfluous r-prefixes on strings
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
1144 db.execute('PRAGMA journal_mode=WAL') |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1145 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1146 return db |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1147 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1148 |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1149 def featuresetup(ui, supported): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1150 supported.add(REQUIREMENT) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1151 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1152 if zstd: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1153 supported.add(REQUIREMENT_ZSTD) |
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 supported.add(REQUIREMENT_ZLIB) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1156 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
|
1157 supported.add(REQUIREMENT_SHALLOW_FILES) |
45372
77b8588dd84e
requirements: introduce new requirements related module
Pulkit Goyal <7895pulkit@gmail.com>
parents:
44062
diff
changeset
|
1158 supported.add(requirements.NARROW_REQUIREMENT) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1159 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1160 |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1161 def newreporequirements(orig, ui, createopts): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1162 if createopts[b'backend'] != b'sqlite': |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1163 return orig(ui, createopts) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1164 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1165 # 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
|
1166 if b'sharedrepo' in createopts: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1167 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
|
1168 _(b'shared repositories not supported with SQLite store') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1169 ) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1170 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1171 # 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
|
1172 # 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
|
1173 # creation options we recognize. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1174 known = { |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1175 b'narrowfiles', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1176 b'backend', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1177 b'shallowfilestore', |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1178 } |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1179 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1180 unsupported = set(createopts) - known |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1181 if unsupported: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1182 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
|
1183 _(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
|
1184 % b', '.join(sorted(unsupported)) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1185 ) |
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 # 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
|
1188 # 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
|
1189 # own requirement. |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1190 createopts[b'backend'] = b'revlogv1' |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1191 requirements = orig(ui, createopts) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1192 requirements.add(REQUIREMENT) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1193 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1194 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
|
1195 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1196 if compression == b'zstd' and not zstd: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1197 raise error.Abort( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1198 _( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1199 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
|
1200 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
|
1201 b'Mercurial install' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1202 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1203 ) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1204 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1205 if compression == b'zstd': |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1206 requirements.add(REQUIREMENT_ZSTD) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1207 elif compression == b'zlib': |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1208 requirements.add(REQUIREMENT_ZLIB) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1209 elif compression == b'none': |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1210 requirements.add(REQUIREMENT_NONE) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1211 else: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1212 raise error.Abort( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1213 _( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1214 b'unknown compression engine defined in ' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1215 b'storage.sqlite.compression: %s' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1216 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1217 % compression |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1218 ) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1219 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1220 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
|
1221 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
|
1222 |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1223 return requirements |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1224 |
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 @interfaceutil.implementer(repository.ilocalrepositoryfilestorage) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1227 class sqlitefilestorage(object): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1228 """Repository file storage backed by SQLite.""" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1229 |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1230 def file(self, path): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1231 if path[0] == b'/': |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1232 path = path[1:] |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1233 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1234 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
|
1235 compression = b'zstd' |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1236 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
|
1237 compression = b'zlib' |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1238 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
|
1239 compression = b'none' |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1240 else: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1241 raise error.Abort( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1242 _( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1243 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
|
1244 b'to use for SQLite storage' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1245 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1246 ) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1247 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1248 return sqlitefilestore(self._dbconn, path, compression) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1249 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1250 |
40390
7e3b6c4f01a2
localrepo: support marking repos as having shallow file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40389
diff
changeset
|
1251 def makefilestorage(orig, requirements, features, **kwargs): |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1252 """Produce a type conforming to ``ilocalrepositoryfilestorage``.""" |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1253 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
|
1254 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
|
1255 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
|
1256 |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1257 return sqlitefilestorage |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1258 else: |
40390
7e3b6c4f01a2
localrepo: support marking repos as having shallow file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40389
diff
changeset
|
1259 return orig(requirements=requirements, features=features, **kwargs) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1260 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1261 |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1262 def makemain(orig, ui, requirements, **kwargs): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1263 if REQUIREMENT in requirements: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1264 if REQUIREMENT_ZSTD in requirements and not zstd: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1265 raise error.Abort( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1266 _( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1267 b'repository uses zstandard compression, which ' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1268 b'is not available to this Mercurial install' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1269 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1270 ) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1271 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1272 return sqliterepository |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1273 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1274 return orig(requirements=requirements, **kwargs) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1275 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1276 |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1277 def verifierinit(orig, self, *args, **kwargs): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1278 orig(self, *args, **kwargs) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1279 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1280 # 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
|
1281 # advertised. So suppress these warnings. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1282 self.warnorphanstorefiles = False |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1283 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1284 |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1285 def extsetup(ui): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1286 localrepo.featuresetupfuncs.add(featuresetup) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1287 extensions.wrapfunction( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1288 localrepo, b'newreporequirements', newreporequirements |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1289 ) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1290 extensions.wrapfunction(localrepo, b'makefilestorage', makefilestorage) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1291 extensions.wrapfunction(localrepo, b'makemain', makemain) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1292 extensions.wrapfunction(verify.verifier, b'__init__', verifierinit) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42814
diff
changeset
|
1293 |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1294 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1295 def reposetup(ui, repo): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1296 if isinstance(repo, sqliterepository): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1297 repo._db = None |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1298 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1299 # TODO check for bundlerepository? |