def _set_cache_(self, attr): if attr == "entries": # read the current index # try memory map for speed lfd = LockedFD(self._file_path) try: fd = lfd.open(write=False, stream=False) except OSError: lfd.rollback() # in new repositories, there may be no index, which means we are empty self.entries = dict() return # END exception handling # Here it comes: on windows in python 2.5, memory maps aren't closed properly # Hence we are in trouble if we try to delete a file that is memory mapped, # which happens during read-tree. # In this case, we will just read the memory in directly. # Its insanely bad ... I am disappointed ! allow_mmap = (os.name != 'nt' or sys.version_info[1] > 5) stream = file_contents_ro(fd, stream=True, allow_mmap=allow_mmap) try: self._deserialize(stream) finally: lfd.rollback() # The handles will be closed on desctruction # END read from default index on demand else: super(IndexFile, self)._set_cache_(attr)
def _set_cache_(self, attr): if attr == "entries": # read the current index # try memory map for speed lfd = LockedFD(self._file_path) try: fd = lfd.open(write=False, stream=False) except OSError: lfd.rollback() # in new repositories, there may be no index, which means we are empty self.entries = dict() return # END exception handling stream = file_contents_ro(fd, stream=True, allow_mmap=True) try: self._deserialize(stream) finally: lfd.rollback() # The handles will be closed on desctruction # END read from default index on demand else: super(IndexFile, self)._set_cache_(attr)