def get_raw(self, name): """Obtain the raw text for an object. :param name: sha for the object. :return: tuple with object type and object contents. """ if len(name) == 40: sha = hex_to_sha(name) hexsha = name elif len(name) == 20: sha = name hexsha = None else: raise AssertionError for pack in self.packs: try: return pack.get_raw(sha) except KeyError: pass if hexsha is None: hexsha = sha_to_hex(name) ret = self._get_shafile(hexsha) if ret is not None: return ret.type, ret.as_raw_string() raise KeyError(hexsha)
def object_index(self, sha): """Return the index in to the corresponding packfile for the object. Given the name of an object it will return the offset that object lives at within the corresponding pack file. If the pack file doesn't have the object then None will be returned. """ if len(sha) == 40: sha = hex_to_sha(sha) return self._object_index(sha)
def object_index(self, sha): """Return the index in to the corresponding packfile for the object. Given the name of an object it will return the offset that object lives at within the corresponding pack file. If the pack file doesn't have the object then None will be returned. """ size = os.path.getsize(self._filename) assert size == self._size, "Pack index %s has changed size, I don't " \ "like that" % self._filename if len(sha) == 40: sha = hex_to_sha(sha) return self._object_index(sha)
def write_cache_entry(f, entry): """Write an index entry to a file. :param f: File object :param entry: Entry to write, tuple with: (name, ctime, mtime, ino, dev, mode, uid, gid, size, sha, flags) """ beginoffset = f.tell() (name, ctime, mtime, ino, dev, mode, uid, gid, size, sha, flags) = entry write_cache_time(f, ctime) write_cache_time(f, mtime) f.write(struct.pack(">LLLLLL20sH", ino, dev, mode, uid, gid, size, hex_to_sha(sha), flags)) f.write(name) f.write(chr(0)) real_size = (f.tell() - beginoffset + 7) & ~7 f.write("\0" * ((beginoffset + real_size) - f.tell()))
def write_tree_array(self, tree_array): tree_array.sort(key=lambda x: x[1]) tree_data = '' for entry in tree_array: rawsha = hex_to_sha(entry[2]) if entry[0] == 'tree': tree_name = entry[1][0:-1] tree_data += "%s %s\0%s" % ('40000', tree_name, rawsha) if entry[0] == 'blob': # TODO : support submodules exec_flag = entry[3] link_flag = entry[4] if link_flag: mode = '120000' elif exec_flag: mode = '100755' else: mode = '100644' tree_data += "%s %s\0%s" % (mode, entry[1], rawsha) sha = self.write_object('tree', tree_data) return sha