hgext/remotefilelog/historypack.py
changeset 44062 2d49482d0dd4
parent 43105 649d3ac37a12
child 44452 9d2b2df2c2ba
equal deleted inserted replaced
44061:cbc5755df6bf 44062:2d49482d0dd4
     1 from __future__ import absolute_import
     1 from __future__ import absolute_import
     2 
     2 
     3 import hashlib
       
     4 import struct
     3 import struct
     5 
     4 
     6 from mercurial.node import hex, nullid
     5 from mercurial.node import hex, nullid
     7 from mercurial import (
     6 from mercurial import (
     8     pycompat,
     7     pycompat,
     9     util,
     8     util,
    10 )
     9 )
       
    10 from mercurial.utils import hashutil
    11 from . import (
    11 from . import (
    12     basepack,
    12     basepack,
    13     constants,
    13     constants,
    14     shallowutil,
    14     shallowutil,
    15 )
    15 )
   195 
   195 
   196         raise KeyError(b"unable to find history for %s:%s" % (name, hex(node)))
   196         raise KeyError(b"unable to find history for %s:%s" % (name, hex(node)))
   197 
   197 
   198     def _findsection(self, name):
   198     def _findsection(self, name):
   199         params = self.params
   199         params = self.params
   200         namehash = hashlib.sha1(name).digest()
   200         namehash = hashutil.sha1(name).digest()
   201         fanoutkey = struct.unpack(
   201         fanoutkey = struct.unpack(
   202             params.fanoutstruct, namehash[: params.fanoutprefix]
   202             params.fanoutstruct, namehash[: params.fanoutprefix]
   203         )[0]
   203         )[0]
   204         fanout = self._fanouttable
   204         fanout = self._fanouttable
   205 
   205 
   497 
   497 
   498             self.writeraw(rawdata)
   498             self.writeraw(rawdata)
   499 
   499 
   500             # Record metadata for the index
   500             # Record metadata for the index
   501             self.files[filename] = (sectionstart, sectionlen)
   501             self.files[filename] = (sectionstart, sectionlen)
   502             node = hashlib.sha1(filename).digest()
   502             node = hashutil.sha1(filename).digest()
   503             self.entries[node] = node
   503             self.entries[node] = node
   504 
   504 
   505     def close(self, ledger=None):
   505     def close(self, ledger=None):
   506         if self._closed:
   506         if self._closed:
   507             return
   507             return
   515         fileindexlength = self.INDEXENTRYLENGTH
   515         fileindexlength = self.INDEXENTRYLENGTH
   516         nodeindexformat = self.NODEINDEXFORMAT
   516         nodeindexformat = self.NODEINDEXFORMAT
   517         nodeindexlength = self.NODEINDEXENTRYLENGTH
   517         nodeindexlength = self.NODEINDEXENTRYLENGTH
   518 
   518 
   519         files = (
   519         files = (
   520             (hashlib.sha1(filename).digest(), filename, offset, size)
   520             (hashutil.sha1(filename).digest(), filename, offset, size)
   521             for filename, (offset, size) in pycompat.iteritems(self.files)
   521             for filename, (offset, size) in pycompat.iteritems(self.files)
   522         )
   522         )
   523         files = sorted(files)
   523         files = sorted(files)
   524 
   524 
   525         # node index is after file index size, file index, and node index size
   525         # node index is after file index size, file index, and node index size