hgext/remotefilelog/basepack.py
changeset 40506 10c10da14c5d
parent 40495 3a333a582d7b
child 40526 1419f780207c
equal deleted inserted replaced
40505:b6b2a3d22344 40506:10c10da14c5d
   258         return newpacks
   258         return newpacks
   259 
   259 
   260 class versionmixin(object):
   260 class versionmixin(object):
   261     # Mix-in for classes with multiple supported versions
   261     # Mix-in for classes with multiple supported versions
   262     VERSION = None
   262     VERSION = None
   263     SUPPORTED_VERSIONS = [0]
   263     SUPPORTED_VERSIONS = [2]
   264 
   264 
   265     def _checkversion(self, version):
   265     def _checkversion(self, version):
   266         if version in self.SUPPORTED_VERSIONS:
   266         if version in self.SUPPORTED_VERSIONS:
   267             if self.VERSION is None:
   267             if self.VERSION is None:
   268                 # only affect this instance
   268                 # only affect this instance
   275 class basepack(versionmixin):
   275 class basepack(versionmixin):
   276     # The maximum amount we should read via mmap before remmaping so the old
   276     # The maximum amount we should read via mmap before remmaping so the old
   277     # pages can be released (100MB)
   277     # pages can be released (100MB)
   278     MAXPAGEDIN = 100 * 1024**2
   278     MAXPAGEDIN = 100 * 1024**2
   279 
   279 
   280     SUPPORTED_VERSIONS = [0]
   280     SUPPORTED_VERSIONS = [2]
   281 
   281 
   282     def __init__(self, path):
   282     def __init__(self, path):
   283         self.path = path
   283         self.path = path
   284         self.packpath = path + self.PACKSUFFIX
   284         self.packpath = path + self.PACKSUFFIX
   285         self.indexpath = path + self.INDEXSUFFIX
   285         self.indexpath = path + self.INDEXSUFFIX
   313             fanouttable.append(fanoutentry)
   313             fanouttable.append(fanoutentry)
   314         return fanouttable
   314         return fanouttable
   315 
   315 
   316     @util.propertycache
   316     @util.propertycache
   317     def _indexend(self):
   317     def _indexend(self):
   318         if self.VERSION == 0:
   318         nodecount = struct.unpack_from('!Q', self._index,
   319             return self.indexsize
   319                                        self.params.indexstart - 8)[0]
   320         else:
   320         return self.params.indexstart + nodecount * self.INDEXENTRYLENGTH
   321             nodecount = struct.unpack_from('!Q', self._index,
       
   322                                            self.params.indexstart - 8)[0]
       
   323             return self.params.indexstart + nodecount * self.INDEXENTRYLENGTH
       
   324 
   321 
   325     def freememory(self):
   322     def freememory(self):
   326         """Unmap and remap the memory to free it up after known expensive
   323         """Unmap and remap the memory to free it up after known expensive
   327         operations. Return True if self._data and self._index were reloaded.
   324         operations. Return True if self._data and self._index were reloaded.
   328         """
   325         """
   359     def iterentries(self):
   356     def iterentries(self):
   360         raise NotImplementedError()
   357         raise NotImplementedError()
   361 
   358 
   362 class mutablebasepack(versionmixin):
   359 class mutablebasepack(versionmixin):
   363 
   360 
   364     def __init__(self, ui, packdir, version=0):
   361     def __init__(self, ui, packdir, version=2):
   365         self._checkversion(version)
   362         self._checkversion(version)
   366 
   363         # TODO(augie): make this configurable
       
   364         self._compressor = 'GZ'
   367         opener = vfsmod.vfs(packdir)
   365         opener = vfsmod.vfs(packdir)
   368         opener.createmode = 0o444
   366         opener.createmode = 0o444
   369         self.opener = opener
   367         self.opener = opener
   370 
   368 
   371         self.entries = {}
   369         self.entries = {}
   494         # header and the fanouttable.
   492         # header and the fanouttable.
   495         rawindex = self.createindex(locations, 2 + len(rawfanouttable))
   493         rawindex = self.createindex(locations, 2 + len(rawfanouttable))
   496 
   494 
   497         self._writeheader(params)
   495         self._writeheader(params)
   498         self.idxfp.write(rawfanouttable)
   496         self.idxfp.write(rawfanouttable)
   499         if self.VERSION == 1:
   497         self.idxfp.write(rawentrieslength)
   500             self.idxfp.write(rawentrieslength)
       
   501         self.idxfp.write(rawindex)
   498         self.idxfp.write(rawindex)
   502         self.idxfp.close()
   499         self.idxfp.close()
   503 
   500 
   504     def createindex(self, nodelocations):
   501     def createindex(self, nodelocations):
   505         raise NotImplementedError()
   502         raise NotImplementedError()
   536 
   533 
   537         # The total bytes used by the fanout table
   534         # The total bytes used by the fanout table
   538         self.fanoutsize = self.fanoutcount * 4
   535         self.fanoutsize = self.fanoutcount * 4
   539 
   536 
   540         self.indexstart = FANOUTSTART + self.fanoutsize
   537         self.indexstart = FANOUTSTART + self.fanoutsize
   541         if version == 1:
   538         # Skip the index length
   542             # Skip the index length
   539         self.indexstart += 8
   543             self.indexstart += 8