hgext/sqlitestore.py
branchstable
changeset 49366 288de6f5d724
parent 49284 d44e3c45f0e4
child 49610 9cac281eb9c0
child 49789 df750b81272f
equal deleted inserted replaced
49364:e8ea403b1c46 49366:288de6f5d724
    41 #
    41 #
    42 # HGREPOFEATURES="sqlitestore" run-tests.py \
    42 # HGREPOFEATURES="sqlitestore" run-tests.py \
    43 #     --extra-config-opt extensions.sqlitestore= \
    43 #     --extra-config-opt extensions.sqlitestore= \
    44 #     --extra-config-opt storage.new-repo-backend=sqlite
    44 #     --extra-config-opt storage.new-repo-backend=sqlite
    45 
    45 
    46 from __future__ import absolute_import
       
    47 
    46 
    48 import sqlite3
    47 import sqlite3
    49 import struct
    48 import struct
    50 import threading
    49 import threading
    51 import zlib
    50 import zlib
   263 class SQLiteStoreError(error.StorageError):
   262 class SQLiteStoreError(error.StorageError):
   264     pass
   263     pass
   265 
   264 
   266 
   265 
   267 @attr.s
   266 @attr.s
   268 class revisionentry(object):
   267 class revisionentry:
   269     rid = attr.ib()
   268     rid = attr.ib()
   270     rev = attr.ib()
   269     rev = attr.ib()
   271     node = attr.ib()
   270     node = attr.ib()
   272     p1rev = attr.ib()
   271     p1rev = attr.ib()
   273     p2rev = attr.ib()
   272     p2rev = attr.ib()
   277     flags = attr.ib()
   276     flags = attr.ib()
   278 
   277 
   279 
   278 
   280 @interfaceutil.implementer(repository.irevisiondelta)
   279 @interfaceutil.implementer(repository.irevisiondelta)
   281 @attr.s(slots=True)
   280 @attr.s(slots=True)
   282 class sqliterevisiondelta(object):
   281 class sqliterevisiondelta:
   283     node = attr.ib()
   282     node = attr.ib()
   284     p1node = attr.ib()
   283     p1node = attr.ib()
   285     p2node = attr.ib()
   284     p2node = attr.ib()
   286     basenode = attr.ib()
   285     basenode = attr.ib()
   287     flags = attr.ib()
   286     flags = attr.ib()
   293     linknode = attr.ib(default=None)
   292     linknode = attr.ib(default=None)
   294 
   293 
   295 
   294 
   296 @interfaceutil.implementer(repository.iverifyproblem)
   295 @interfaceutil.implementer(repository.iverifyproblem)
   297 @attr.s(frozen=True)
   296 @attr.s(frozen=True)
   298 class sqliteproblem(object):
   297 class sqliteproblem:
   299     warning = attr.ib(default=None)
   298     warning = attr.ib(default=None)
   300     error = attr.ib(default=None)
   299     error = attr.ib(default=None)
   301     node = attr.ib(default=None)
   300     node = attr.ib(default=None)
   302 
   301 
   303 
   302 
   304 @interfaceutil.implementer(repository.ifilestorage)
   303 @interfaceutil.implementer(repository.ifilestorage)
   305 class sqlitefilestore(object):
   304 class sqlitefilestore:
   306     """Implements storage for an individual tracked path."""
   305     """Implements storage for an individual tracked path."""
   307 
   306 
   308     def __init__(self, db, path, compression):
   307     def __init__(self, db, path, compression):
   309         self.nullid = sha1nodeconstants.nullid
   308         self.nullid = sha1nodeconstants.nullid
   310         self._db = db
   309         self._db = db
   395 
   394 
   396     def __len__(self):
   395     def __len__(self):
   397         return len(self._revisions)
   396         return len(self._revisions)
   398 
   397 
   399     def __iter__(self):
   398     def __iter__(self):
   400         return iter(pycompat.xrange(len(self._revisions)))
   399         return iter(range(len(self._revisions)))
   401 
   400 
   402     def hasnode(self, node):
   401     def hasnode(self, node):
   403         if node == sha1nodeconstants.nullid:
   402         if node == sha1nodeconstants.nullid:
   404             return False
   403             return False
   405 
   404 
  1248 
  1247 
  1249     return requirements
  1248     return requirements
  1250 
  1249 
  1251 
  1250 
  1252 @interfaceutil.implementer(repository.ilocalrepositoryfilestorage)
  1251 @interfaceutil.implementer(repository.ilocalrepositoryfilestorage)
  1253 class sqlitefilestorage(object):
  1252 class sqlitefilestorage:
  1254     """Repository file storage backed by SQLite."""
  1253     """Repository file storage backed by SQLite."""
  1255 
  1254 
  1256     def file(self, path):
  1255     def file(self, path):
  1257         if path[0] == b'/':
  1256         if path[0] == b'/':
  1258             path = path[1:]
  1257             path = path[1:]