author | Gregory Szorc <gregory.szorc@gmail.com> |
Wed, 28 Nov 2018 10:37:43 -0800 | |
branch | stable |
changeset 40723 | 94b0d0f996e1 |
parent 40444 | 256b1f0c24e8 |
child 40460 | 4fe63b573791 |
permissions | -rw-r--r-- |
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 hashlib |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
49 |
import sqlite3 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
50 |
import struct |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
51 |
import threading |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
52 |
import zlib |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
53 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
54 |
from mercurial.i18n import _ |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
55 |
from mercurial.node import ( |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
56 |
nullid, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
57 |
nullrev, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
58 |
short, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
59 |
) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
60 |
from mercurial.thirdparty import ( |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
61 |
attr, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
62 |
) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
63 |
from mercurial import ( |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
64 |
ancestor, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
65 |
dagop, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
66 |
error, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
67 |
extensions, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
68 |
localrepo, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
69 |
mdiff, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
70 |
pycompat, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
71 |
registrar, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
72 |
repository, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
73 |
util, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
74 |
verify, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
75 |
) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
76 |
from mercurial.utils import ( |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
77 |
interfaceutil, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
78 |
storageutil, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
79 |
) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
80 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
81 |
try: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
82 |
from mercurial import zstd |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
83 |
zstd.__version__ |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
84 |
except ImportError: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
85 |
zstd = None |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
86 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
87 |
configtable = {} |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
88 |
configitem = registrar.configitem(configtable) |
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 |
# experimental config: storage.sqlite.compression |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
91 |
configitem('storage', 'sqlite.compression', |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
92 |
default='zstd' if zstd else 'zlib') |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
93 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
94 |
# 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
|
95 |
# 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
|
96 |
# 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
|
97 |
# leave the attribute unspecified. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
98 |
testedwith = 'ships-with-hg-core' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
99 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
100 |
REQUIREMENT = b'exp-sqlite-001' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
101 |
REQUIREMENT_ZSTD = b'exp-sqlite-comp-001=zstd' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
102 |
REQUIREMENT_ZLIB = b'exp-sqlite-comp-001=zlib' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
103 |
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
|
104 |
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
|
105 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
106 |
CURRENT_SCHEMA_VERSION = 1 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
107 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
108 |
COMPRESSION_NONE = 1 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
109 |
COMPRESSION_ZSTD = 2 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
110 |
COMPRESSION_ZLIB = 3 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
111 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
112 |
FLAG_CENSORED = 1 |
40392
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
113 |
FLAG_MISSING_P1 = 2 |
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
114 |
FLAG_MISSING_P2 = 4 |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
115 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
116 |
CREATE_SCHEMA = [ |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
117 |
# Deltas are stored as content-indexed blobs. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
118 |
# compression column holds COMPRESSION_* constant for how the |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
119 |
# delta is encoded. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
120 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
121 |
r'CREATE TABLE delta (' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
122 |
r' id INTEGER PRIMARY KEY, ' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
123 |
r' compression INTEGER NOT NULL, ' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
124 |
r' hash BLOB UNIQUE ON CONFLICT ABORT, ' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
125 |
r' delta BLOB NOT NULL ' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
126 |
r')', |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
127 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
128 |
# 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
|
129 |
# storage of the path name. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
130 |
r'CREATE TABLE filepath (' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
131 |
r' id INTEGER PRIMARY KEY, ' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
132 |
r' path BLOB NOT NULL ' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
133 |
r')', |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
134 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
135 |
r'CREATE UNIQUE INDEX filepath_path ' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
136 |
r' ON filepath (path)', |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
137 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
138 |
# 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
|
139 |
# 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
|
140 |
# (path, node). |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
141 |
# |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
142 |
# 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
|
143 |
# 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
|
144 |
# 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
|
145 |
# 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
|
146 |
# |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
147 |
# 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
|
148 |
# These flags are defined by the FLAG_* constants. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
149 |
r'CREATE TABLE fileindex (' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
150 |
r' id INTEGER PRIMARY KEY, ' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
151 |
r' pathid INTEGER REFERENCES filepath(id), ' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
152 |
r' revnum INTEGER NOT NULL, ' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
153 |
r' p1rev INTEGER NOT NULL, ' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
154 |
r' p2rev INTEGER NOT NULL, ' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
155 |
r' linkrev INTEGER NOT NULL, ' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
156 |
r' flags INTEGER NOT NULL, ' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
157 |
r' deltaid INTEGER REFERENCES delta(id), ' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
158 |
r' deltabaseid INTEGER REFERENCES fileindex(id), ' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
159 |
r' node BLOB NOT NULL ' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
160 |
r')', |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
161 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
162 |
r'CREATE UNIQUE INDEX fileindex_pathrevnum ' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
163 |
r' ON fileindex (pathid, revnum)', |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
164 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
165 |
r'CREATE UNIQUE INDEX fileindex_pathnode ' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
166 |
r' ON fileindex (pathid, node)', |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
167 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
168 |
# Provide a view over all file data for convenience. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
169 |
r'CREATE VIEW filedata AS ' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
170 |
r'SELECT ' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
171 |
r' fileindex.id AS id, ' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
172 |
r' filepath.id AS pathid, ' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
173 |
r' filepath.path AS path, ' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
174 |
r' fileindex.revnum AS revnum, ' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
175 |
r' fileindex.node AS node, ' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
176 |
r' fileindex.p1rev AS p1rev, ' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
177 |
r' fileindex.p2rev AS p2rev, ' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
178 |
r' fileindex.linkrev AS linkrev, ' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
179 |
r' fileindex.flags AS flags, ' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
180 |
r' fileindex.deltaid AS deltaid, ' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
181 |
r' fileindex.deltabaseid AS deltabaseid ' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
182 |
r'FROM filepath, fileindex ' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
183 |
r'WHERE fileindex.pathid=filepath.id', |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
184 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
185 |
r'PRAGMA user_version=%d' % CURRENT_SCHEMA_VERSION, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
186 |
] |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
187 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
188 |
def resolvedeltachain(db, pathid, node, revisioncache, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
189 |
stoprids, zstddctx=None): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
190 |
"""Resolve a delta chain for a file node.""" |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
191 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
192 |
# 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
|
193 |
# 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
|
194 |
# 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
|
195 |
# 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
|
196 |
# "is not null". |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
197 |
res = db.execute( |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
198 |
r'WITH RECURSIVE ' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
199 |
r' deltachain(deltaid, baseid) AS (' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
200 |
r' SELECT deltaid, deltabaseid FROM fileindex ' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
201 |
r' WHERE pathid=? AND node=? ' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
202 |
r' UNION ALL ' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
203 |
r' SELECT fileindex.deltaid, deltabaseid ' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
204 |
r' FROM fileindex, deltachain ' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
205 |
r' WHERE ' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
206 |
r' fileindex.id=deltachain.baseid ' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
207 |
r' AND deltachain.baseid IS NOT NULL ' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
208 |
r' AND fileindex.id NOT IN ({stops}) ' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
209 |
r' ) ' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
210 |
r'SELECT deltachain.baseid, compression, delta ' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
211 |
r'FROM deltachain, delta ' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
212 |
r'WHERE delta.id=deltachain.deltaid'.format( |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
213 |
stops=r','.join([r'?'] * len(stoprids))), |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
214 |
tuple([pathid, node] + list(stoprids.keys()))) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
215 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
216 |
deltas = [] |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
217 |
lastdeltabaseid = None |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
218 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
219 |
for deltabaseid, compression, delta in res: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
220 |
lastdeltabaseid = deltabaseid |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
221 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
222 |
if compression == COMPRESSION_ZSTD: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
223 |
delta = zstddctx.decompress(delta) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
224 |
elif compression == COMPRESSION_NONE: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
225 |
delta = delta |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
226 |
elif compression == COMPRESSION_ZLIB: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
227 |
delta = zlib.decompress(delta) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
228 |
else: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
229 |
raise SQLiteStoreError('unhandled compression type: %d' % |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
230 |
compression) |
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 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
250 |
def insertdelta(db, compression, hash, delta): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
251 |
try: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
252 |
return db.execute( |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
253 |
r'INSERT INTO delta (compression, hash, delta) ' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
254 |
r'VALUES (?, ?, ?)', |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
255 |
(compression, hash, delta)).lastrowid |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
256 |
except sqlite3.IntegrityError: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
257 |
return db.execute( |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
258 |
r'SELECT id FROM delta WHERE hash=?', |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
259 |
(hash,)).fetchone()[0] |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
260 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
261 |
class SQLiteStoreError(error.StorageError): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
262 |
pass |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
263 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
264 |
@attr.s |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
265 |
class revisionentry(object): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
266 |
rid = attr.ib() |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
267 |
rev = attr.ib() |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
268 |
node = attr.ib() |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
269 |
p1rev = attr.ib() |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
270 |
p2rev = attr.ib() |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
271 |
p1node = attr.ib() |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
272 |
p2node = attr.ib() |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
273 |
linkrev = attr.ib() |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
274 |
flags = attr.ib() |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
275 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
276 |
@interfaceutil.implementer(repository.irevisiondelta) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
277 |
@attr.s(slots=True) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
278 |
class sqliterevisiondelta(object): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
279 |
node = attr.ib() |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
280 |
p1node = attr.ib() |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
281 |
p2node = attr.ib() |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
282 |
basenode = attr.ib() |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
283 |
flags = attr.ib() |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
284 |
baserevisionsize = attr.ib() |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
285 |
revision = attr.ib() |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
286 |
delta = attr.ib() |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
287 |
linknode = attr.ib(default=None) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
288 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
289 |
@interfaceutil.implementer(repository.iverifyproblem) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
290 |
@attr.s(frozen=True) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
291 |
class sqliteproblem(object): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
292 |
warning = attr.ib(default=None) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
293 |
error = attr.ib(default=None) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
294 |
node = attr.ib(default=None) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
295 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
296 |
@interfaceutil.implementer(repository.ifilestorage) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
297 |
class sqlitefilestore(object): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
298 |
"""Implements storage for an individual tracked path.""" |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
299 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
300 |
def __init__(self, db, path, compression): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
301 |
self._db = db |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
302 |
self._path = path |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
303 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
304 |
self._pathid = None |
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 |
# revnum -> node |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
307 |
self._revtonode = {} |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
308 |
# node -> revnum |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
309 |
self._nodetorev = {} |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
310 |
# node -> data structure |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
311 |
self._revisions = {} |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
312 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
313 |
self._revisioncache = util.lrucachedict(10) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
314 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
315 |
self._compengine = compression |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
316 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
317 |
if compression == 'zstd': |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
318 |
self._cctx = zstd.ZstdCompressor(level=3) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
319 |
self._dctx = zstd.ZstdDecompressor() |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
320 |
else: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
321 |
self._cctx = None |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
322 |
self._dctx = None |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
323 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
324 |
self._refreshindex() |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
325 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
326 |
def _refreshindex(self): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
327 |
self._revtonode = {} |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
328 |
self._nodetorev = {} |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
329 |
self._revisions = {} |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
330 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
331 |
res = list(self._db.execute( |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
332 |
r'SELECT id FROM filepath WHERE path=?', (self._path,))) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
333 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
334 |
if not res: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
335 |
self._pathid = None |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
336 |
return |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
337 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
338 |
self._pathid = res[0][0] |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
339 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
340 |
res = self._db.execute( |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
341 |
r'SELECT id, revnum, node, p1rev, p2rev, linkrev, flags ' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
342 |
r'FROM fileindex ' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
343 |
r'WHERE pathid=? ' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
344 |
r'ORDER BY revnum ASC', |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
345 |
(self._pathid,)) |
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 |
for i, row in enumerate(res): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
348 |
rid, rev, node, p1rev, p2rev, linkrev, flags = row |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
349 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
350 |
if i != rev: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
351 |
raise SQLiteStoreError(_('sqlite database has inconsistent ' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
352 |
'revision numbers')) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
353 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
354 |
if p1rev == nullrev: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
355 |
p1node = nullid |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
356 |
else: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
357 |
p1node = self._revtonode[p1rev] |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
358 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
359 |
if p2rev == nullrev: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
360 |
p2node = nullid |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
361 |
else: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
362 |
p2node = self._revtonode[p2rev] |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
363 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
364 |
entry = revisionentry( |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
365 |
rid=rid, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
366 |
rev=rev, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
367 |
node=node, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
368 |
p1rev=p1rev, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
369 |
p2rev=p2rev, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
370 |
p1node=p1node, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
371 |
p2node=p2node, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
372 |
linkrev=linkrev, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
373 |
flags=flags) |
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 |
self._revtonode[rev] = node |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
376 |
self._nodetorev[node] = rev |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
377 |
self._revisions[node] = entry |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
378 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
379 |
# Start of ifileindex interface. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
380 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
381 |
def __len__(self): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
382 |
return len(self._revisions) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
383 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
384 |
def __iter__(self): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
385 |
return iter(pycompat.xrange(len(self._revisions))) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
386 |
|
40387
f1a39128da95
filelog: add a hasnode() method (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40326
diff
changeset
|
387 |
def hasnode(self, node): |
f1a39128da95
filelog: add a hasnode() method (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40326
diff
changeset
|
388 |
if node == nullid: |
f1a39128da95
filelog: add a hasnode() method (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40326
diff
changeset
|
389 |
return False |
f1a39128da95
filelog: add a hasnode() method (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40326
diff
changeset
|
390 |
|
f1a39128da95
filelog: add a hasnode() method (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40326
diff
changeset
|
391 |
return node in self._nodetorev |
f1a39128da95
filelog: add a hasnode() method (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40326
diff
changeset
|
392 |
|
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
393 |
def revs(self, start=0, stop=None): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
394 |
return storageutil.iterrevs(len(self._revisions), start=start, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
395 |
stop=stop) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
396 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
397 |
def parents(self, node): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
398 |
if node == nullid: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
399 |
return nullid, nullid |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
400 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
401 |
if node not in self._revisions: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
402 |
raise error.LookupError(node, self._path, _('no node')) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
403 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
404 |
entry = self._revisions[node] |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
405 |
return entry.p1node, entry.p2node |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
406 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
407 |
def parentrevs(self, rev): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
408 |
if rev == nullrev: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
409 |
return nullrev, nullrev |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
410 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
411 |
if rev not in self._revtonode: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
412 |
raise IndexError(rev) |
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 |
entry = self._revisions[self._revtonode[rev]] |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
415 |
return entry.p1rev, entry.p2rev |
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 |
def rev(self, node): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
418 |
if node == nullid: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
419 |
return nullrev |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
420 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
421 |
if node not in self._nodetorev: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
422 |
raise error.LookupError(node, self._path, _('no node')) |
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 |
return self._nodetorev[node] |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
425 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
426 |
def node(self, rev): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
427 |
if rev == nullrev: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
428 |
return nullid |
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 |
if rev not in self._revtonode: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
431 |
raise IndexError(rev) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
432 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
433 |
return self._revtonode[rev] |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
434 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
435 |
def lookup(self, node): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
436 |
return storageutil.fileidlookup(self, node, self._path) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
437 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
438 |
def linkrev(self, rev): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
439 |
if rev == nullrev: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
440 |
return nullrev |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
441 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
442 |
if rev not in self._revtonode: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
443 |
raise IndexError(rev) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
444 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
445 |
entry = self._revisions[self._revtonode[rev]] |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
446 |
return entry.linkrev |
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 iscensored(self, rev): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
449 |
if rev == nullrev: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
450 |
return False |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
451 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
452 |
if rev not in self._revtonode: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
453 |
raise IndexError(rev) |
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 |
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
|
456 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
457 |
def commonancestorsheads(self, node1, node2): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
458 |
rev1 = self.rev(node1) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
459 |
rev2 = self.rev(node2) |
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 |
ancestors = ancestor.commonancestorsheads(self.parentrevs, rev1, rev2) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
462 |
return pycompat.maplist(self.node, ancestors) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
463 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
464 |
def descendants(self, revs): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
465 |
# 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
|
466 |
# might be faster. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
467 |
return dagop.descendantrevs(revs, self.revs, self.parentrevs) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
468 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
469 |
def heads(self, start=None, stop=None): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
470 |
if start is None and stop is None: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
471 |
if not len(self): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
472 |
return [nullid] |
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 |
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
|
475 |
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
|
476 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
477 |
revs = dagop.headrevssubset(self.revs, self.parentrevs, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
478 |
startrev=startrev, stoprevs=stoprevs) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
479 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
480 |
return [self.node(rev) for rev in revs] |
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 children(self, node): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
483 |
rev = self.rev(node) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
484 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
485 |
res = self._db.execute( |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
486 |
r'SELECT' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
487 |
r' node ' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
488 |
r' FROM filedata ' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
489 |
r' WHERE path=? AND (p1rev=? OR p2rev=?) ' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
490 |
r' ORDER BY revnum ASC', |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
491 |
(self._path, rev, rev)) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
492 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
493 |
return [row[0] for row in res] |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
494 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
495 |
# End of ifileindex interface. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
496 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
497 |
# Start of ifiledata interface. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
498 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
499 |
def size(self, rev): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
500 |
if rev == nullrev: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
501 |
return 0 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
502 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
503 |
if rev not in self._revtonode: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
504 |
raise IndexError(rev) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
505 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
506 |
node = self._revtonode[rev] |
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 |
if self.renamed(node): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
509 |
return len(self.read(node)) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
510 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
511 |
return len(self.revision(node)) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
512 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
513 |
def revision(self, node, raw=False, _verifyhash=True): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
514 |
if node in (nullid, nullrev): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
515 |
return b'' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
516 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
517 |
if isinstance(node, int): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
518 |
node = self.node(node) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
519 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
520 |
if node not in self._nodetorev: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
521 |
raise error.LookupError(node, self._path, _('no node')) |
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 node in self._revisioncache: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
524 |
return self._revisioncache[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 |
# 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
|
527 |
# 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
|
528 |
# we encounter a revision in the cache. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
529 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
530 |
stoprids = {self._revisions[n].rid: n |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
531 |
for n in self._revisioncache} |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
532 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
533 |
if not stoprids: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
534 |
stoprids[-1] = None |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
535 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
536 |
fulltext = resolvedeltachain(self._db, self._pathid, node, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
537 |
self._revisioncache, stoprids, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
538 |
zstddctx=self._dctx) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
539 |
|
40392
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
540 |
# 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
|
541 |
# wouldn't verify. |
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
542 |
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
|
543 |
_verifyhash = False |
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
544 |
|
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
545 |
if _verifyhash: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
546 |
self._checkhash(fulltext, node) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
547 |
self._revisioncache[node] = fulltext |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
548 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
549 |
return fulltext |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
550 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
551 |
def read(self, node): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
552 |
return storageutil.filtermetadata(self.revision(node)) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
553 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
554 |
def renamed(self, node): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
555 |
return storageutil.filerevisioncopied(self, node) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
556 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
557 |
def cmp(self, node, fulltext): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
558 |
return not storageutil.filedataequivalent(self, node, fulltext) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
559 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
560 |
def emitrevisions(self, nodes, nodesorder=None, revisiondata=False, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
561 |
assumehaveparentrevisions=False, deltaprevious=False): |
40444
256b1f0c24e8
changegroup: introduce an explicit linear sorting
Boris Feld <boris.feld@octobus.net>
parents:
40392
diff
changeset
|
562 |
if nodesorder not in ('nodes', 'storage', 'linear', None): |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
563 |
raise error.ProgrammingError('unhandled value for nodesorder: %s' % |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
564 |
nodesorder) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
565 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
566 |
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
|
567 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
568 |
if not nodes: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
569 |
return |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
570 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
571 |
# TODO perform in a single query. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
572 |
res = self._db.execute( |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
573 |
r'SELECT revnum, deltaid FROM fileindex ' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
574 |
r'WHERE pathid=? ' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
575 |
r' AND node in (%s)' % (r','.join([r'?'] * len(nodes))), |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
576 |
tuple([self._pathid] + nodes)) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
577 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
578 |
deltabases = {} |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
579 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
580 |
for rev, deltaid in res: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
581 |
res = self._db.execute( |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
582 |
r'SELECT revnum from fileindex WHERE pathid=? AND deltaid=?', |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
583 |
(self._pathid, deltaid)) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
584 |
deltabases[rev] = res.fetchone()[0] |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
585 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
586 |
# 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
|
587 |
for delta in storageutil.emitrevisions( |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
588 |
self, nodes, nodesorder, sqliterevisiondelta, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
589 |
deltaparentfn=deltabases.__getitem__, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
590 |
revisiondata=revisiondata, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
591 |
assumehaveparentrevisions=assumehaveparentrevisions, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
592 |
deltaprevious=deltaprevious): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
593 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
594 |
yield delta |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
595 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
596 |
# End of ifiledata interface. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
597 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
598 |
# Start of ifilemutation interface. |
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 |
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
|
601 |
if meta or filedata.startswith(b'\x01\n'): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
602 |
filedata = storageutil.packmeta(meta, filedata) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
603 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
604 |
return self.addrevision(filedata, transaction, linkrev, p1, p2) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
605 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
606 |
def addrevision(self, revisiondata, transaction, linkrev, p1, p2, node=None, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
607 |
flags=0, cachedelta=None): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
608 |
if flags: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
609 |
raise SQLiteStoreError(_('flags not supported on revisions')) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
610 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
611 |
validatehash = node is not None |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
612 |
node = node or storageutil.hashrevisionsha1(revisiondata, p1, p2) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
613 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
614 |
if validatehash: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
615 |
self._checkhash(revisiondata, node, p1, p2) |
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 |
if node in self._nodetorev: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
618 |
return node |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
619 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
620 |
node = self._addrawrevision(node, revisiondata, transaction, linkrev, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
621 |
p1, p2) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
622 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
623 |
self._revisioncache[node] = revisiondata |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
624 |
return node |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
625 |
|
40389
1b183edbb68e
repository: teach addgroup() to receive data with missing parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40387
diff
changeset
|
626 |
def addgroup(self, deltas, linkmapper, transaction, addrevisioncb=None, |
1b183edbb68e
repository: teach addgroup() to receive data with missing parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40387
diff
changeset
|
627 |
maybemissingparents=False): |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
628 |
nodes = [] |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
629 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
630 |
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
|
631 |
storeflags = 0 |
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 |
if wireflags & repository.REVISION_FLAG_CENSORED: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
634 |
storeflags |= FLAG_CENSORED |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
635 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
636 |
if wireflags & ~repository.REVISION_FLAG_CENSORED: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
637 |
raise SQLiteStoreError('unhandled revision flag') |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
638 |
|
40392
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
639 |
if maybemissingparents: |
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
640 |
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
|
641 |
p1 = nullid |
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
642 |
storeflags |= FLAG_MISSING_P1 |
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
643 |
|
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
644 |
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
|
645 |
p2 = nullid |
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
646 |
storeflags |= FLAG_MISSING_P2 |
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
647 |
|
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
648 |
baserev = self.rev(deltabase) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
649 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
650 |
# 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
|
651 |
# patch operation. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
652 |
if baserev != nullrev and self.iscensored(baserev): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
653 |
hlen = struct.calcsize('>lll') |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
654 |
oldlen = len(self.revision(deltabase, raw=True, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
655 |
_verifyhash=False)) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
656 |
newlen = len(delta) - hlen |
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 delta[:hlen] != mdiff.replacediffheader(oldlen, newlen): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
659 |
raise error.CensoredBaseError(self._path, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
660 |
deltabase) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
661 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
662 |
if (not (storeflags & FLAG_CENSORED) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
663 |
and storageutil.deltaiscensored( |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
664 |
delta, baserev, lambda x: len(self.revision(x, raw=True)))): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
665 |
storeflags |= FLAG_CENSORED |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
666 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
667 |
linkrev = linkmapper(linknode) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
668 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
669 |
nodes.append(node) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
670 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
671 |
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
|
672 |
# 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
|
673 |
entry = self._revisions[node] |
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
674 |
|
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
675 |
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
|
676 |
entry.p1node = p1 |
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
677 |
entry.p1rev = self._nodetorev[p1] |
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
678 |
entry.flags &= ~FLAG_MISSING_P1 |
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
679 |
|
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
680 |
self._db.execute( |
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
681 |
r'UPDATE fileindex SET p1rev=?, flags=? ' |
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
682 |
r'WHERE id=?', |
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
683 |
(self._nodetorev[p1], entry.flags, entry.rid)) |
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
684 |
|
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
685 |
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
|
686 |
entry.p2node = p2 |
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
687 |
entry.p2rev = self._nodetorev[p2] |
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
688 |
entry.flags &= ~FLAG_MISSING_P2 |
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
689 |
|
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
690 |
self._db.execute( |
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
691 |
r'UPDATE fileindex SET p2rev=?, flags=? ' |
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
692 |
r'WHERE id=?', |
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
693 |
(self._nodetorev[p1], entry.flags, entry.rid)) |
595641bd8404
sqlitestore: support for storing revisions without their parents
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40390
diff
changeset
|
694 |
|
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
695 |
continue |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
696 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
697 |
if deltabase == nullid: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
698 |
text = mdiff.patch(b'', delta) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
699 |
storedelta = None |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
700 |
else: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
701 |
text = None |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
702 |
storedelta = (deltabase, delta) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
703 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
704 |
self._addrawrevision(node, text, transaction, linkrev, p1, p2, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
705 |
storedelta=storedelta, flags=storeflags) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
706 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
707 |
if addrevisioncb: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
708 |
addrevisioncb(self, node) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
709 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
710 |
return nodes |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
711 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
712 |
def censorrevision(self, tr, censornode, tombstone=b''): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
713 |
tombstone = storageutil.packmeta({b'censored': tombstone}, b'') |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
714 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
715 |
# 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
|
716 |
# SQLite, since columns can be resized at will. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
717 |
if len(tombstone) > len(self.revision(censornode, raw=True)): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
718 |
raise error.Abort(_('censor tombstone must be no longer than ' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
719 |
'censored data')) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
720 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
721 |
# 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
|
722 |
# 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
|
723 |
# reference it. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
724 |
# |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
725 |
# 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
|
726 |
# 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
|
727 |
# 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
|
728 |
# 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
|
729 |
# revision and insert a replacement. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
730 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
731 |
# Find the delta to be censored. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
732 |
censoreddeltaid = self._db.execute( |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
733 |
r'SELECT deltaid FROM fileindex WHERE id=?', |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
734 |
(self._revisions[censornode].rid,)).fetchone()[0] |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
735 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
736 |
# Find all its delta chain children. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
737 |
# 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
|
738 |
# for those delta chains too. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
739 |
rows = list(self._db.execute( |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
740 |
r'SELECT id, pathid, node FROM fileindex ' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
741 |
r'WHERE deltabaseid=? OR deltaid=?', |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
742 |
(censoreddeltaid, censoreddeltaid))) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
743 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
744 |
for row in rows: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
745 |
rid, pathid, node = row |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
746 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
747 |
fulltext = resolvedeltachain(self._db, pathid, node, {}, {-1: None}, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
748 |
zstddctx=self._dctx) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
749 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
750 |
deltahash = hashlib.sha1(fulltext).digest() |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
751 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
752 |
if self._compengine == 'zstd': |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
753 |
deltablob = self._cctx.compress(fulltext) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
754 |
compression = COMPRESSION_ZSTD |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
755 |
elif self._compengine == 'zlib': |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
756 |
deltablob = zlib.compress(fulltext) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
757 |
compression = COMPRESSION_ZLIB |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
758 |
elif self._compengine == 'none': |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
759 |
deltablob = fulltext |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
760 |
compression = COMPRESSION_NONE |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
761 |
else: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
762 |
raise error.ProgrammingError('unhandled compression engine: %s' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
763 |
% self._compengine) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
764 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
765 |
if len(deltablob) >= len(fulltext): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
766 |
deltablob = fulltext |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
767 |
compression = COMPRESSION_NONE |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
768 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
769 |
deltaid = insertdelta(self._db, compression, deltahash, deltablob) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
770 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
771 |
self._db.execute( |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
772 |
r'UPDATE fileindex SET deltaid=?, deltabaseid=NULL ' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
773 |
r'WHERE id=?', (deltaid, rid)) |
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 |
# 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
|
776 |
# node. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
777 |
deltahash = hashlib.sha1(tombstone).digest() |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
778 |
tombstonedeltaid = insertdelta(self._db, COMPRESSION_NONE, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
779 |
deltahash, tombstone) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
780 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
781 |
flags = self._revisions[censornode].flags |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
782 |
flags |= FLAG_CENSORED |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
783 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
784 |
self._db.execute( |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
785 |
r'UPDATE fileindex SET flags=?, deltaid=?, deltabaseid=NULL ' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
786 |
r'WHERE pathid=? AND node=?', |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
787 |
(flags, tombstonedeltaid, self._pathid, censornode)) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
788 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
789 |
self._db.execute( |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
790 |
r'DELETE FROM delta WHERE id=?', (censoreddeltaid,)) |
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 |
self._refreshindex() |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
793 |
self._revisioncache.clear() |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
794 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
795 |
def getstrippoint(self, minlink): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
796 |
return storageutil.resolvestripinfo(minlink, len(self) - 1, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
797 |
[self.rev(n) for n in self.heads()], |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
798 |
self.linkrev, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
799 |
self.parentrevs) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
800 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
801 |
def strip(self, minlink, transaction): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
802 |
if not len(self): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
803 |
return |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
804 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
805 |
rev, _ignored = self.getstrippoint(minlink) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
806 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
807 |
if rev == len(self): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
808 |
return |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
809 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
810 |
for rev in self.revs(rev): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
811 |
self._db.execute( |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
812 |
r'DELETE FROM fileindex WHERE pathid=? AND node=?', |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
813 |
(self._pathid, self.node(rev))) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
814 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
815 |
# 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
|
816 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
817 |
self._refreshindex() |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
818 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
819 |
# End of ifilemutation interface. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
820 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
821 |
# Start of ifilestorage interface. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
822 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
823 |
def files(self): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
824 |
return [] |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
825 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
826 |
def storageinfo(self, exclusivefiles=False, sharedfiles=False, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
827 |
revisionscount=False, trackedsize=False, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
828 |
storedsize=False): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
829 |
d = {} |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
830 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
831 |
if exclusivefiles: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
832 |
d['exclusivefiles'] = [] |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
833 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
834 |
if sharedfiles: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
835 |
# TODO list sqlite file(s) here. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
836 |
d['sharedfiles'] = [] |
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 |
if revisionscount: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
839 |
d['revisionscount'] = len(self) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
840 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
841 |
if trackedsize: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
842 |
d['trackedsize'] = sum(len(self.revision(node)) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
843 |
for node in self._nodetorev) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
844 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
845 |
if storedsize: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
846 |
# TODO implement this? |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
847 |
d['storedsize'] = None |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
848 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
849 |
return d |
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 |
def verifyintegrity(self, state): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
852 |
state['skipread'] = set() |
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 |
for rev in self: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
855 |
node = self.node(rev) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
856 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
857 |
try: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
858 |
self.revision(node) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
859 |
except Exception as e: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
860 |
yield sqliteproblem( |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
861 |
error=_('unpacking %s: %s') % (short(node), e), |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
862 |
node=node) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
863 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
864 |
state['skipread'].add(node) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
865 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
866 |
# End of ifilestorage interface. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
867 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
868 |
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
|
869 |
if p1 is None and p2 is None: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
870 |
p1, p2 = self.parents(node) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
871 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
872 |
if node == storageutil.hashrevisionsha1(fulltext, p1, p2): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
873 |
return |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
874 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
875 |
try: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
876 |
del self._revisioncache[node] |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
877 |
except KeyError: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
878 |
pass |
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 storageutil.iscensoredtext(fulltext): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
881 |
raise error.CensoredNodeError(self._path, node, fulltext) |
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 |
raise SQLiteStoreError(_('integrity check failed on %s') % |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
884 |
self._path) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
885 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
886 |
def _addrawrevision(self, node, revisiondata, transaction, linkrev, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
887 |
p1, p2, storedelta=None, flags=0): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
888 |
if self._pathid is None: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
889 |
res = self._db.execute( |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
890 |
r'INSERT INTO filepath (path) VALUES (?)', (self._path,)) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
891 |
self._pathid = res.lastrowid |
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 |
# For simplicity, always store a delta against p1. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
894 |
# 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
|
895 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
896 |
if storedelta: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
897 |
deltabase, delta = storedelta |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
898 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
899 |
if isinstance(deltabase, int): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
900 |
deltabase = self.node(deltabase) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
901 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
902 |
else: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
903 |
assert revisiondata is not None |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
904 |
deltabase = p1 |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
905 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
906 |
if deltabase == nullid: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
907 |
delta = revisiondata |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
908 |
else: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
909 |
delta = mdiff.textdiff(self.revision(self.rev(deltabase)), |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
910 |
revisiondata) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
911 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
912 |
# 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
|
913 |
# 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
|
914 |
if deltabase == nullid: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
915 |
baseid = None |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
916 |
else: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
917 |
baseid = self._revisions[deltabase].rid |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
918 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
919 |
# 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
|
920 |
# 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
|
921 |
# 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
|
922 |
# first. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
923 |
deltahash = hashlib.sha1(delta).digest() |
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 self._compengine == 'zstd': |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
926 |
deltablob = self._cctx.compress(delta) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
927 |
compression = COMPRESSION_ZSTD |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
928 |
elif self._compengine == 'zlib': |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
929 |
deltablob = zlib.compress(delta) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
930 |
compression = COMPRESSION_ZLIB |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
931 |
elif self._compengine == 'none': |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
932 |
deltablob = delta |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
933 |
compression = COMPRESSION_NONE |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
934 |
else: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
935 |
raise error.ProgrammingError('unhandled compression engine: %s' % |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
936 |
self._compengine) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
937 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
938 |
# 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
|
939 |
if len(deltablob) >= len(delta): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
940 |
deltablob = delta |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
941 |
compression = COMPRESSION_NONE |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
942 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
943 |
deltaid = insertdelta(self._db, compression, deltahash, deltablob) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
944 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
945 |
rev = len(self) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
946 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
947 |
if p1 == nullid: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
948 |
p1rev = nullrev |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
949 |
else: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
950 |
p1rev = self._nodetorev[p1] |
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 p2 == nullid: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
953 |
p2rev = nullrev |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
954 |
else: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
955 |
p2rev = self._nodetorev[p2] |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
956 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
957 |
rid = self._db.execute( |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
958 |
r'INSERT INTO fileindex (' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
959 |
r' pathid, revnum, node, p1rev, p2rev, linkrev, flags, ' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
960 |
r' deltaid, deltabaseid) ' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
961 |
r' VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)', |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
962 |
(self._pathid, rev, node, p1rev, p2rev, linkrev, flags, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
963 |
deltaid, baseid) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
964 |
).lastrowid |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
965 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
966 |
entry = revisionentry( |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
967 |
rid=rid, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
968 |
rev=rev, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
969 |
node=node, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
970 |
p1rev=p1rev, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
971 |
p2rev=p2rev, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
972 |
p1node=p1, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
973 |
p2node=p2, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
974 |
linkrev=linkrev, |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
975 |
flags=flags) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
976 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
977 |
self._nodetorev[node] = rev |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
978 |
self._revtonode[rev] = node |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
979 |
self._revisions[node] = entry |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
980 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
981 |
return node |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
982 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
983 |
class sqliterepository(localrepo.localrepository): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
984 |
def cancopy(self): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
985 |
return False |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
986 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
987 |
def transaction(self, *args, **kwargs): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
988 |
current = self.currenttransaction() |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
989 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
990 |
tr = super(sqliterepository, self).transaction(*args, **kwargs) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
991 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
992 |
if current: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
993 |
return tr |
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 |
self._dbconn.execute(r'BEGIN TRANSACTION') |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
996 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
997 |
def committransaction(_): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
998 |
self._dbconn.commit() |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
999 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1000 |
tr.addfinalize('sqlitestore', committransaction) |
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 |
return tr |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1003 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1004 |
@property |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1005 |
def _dbconn(self): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1006 |
# 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
|
1007 |
# 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
|
1008 |
# multiple threads. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1009 |
tid = threading.current_thread().ident |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1010 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1011 |
if self._db: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1012 |
if self._db[0] == tid: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1013 |
return self._db[1] |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1014 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1015 |
db = makedb(self.svfs.join('db.sqlite')) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1016 |
self._db = (tid, db) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1017 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1018 |
return db |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1019 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1020 |
def makedb(path): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1021 |
"""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
|
1022 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1023 |
db = sqlite3.connect(path) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1024 |
db.text_factory = bytes |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1025 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1026 |
res = db.execute(r'PRAGMA user_version').fetchone()[0] |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1027 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1028 |
# New database. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1029 |
if res == 0: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1030 |
for statement in CREATE_SCHEMA: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1031 |
db.execute(statement) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1032 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1033 |
db.commit() |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1034 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1035 |
elif res == CURRENT_SCHEMA_VERSION: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1036 |
pass |
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 |
else: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1039 |
raise error.Abort(_('sqlite database has unrecognized version')) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1040 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1041 |
db.execute(r'PRAGMA journal_mode=WAL') |
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 |
return db |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1044 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1045 |
def featuresetup(ui, supported): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1046 |
supported.add(REQUIREMENT) |
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 |
if zstd: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1049 |
supported.add(REQUIREMENT_ZSTD) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1050 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1051 |
supported.add(REQUIREMENT_ZLIB) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1052 |
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
|
1053 |
supported.add(REQUIREMENT_SHALLOW_FILES) |
7e3b6c4f01a2
localrepo: support marking repos as having shallow file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40389
diff
changeset
|
1054 |
supported.add(repository.NARROW_REQUIREMENT) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1055 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1056 |
def newreporequirements(orig, ui, createopts): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1057 |
if createopts['backend'] != 'sqlite': |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1058 |
return orig(ui, createopts) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1059 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1060 |
# This restriction can be lifted once we have more confidence. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1061 |
if 'sharedrepo' in createopts: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1062 |
raise error.Abort(_('shared repositories not supported with SQLite ' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1063 |
'store')) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1064 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1065 |
# 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
|
1066 |
# 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
|
1067 |
# creation options we recognize. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1068 |
known = { |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1069 |
'narrowfiles', |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1070 |
'backend', |
40390
7e3b6c4f01a2
localrepo: support marking repos as having shallow file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40389
diff
changeset
|
1071 |
'shallowfilestore', |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1072 |
} |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1073 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1074 |
unsupported = set(createopts) - known |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1075 |
if unsupported: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1076 |
raise error.Abort(_('SQLite store does not support repo creation ' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1077 |
'option: %s') % ', '.join(sorted(unsupported))) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1078 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1079 |
# 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
|
1080 |
# 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
|
1081 |
# own requirement. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1082 |
createopts['backend'] = 'revlogv1' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1083 |
requirements = orig(ui, createopts) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1084 |
requirements.add(REQUIREMENT) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1085 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1086 |
compression = ui.config('storage', 'sqlite.compression') |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1087 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1088 |
if compression == 'zstd' and not zstd: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1089 |
raise error.Abort(_('storage.sqlite.compression set to "zstd" but ' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1090 |
'zstandard compression not available to this ' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1091 |
'Mercurial install')) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1092 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1093 |
if compression == 'zstd': |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1094 |
requirements.add(REQUIREMENT_ZSTD) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1095 |
elif compression == 'zlib': |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1096 |
requirements.add(REQUIREMENT_ZLIB) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1097 |
elif compression == 'none': |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1098 |
requirements.add(REQUIREMENT_NONE) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1099 |
else: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1100 |
raise error.Abort(_('unknown compression engine defined in ' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1101 |
'storage.sqlite.compression: %s') % compression) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1102 |
|
40390
7e3b6c4f01a2
localrepo: support marking repos as having shallow file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40389
diff
changeset
|
1103 |
if createopts.get('shallowfilestore'): |
7e3b6c4f01a2
localrepo: support marking repos as having shallow file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40389
diff
changeset
|
1104 |
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
|
1105 |
|
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1106 |
return requirements |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1107 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1108 |
@interfaceutil.implementer(repository.ilocalrepositoryfilestorage) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1109 |
class sqlitefilestorage(object): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1110 |
"""Repository file storage backed by SQLite.""" |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1111 |
def file(self, path): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1112 |
if path[0] == b'/': |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1113 |
path = path[1:] |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1114 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1115 |
if REQUIREMENT_ZSTD in self.requirements: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1116 |
compression = 'zstd' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1117 |
elif REQUIREMENT_ZLIB in self.requirements: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1118 |
compression = 'zlib' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1119 |
elif REQUIREMENT_NONE in self.requirements: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1120 |
compression = 'none' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1121 |
else: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1122 |
raise error.Abort(_('unable to determine what compression engine ' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1123 |
'to use for SQLite storage')) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1124 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1125 |
return sqlitefilestore(self._dbconn, path, compression) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1126 |
|
40390
7e3b6c4f01a2
localrepo: support marking repos as having shallow file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40389
diff
changeset
|
1127 |
def makefilestorage(orig, requirements, features, **kwargs): |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1128 |
"""Produce a type conforming to ``ilocalrepositoryfilestorage``.""" |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1129 |
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
|
1130 |
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
|
1131 |
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
|
1132 |
|
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1133 |
return sqlitefilestorage |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1134 |
else: |
40390
7e3b6c4f01a2
localrepo: support marking repos as having shallow file storage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40389
diff
changeset
|
1135 |
return orig(requirements=requirements, features=features, **kwargs) |
40326
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1136 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1137 |
def makemain(orig, ui, requirements, **kwargs): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1138 |
if REQUIREMENT in requirements: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1139 |
if REQUIREMENT_ZSTD in requirements and not zstd: |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1140 |
raise error.Abort(_('repository uses zstandard compression, which ' |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1141 |
'is not available to this Mercurial install')) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1142 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1143 |
return sqliterepository |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1144 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1145 |
return orig(requirements=requirements, **kwargs) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1146 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1147 |
def verifierinit(orig, self, *args, **kwargs): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1148 |
orig(self, *args, **kwargs) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1149 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1150 |
# 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
|
1151 |
# advertised. So suppress these warnings. |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1152 |
self.warnorphanstorefiles = False |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1153 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1154 |
def extsetup(ui): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1155 |
localrepo.featuresetupfuncs.add(featuresetup) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1156 |
extensions.wrapfunction(localrepo, 'newreporequirements', |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1157 |
newreporequirements) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1158 |
extensions.wrapfunction(localrepo, 'makefilestorage', |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1159 |
makefilestorage) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1160 |
extensions.wrapfunction(localrepo, 'makemain', |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1161 |
makemain) |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1162 |
extensions.wrapfunction(verify.verifier, '__init__', |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1163 |
verifierinit) |
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 |
def reposetup(ui, repo): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1166 |
if isinstance(repo, sqliterepository): |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1167 |
repo._db = None |
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1168 |
|
fed697fa1734
sqlitestore: file storage backend using SQLite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1169 |
# TODO check for bundlerepository? |