Show More
@@ -121,19 +121,19 b' CREATE_SCHEMA = [' | |||||
121 | # Deltas are stored as content-indexed blobs. |
|
121 | # Deltas are stored as content-indexed blobs. | |
122 | # compression column holds COMPRESSION_* constant for how the |
|
122 | # compression column holds COMPRESSION_* constant for how the | |
123 | # delta is encoded. |
|
123 | # delta is encoded. | |
124 |
|
|
124 | 'CREATE TABLE delta (' | |
125 |
|
|
125 | ' id INTEGER PRIMARY KEY, ' | |
126 |
|
|
126 | ' compression INTEGER NOT NULL, ' | |
127 |
|
|
127 | ' hash BLOB UNIQUE ON CONFLICT ABORT, ' | |
128 |
|
|
128 | ' delta BLOB NOT NULL ' | |
129 |
|
|
129 | ')', | |
130 | # Tracked paths are denormalized to integers to avoid redundant |
|
130 | # Tracked paths are denormalized to integers to avoid redundant | |
131 | # storage of the path name. |
|
131 | # storage of the path name. | |
132 |
|
|
132 | 'CREATE TABLE filepath (' | |
133 |
|
|
133 | ' id INTEGER PRIMARY KEY, ' | |
134 |
|
|
134 | ' path BLOB NOT NULL ' | |
135 |
|
|
135 | ')', | |
136 |
|
|
136 | 'CREATE UNIQUE INDEX filepath_path ON filepath (path)', | |
137 | # We have a single table for all file revision data. |
|
137 | # We have a single table for all file revision data. | |
138 | # Each file revision is uniquely described by a (path, rev) and |
|
138 | # Each file revision is uniquely described by a (path, rev) and | |
139 | # (path, node). |
|
139 | # (path, node). | |
@@ -145,39 +145,38 b' CREATE_SCHEMA = [' | |||||
145 | # |
|
145 | # | |
146 | # flags column holds bitwise integer flags controlling storage options. |
|
146 | # flags column holds bitwise integer flags controlling storage options. | |
147 | # These flags are defined by the FLAG_* constants. |
|
147 | # These flags are defined by the FLAG_* constants. | |
148 |
|
|
148 | 'CREATE TABLE fileindex (' | |
149 |
|
|
149 | ' id INTEGER PRIMARY KEY, ' | |
150 |
|
|
150 | ' pathid INTEGER REFERENCES filepath(id), ' | |
151 |
|
|
151 | ' revnum INTEGER NOT NULL, ' | |
152 |
|
|
152 | ' p1rev INTEGER NOT NULL, ' | |
153 |
|
|
153 | ' p2rev INTEGER NOT NULL, ' | |
154 |
|
|
154 | ' linkrev INTEGER NOT NULL, ' | |
155 |
|
|
155 | ' flags INTEGER NOT NULL, ' | |
156 |
|
|
156 | ' deltaid INTEGER REFERENCES delta(id), ' | |
157 |
|
|
157 | ' deltabaseid INTEGER REFERENCES fileindex(id), ' | |
158 |
|
|
158 | ' node BLOB NOT NULL ' | |
159 |
|
|
159 | ')', | |
160 |
|
|
160 | 'CREATE UNIQUE INDEX fileindex_pathrevnum ' | |
161 |
|
|
161 | ' ON fileindex (pathid, revnum)', | |
162 |
|
|
162 | 'CREATE UNIQUE INDEX fileindex_pathnode ON fileindex (pathid, node)', | |
163 | r' ON fileindex (pathid, node)', |
|
|||
164 | # Provide a view over all file data for convenience. |
|
163 | # Provide a view over all file data for convenience. | |
165 |
|
|
164 | 'CREATE VIEW filedata AS ' | |
166 |
|
|
165 | 'SELECT ' | |
167 |
|
|
166 | ' fileindex.id AS id, ' | |
168 |
|
|
167 | ' filepath.id AS pathid, ' | |
169 |
|
|
168 | ' filepath.path AS path, ' | |
170 |
|
|
169 | ' fileindex.revnum AS revnum, ' | |
171 |
|
|
170 | ' fileindex.node AS node, ' | |
172 |
|
|
171 | ' fileindex.p1rev AS p1rev, ' | |
173 |
|
|
172 | ' fileindex.p2rev AS p2rev, ' | |
174 |
|
|
173 | ' fileindex.linkrev AS linkrev, ' | |
175 |
|
|
174 | ' fileindex.flags AS flags, ' | |
176 |
|
|
175 | ' fileindex.deltaid AS deltaid, ' | |
177 |
|
|
176 | ' fileindex.deltabaseid AS deltabaseid ' | |
178 |
|
|
177 | 'FROM filepath, fileindex ' | |
179 |
|
|
178 | 'WHERE fileindex.pathid=filepath.id', | |
180 |
|
|
179 | 'PRAGMA user_version=%d' % CURRENT_SCHEMA_VERSION, | |
181 | ] |
|
180 | ] | |
182 |
|
181 | |||
183 |
|
182 | |||
@@ -190,22 +189,22 b' def resolvedeltachain(db, pathid, node, ' | |||||
190 | # baseid "poisoned" to null and limited the recursive filter to |
|
189 | # baseid "poisoned" to null and limited the recursive filter to | |
191 | # "is not null". |
|
190 | # "is not null". | |
192 | res = db.execute( |
|
191 | res = db.execute( | |
193 |
|
|
192 | 'WITH RECURSIVE ' | |
194 |
|
|
193 | ' deltachain(deltaid, baseid) AS (' | |
195 |
|
|
194 | ' SELECT deltaid, deltabaseid FROM fileindex ' | |
196 |
|
|
195 | ' WHERE pathid=? AND node=? ' | |
197 |
|
|
196 | ' UNION ALL ' | |
198 |
|
|
197 | ' SELECT fileindex.deltaid, deltabaseid ' | |
199 |
|
|
198 | ' FROM fileindex, deltachain ' | |
200 |
|
|
199 | ' WHERE ' | |
201 |
|
|
200 | ' fileindex.id=deltachain.baseid ' | |
202 |
|
|
201 | ' AND deltachain.baseid IS NOT NULL ' | |
203 |
|
|
202 | ' AND fileindex.id NOT IN ({stops}) ' | |
204 |
|
|
203 | ' ) ' | |
205 |
|
|
204 | 'SELECT deltachain.baseid, compression, delta ' | |
206 |
|
|
205 | 'FROM deltachain, delta ' | |
207 |
|
|
206 | 'WHERE delta.id=deltachain.deltaid'.format( | |
208 |
stops= |
|
207 | stops=','.join(['?'] * len(stoprids)) | |
209 | ), |
|
208 | ), | |
210 | tuple([pathid, node] + list(stoprids.keys())), |
|
209 | tuple([pathid, node] + list(stoprids.keys())), | |
211 | ) |
|
210 | ) | |
@@ -249,13 +248,12 b' def resolvedeltachain(db, pathid, node, ' | |||||
249 | def insertdelta(db, compression, hash, delta): |
|
248 | def insertdelta(db, compression, hash, delta): | |
250 | try: |
|
249 | try: | |
251 | return db.execute( |
|
250 | return db.execute( | |
252 |
|
|
251 | 'INSERT INTO delta (compression, hash, delta) VALUES (?, ?, ?)', | |
253 | r'VALUES (?, ?, ?)', |
|
|||
254 | (compression, hash, delta), |
|
252 | (compression, hash, delta), | |
255 | ).lastrowid |
|
253 | ).lastrowid | |
256 | except sqlite3.IntegrityError: |
|
254 | except sqlite3.IntegrityError: | |
257 | return db.execute( |
|
255 | return db.execute( | |
258 |
|
|
256 | 'SELECT id FROM delta WHERE hash=?', (hash,) | |
259 | ).fetchone()[0] |
|
257 | ).fetchone()[0] | |
260 |
|
258 | |||
261 |
|
259 | |||
@@ -335,7 +333,7 b' class sqlitefilestore(object):' | |||||
335 |
|
333 | |||
336 | res = list( |
|
334 | res = list( | |
337 | self._db.execute( |
|
335 | self._db.execute( | |
338 |
|
|
336 | 'SELECT id FROM filepath WHERE path=?', (self._path,) | |
339 | ) |
|
337 | ) | |
340 | ) |
|
338 | ) | |
341 |
|
339 | |||
@@ -346,10 +344,10 b' class sqlitefilestore(object):' | |||||
346 | self._pathid = res[0][0] |
|
344 | self._pathid = res[0][0] | |
347 |
|
345 | |||
348 | res = self._db.execute( |
|
346 | res = self._db.execute( | |
349 |
|
|
347 | 'SELECT id, revnum, node, p1rev, p2rev, linkrev, flags ' | |
350 |
|
|
348 | 'FROM fileindex ' | |
351 |
|
|
349 | 'WHERE pathid=? ' | |
352 |
|
|
350 | 'ORDER BY revnum ASC', | |
353 | (self._pathid,), |
|
351 | (self._pathid,), | |
354 | ) |
|
352 | ) | |
355 |
|
353 | |||
@@ -496,11 +494,11 b' class sqlitefilestore(object):' | |||||
496 | rev = self.rev(node) |
|
494 | rev = self.rev(node) | |
497 |
|
495 | |||
498 | res = self._db.execute( |
|
496 | res = self._db.execute( | |
499 |
|
|
497 | 'SELECT' | |
500 |
|
|
498 | ' node ' | |
501 |
|
|
499 | ' FROM filedata ' | |
502 |
|
|
500 | ' WHERE path=? AND (p1rev=? OR p2rev=?) ' | |
503 |
|
|
501 | ' ORDER BY revnum ASC', | |
504 | (self._path, rev, rev), |
|
502 | (self._path, rev, rev), | |
505 | ) |
|
503 | ) | |
506 |
|
504 | |||
@@ -598,9 +596,9 b' class sqlitefilestore(object):' | |||||
598 |
|
596 | |||
599 | # TODO perform in a single query. |
|
597 | # TODO perform in a single query. | |
600 | res = self._db.execute( |
|
598 | res = self._db.execute( | |
601 |
|
|
599 | 'SELECT revnum, deltaid FROM fileindex ' | |
602 |
|
|
600 | 'WHERE pathid=? ' | |
603 |
|
|
601 | ' AND node in (%s)' % (','.join(['?'] * len(nodes))), | |
604 | tuple([self._pathid] + nodes), |
|
602 | tuple([self._pathid] + nodes), | |
605 | ) |
|
603 | ) | |
606 |
|
604 | |||
@@ -608,7 +606,7 b' class sqlitefilestore(object):' | |||||
608 |
|
606 | |||
609 | for rev, deltaid in res: |
|
607 | for rev, deltaid in res: | |
610 | res = self._db.execute( |
|
608 | res = self._db.execute( | |
611 |
|
|
609 | 'SELECT revnum from fileindex WHERE pathid=? AND deltaid=?', | |
612 | (self._pathid, deltaid), |
|
610 | (self._pathid, deltaid), | |
613 | ) |
|
611 | ) | |
614 | deltabases[rev] = res.fetchone()[0] |
|
612 | deltabases[rev] = res.fetchone()[0] | |
@@ -726,7 +724,7 b' class sqlitefilestore(object):' | |||||
726 | entry.flags &= ~FLAG_MISSING_P1 |
|
724 | entry.flags &= ~FLAG_MISSING_P1 | |
727 |
|
725 | |||
728 | self._db.execute( |
|
726 | self._db.execute( | |
729 |
|
|
727 | 'UPDATE fileindex SET p1rev=?, flags=? WHERE id=?', | |
730 | (self._nodetorev[p1], entry.flags, entry.rid), |
|
728 | (self._nodetorev[p1], entry.flags, entry.rid), | |
731 | ) |
|
729 | ) | |
732 |
|
730 | |||
@@ -736,7 +734,7 b' class sqlitefilestore(object):' | |||||
736 | entry.flags &= ~FLAG_MISSING_P2 |
|
734 | entry.flags &= ~FLAG_MISSING_P2 | |
737 |
|
735 | |||
738 | self._db.execute( |
|
736 | self._db.execute( | |
739 |
|
|
737 | 'UPDATE fileindex SET p2rev=?, flags=? WHERE id=?', | |
740 | (self._nodetorev[p1], entry.flags, entry.rid), |
|
738 | (self._nodetorev[p1], entry.flags, entry.rid), | |
741 | ) |
|
739 | ) | |
742 |
|
740 | |||
@@ -787,7 +785,7 b' class sqlitefilestore(object):' | |||||
787 |
|
785 | |||
788 | # Find the delta to be censored. |
|
786 | # Find the delta to be censored. | |
789 | censoreddeltaid = self._db.execute( |
|
787 | censoreddeltaid = self._db.execute( | |
790 |
|
|
788 | 'SELECT deltaid FROM fileindex WHERE id=?', | |
791 | (self._revisions[censornode].rid,), |
|
789 | (self._revisions[censornode].rid,), | |
792 | ).fetchone()[0] |
|
790 | ).fetchone()[0] | |
793 |
|
791 | |||
@@ -796,8 +794,8 b' class sqlitefilestore(object):' | |||||
796 | # for those delta chains too. |
|
794 | # for those delta chains too. | |
797 | rows = list( |
|
795 | rows = list( | |
798 | self._db.execute( |
|
796 | self._db.execute( | |
799 |
|
|
797 | 'SELECT id, pathid, node FROM fileindex ' | |
800 |
|
|
798 | 'WHERE deltabaseid=? OR deltaid=?', | |
801 | (censoreddeltaid, censoreddeltaid), |
|
799 | (censoreddeltaid, censoreddeltaid), | |
802 | ) |
|
800 | ) | |
803 | ) |
|
801 | ) | |
@@ -832,8 +830,8 b' class sqlitefilestore(object):' | |||||
832 | deltaid = insertdelta(self._db, compression, deltahash, deltablob) |
|
830 | deltaid = insertdelta(self._db, compression, deltahash, deltablob) | |
833 |
|
831 | |||
834 | self._db.execute( |
|
832 | self._db.execute( | |
835 |
|
|
833 | 'UPDATE fileindex SET deltaid=?, deltabaseid=NULL ' | |
836 |
|
|
834 | 'WHERE id=?', | |
837 | (deltaid, rid), |
|
835 | (deltaid, rid), | |
838 | ) |
|
836 | ) | |
839 |
|
837 | |||
@@ -848,12 +846,12 b' class sqlitefilestore(object):' | |||||
848 | flags |= FLAG_CENSORED |
|
846 | flags |= FLAG_CENSORED | |
849 |
|
847 | |||
850 | self._db.execute( |
|
848 | self._db.execute( | |
851 |
|
|
849 | 'UPDATE fileindex SET flags=?, deltaid=?, deltabaseid=NULL ' | |
852 |
|
|
850 | 'WHERE pathid=? AND node=?', | |
853 | (flags, tombstonedeltaid, self._pathid, censornode), |
|
851 | (flags, tombstonedeltaid, self._pathid, censornode), | |
854 | ) |
|
852 | ) | |
855 |
|
853 | |||
856 |
self._db.execute( |
|
854 | self._db.execute('DELETE FROM delta WHERE id=?', (censoreddeltaid,)) | |
857 |
|
855 | |||
858 | self._refreshindex() |
|
856 | self._refreshindex() | |
859 | self._revisioncache.clear() |
|
857 | self._revisioncache.clear() | |
@@ -878,7 +876,7 b' class sqlitefilestore(object):' | |||||
878 |
|
876 | |||
879 | for rev in self.revs(rev): |
|
877 | for rev in self.revs(rev): | |
880 | self._db.execute( |
|
878 | self._db.execute( | |
881 |
|
|
879 | 'DELETE FROM fileindex WHERE pathid=? AND node=?', | |
882 | (self._pathid, self.node(rev)), |
|
880 | (self._pathid, self.node(rev)), | |
883 | ) |
|
881 | ) | |
884 |
|
882 | |||
@@ -971,7 +969,7 b' class sqlitefilestore(object):' | |||||
971 | ): |
|
969 | ): | |
972 | if self._pathid is None: |
|
970 | if self._pathid is None: | |
973 | res = self._db.execute( |
|
971 | res = self._db.execute( | |
974 |
|
|
972 | 'INSERT INTO filepath (path) VALUES (?)', (self._path,) | |
975 | ) |
|
973 | ) | |
976 | self._pathid = res.lastrowid |
|
974 | self._pathid = res.lastrowid | |
977 |
|
975 | |||
@@ -1042,10 +1040,10 b' class sqlitefilestore(object):' | |||||
1042 | p2rev = self._nodetorev[p2] |
|
1040 | p2rev = self._nodetorev[p2] | |
1043 |
|
1041 | |||
1044 | rid = self._db.execute( |
|
1042 | rid = self._db.execute( | |
1045 |
|
|
1043 | 'INSERT INTO fileindex (' | |
1046 |
|
|
1044 | ' pathid, revnum, node, p1rev, p2rev, linkrev, flags, ' | |
1047 |
|
|
1045 | ' deltaid, deltabaseid) ' | |
1048 |
|
|
1046 | ' VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)', | |
1049 | ( |
|
1047 | ( | |
1050 | self._pathid, |
|
1048 | self._pathid, | |
1051 | rev, |
|
1049 | rev, | |
@@ -1090,7 +1088,7 b' class sqliterepository(localrepo.localre' | |||||
1090 | if current: |
|
1088 | if current: | |
1091 | return tr |
|
1089 | return tr | |
1092 |
|
1090 | |||
1093 |
self._dbconn.execute( |
|
1091 | self._dbconn.execute('BEGIN TRANSACTION') | |
1094 |
|
1092 | |||
1095 | def committransaction(_): |
|
1093 | def committransaction(_): | |
1096 | self._dbconn.commit() |
|
1094 | self._dbconn.commit() | |
@@ -1122,7 +1120,7 b' def makedb(path):' | |||||
1122 | db = sqlite3.connect(encoding.strfromlocal(path)) |
|
1120 | db = sqlite3.connect(encoding.strfromlocal(path)) | |
1123 | db.text_factory = bytes |
|
1121 | db.text_factory = bytes | |
1124 |
|
1122 | |||
1125 |
res = db.execute( |
|
1123 | res = db.execute('PRAGMA user_version').fetchone()[0] | |
1126 |
|
1124 | |||
1127 | # New database. |
|
1125 | # New database. | |
1128 | if res == 0: |
|
1126 | if res == 0: | |
@@ -1137,7 +1135,7 b' def makedb(path):' | |||||
1137 | else: |
|
1135 | else: | |
1138 | raise error.Abort(_(b'sqlite database has unrecognized version')) |
|
1136 | raise error.Abort(_(b'sqlite database has unrecognized version')) | |
1139 |
|
1137 | |||
1140 |
db.execute( |
|
1138 | db.execute('PRAGMA journal_mode=WAL') | |
1141 |
|
1139 | |||
1142 | return db |
|
1140 | return db | |
1143 |
|
1141 |
General Comments 0
You need to be logged in to leave comments.
Login now