def setwithlimit(self, hexnode, manifest, limit=-1): """Writes a manifest to the cache. Returns True if the cache already contains the item or if the write is successful. Returns False if the write fails. Raises CacheFullException if writing the cache entry would cause us to pass the limit. """ if hexnode in self: return True path = self._pathfromnode(hexnode) if (isinstance(manifest, cfastmanifest.fastmanifest) or isinstance(manifest, fastmanifestdict)): fm = manifest else: fm = cfastmanifest.fastmanifest(manifest.text()) tmpfpath = util.mktempcopy(path, True) entrysize = fm.bytes() if limit != -1 and self.totalsize()[0] + entrysize > limit: raise CacheFullException() try: fm._save(tmpfpath) util.rename(tmpfpath, path) return True except EnvironmentError: return False finally: try: os.unlink(tmpfpath) except OSError: pass
def __init__(self, name, mode='w+b', createmode=None, checkambig=False): self.__name = name # permanent name self._tempname = util.mktempcopy(name, emptyok=('w' in mode), createmode=createmode) self._fp = posixfile_utf8(self._tempname, mode) self._checkambig = checkambig # delegated methods self.read = self._fp.read self.write = self._fp.write self.seek = self._fp.seek self.tell = self._fp.tell self.fileno = self._fp.fileno
def __init__(self, name, mode, createmode=None): self.__name = name self.temp = util.mktempcopy(name, emptyok=('w' in mode), createmode=createmode) posixfile_utf8.__init__(self, self.temp, mode)
def shrink(ui, repo, **opts): """shrink a revlog by reordering revisions Rewrites all the entries in some revlog of the current repository (by default, the manifest log) to save space. Different sort algorithms have different performance characteristics. Use ``--sort`` to select a sort algorithm so you can determine which works best for your data. """ if not repo.local(): raise util.Abort(_('not a local repository: %s') % repo.root) fn = opts.get('revlog') if not fn: indexfn = repo.sjoin('00manifest.i') else: if not fn.endswith('.i'): raise util.Abort(_('--revlog option must specify the revlog index ' 'file (*.i), not %s') % opts.get('revlog')) indexfn = os.path.realpath(fn) store = repo.sjoin('') if not indexfn.startswith(store): raise util.Abort(_('--revlog option must specify a revlog in %s, ' 'not %s') % (store, indexfn)) sortname = opts['sort'] try: toposort = globals()['toposort_' + sortname] except KeyError: raise util.Abort(_('no such toposort algorithm: %s') % sortname) if not os.path.exists(indexfn): raise util.Abort(_('no such file: %s') % indexfn) if '00changelog' in indexfn: raise util.Abort(_('shrinking the changelog ' 'will corrupt your repository')) ui.write(_('shrinking %s\n') % indexfn) tmpindexfn = util.mktempcopy(indexfn, emptyok=True) r1 = revlog.revlog(scmutil.opener(os.getcwd(), audit=False), indexfn) r2 = revlog.revlog(scmutil.opener(os.getcwd(), audit=False), tmpindexfn) datafn, tmpdatafn = r1.datafile, r2.datafile oldindexfn = indexfn + '.old' olddatafn = datafn + '.old' if os.path.exists(oldindexfn) or os.path.exists(olddatafn): raise util.Abort(_('one or both of\n' ' %s\n' ' %s\n' 'exists from a previous run; please clean up ' 'before running again') % (oldindexfn, olddatafn)) # Don't use repo.transaction(), because then things get hairy with # paths: some need to be relative to .hg, and some need to be # absolute. Doing it this way keeps things simple: everything is an # absolute path. lock = repo.lock(wait=False) tr = transaction.transaction(ui.warn, open, repo.sjoin('journal')) def ignoremissing(func): def f(*args, **kw): try: return func(*args, **kw) except OSError, inst: if inst.errno != errno.ENOENT: raise return f
def __init__(self, name, mode='w+b', createmode=None): self.__name = name self._tempname = util.mktempcopy(name, emptyok=('w' in mode), createmode=createmode) posixfile_utf8.__init__(self, self._tempname, mode)