Beispiel #1
0
 def sha(self):
     """The SHA1 object that is the name of this object."""
     if self._needs_serialization or self._sha is None:
         self._sha = make_sha()
         self._sha.update(self._header())
         self._sha.update(self.as_raw_string())
     return self._sha
Beispiel #2
0
    def calculate_checksum(self):
        """Calculate the checksum for this pack.

        :return: 20-byte binary SHA1 digest
        """
        map, map_offset = simple_mmap(self._file, 0, self._size - 20)
        try:
            return make_sha(map[map_offset:self._size-20]).digest()
        finally:
            map.close()
Beispiel #3
0
def iter_sha1(iter):
    """Return the hexdigest of the SHA1 over a set of names.
    
    :param iter: Iterator over string objects
    :return: 40-byte hex sha1 digest
    """
    sha1 = make_sha()
    for name in iter:
        sha1.update(name)
    return sha1.hexdigest()
Beispiel #4
0
 def write_object(self, obj_type, obj_contents):
     raw_data = "%s %d\0%s" % (obj_type, len(obj_contents), obj_contents)
     git_sha = make_sha(raw_data)
     git_hex_sha = git_sha.hexdigest()
     if not git_hex_sha in self.object_store:
         object_dir = os.path.join(self.path, OBJECTDIR, git_hex_sha[0:2])
         if not os.path.exists(object_dir):
             os.mkdir(object_dir)
         object_path = os.path.join(object_dir, git_hex_sha[2:])
         data = zlib.compress(raw_data)
         open(object_path, 'w').write(data) # write the object
     return git_hex_sha
Beispiel #5
0
 def __init__(self, f):
     self.f = f
     self.sha1 = make_sha("")
Beispiel #6
0
    def calculate_checksum(self):
        """Calculate the SHA1 checksum over this pack index.

        :return: This is a 20-byte binary digest
        """
        return make_sha(self._contents[:-20]).digest()