Esempio n. 1
0
    def markledger(self, ledger, options=None):
        if options and options.get(constants.OPTION_PACKSONLY):
            return
        treename = b''
        rl = revlog.revlog(self._svfs, b'00manifesttree.i')
        startlinkrev = self._repackstartlinkrev
        endlinkrev = self._repackendlinkrev
        for rev in pycompat.xrange(len(rl) - 1, -1, -1):
            linkrev = rl.linkrev(rev)
            if linkrev < startlinkrev:
                break
            if linkrev > endlinkrev:
                continue
            node = rl.node(rev)
            ledger.markdataentry(self, treename, node)
            ledger.markhistoryentry(self, treename, node)

        for path, encoded, size in self._store.datafiles():
            if path[:5] != b'meta/' or path[-2:] != b'.i':
                continue

            treename = path[5 : -len(b'/00manifest.i')]

            rl = revlog.revlog(self._svfs, path)
            for rev in pycompat.xrange(len(rl) - 1, -1, -1):
                linkrev = rl.linkrev(rev)
                if linkrev < startlinkrev:
                    break
                if linkrev > endlinkrev:
                    continue
                node = rl.node(rev)
                ledger.markdataentry(self, treename, node)
                ledger.markhistoryentry(self, treename, node)
Esempio n. 2
0
    def markledger(self, ledger, options=None):
        if options and options.get(constants.OPTION_PACKSONLY):
            return
        treename = ''
        rl = revlog.revlog(self._svfs, '00manifesttree.i')
        startlinkrev = self._repackstartlinkrev
        endlinkrev = self._repackendlinkrev
        for rev in xrange(len(rl) - 1, -1, -1):
            linkrev = rl.linkrev(rev)
            if linkrev < startlinkrev:
                break
            if linkrev > endlinkrev:
                continue
            node = rl.node(rev)
            ledger.markdataentry(self, treename, node)
            ledger.markhistoryentry(self, treename, node)

        for path, encoded, size in self._store.datafiles():
            if path[:5] != 'meta/' or path[-2:] != '.i':
                continue

            treename = path[5:-len('/00manifest.i')]

            rl = revlog.revlog(self._svfs, path)
            for rev in xrange(len(rl) - 1, -1, -1):
                linkrev = rl.linkrev(rev)
                if linkrev < startlinkrev:
                    break
                if linkrev > endlinkrev:
                    continue
                node = rl.node(rev)
                ledger.markdataentry(self, treename, node)
                ledger.markhistoryentry(self, treename, node)
Esempio n. 3
0
def _getrevlog(repo, filename):
    path = 'undolog/' + filename
    try:
        return revlog.revlog(repo.vfs, path)
    except error.RevlogError:
        # corruption: for now, we can simply nuke all files
        repo.ui.debug("caught revlog error. %s was probably corrupted\n" % path)
        _logtoscuba(repo.ui, 'revlog error')
        repo.vfs.rmtree('undolog')
        repo.vfs.makedirs('undolog')
        # if we get the error a second time
        # then someone is actively messing with these files
        return revlog.revlog(repo.vfs, path)
Esempio n. 4
0
 def _revlog(self, name):
     rl = self._revlogs.get(name)
     if rl is None:
         revlogname = b'00manifesttree.i'
         if name != b'':
             revlogname = b'meta/%s/00manifest.i' % name
         rl = revlog.revlog(self._svfs, revlogname)
         self._revlogs[name] = rl
     return rl
Esempio n. 5
0
 def _revlog(self, name):
     rl = self._revlogs.get(name)
     if rl is None:
         revlogname = '00manifesttree.i'
         if name != '':
             revlogname = 'meta/%s/00manifest.i' % name
         rl = revlog.revlog(self._svfs, revlogname)
         self._revlogs[name] = rl
     return rl
Esempio n. 6
0
 def d():
     r = revlog.revlog(lambda fn: open(fn, 'rb'), file_)
     for x in xrange(0, len(r), dist):
         r.revision(r.node(x))
Esempio n. 7
0
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
Esempio n. 8
0
 def __init__(self, repo):
     self._store = repo.store
     self._svfs = repo.svfs
     self._revlogs = dict()
     self._cl = revlog.revlog(self._svfs, b'00changelog.i')
     self._repackstartlinkrev = 0
Esempio n. 9
0
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
Esempio n. 10
0
 def d():
     r = revlog.revlog(lambda fn: open(fn, 'rb'), file_)
     for x in xrange(0, len(r), dist):
         r.revision(r.node(x))
Esempio n. 11
0
def newrevlog(name=b'_testrevlog.i', recreate=False):
    if recreate:
        tvfs.tryunlink(name)
    rlog = revlog.revlog(tvfs, name)
    return rlog
Esempio n. 12
0
 def constructor():
     revlog.revlog(opener, indexfile)
def _upgrade(ui, repo):
    if not util.safehasattr(repo, 'svfs'):
        return
    if not ui.configbool('upgradegeneraldelta', 'upgrade'):
        return

    f = repo.svfs('00manifest.i')
    i = f.read(4)
    f.close()
    if len(i) < 4:
        # empty manifest
        return

    # probably only works with revlogng -- it became the default years ago so
    # that's fine
    v = revlog.versionformat_unpack(i)[0]
    isgeneraldelta = v & revlog.FLAG_GENERALDELTA
    if isgeneraldelta:
        return

    # write out a new revlog, this time with generaldelta
    oldopts = repo.svfs.options
    lock = repo.lock()
    tr = repo.transaction('upgradegeneraldelta')
    try:
        ui.warn(_('upgrading repository to generaldelta\n'))
        trp = weakref.proxy(tr)

        newopts = oldopts.copy()
        newopts['generaldelta'] = 1
        repo.svfs.options = newopts
        # remove 00manifestgd.i if present
        repo.svfs.unlinkpath('00manifestgd.i', ignoremissing=True)
        newmf = revlog.revlog(repo.svfs, '00manifestgd.i')
        oldmf = repo.manifest
        i = oldmf.index
        chunk = oldmf._chunk

        for rev in oldmf:
            ui.progress(_('upgrading'), rev, total=len(oldmf))
            e = i[rev]
            # if the delta base is the rev, this rev is a fulltext
            isdelta = (rev != e[3])
            revchunk = chunk(rev)
            if isdelta:
                newmf.addrevision(None, trp, e[4], i[e[5]][7], i[e[6]][7],
                                  cachedelta=(rev - 1, revchunk),
                                  node=e[7])
            else:
                newmf.addrevision(revchunk, trp, e[4], i[e[5]][7], i[e[6]][7],
                                  node=e[7])
        tr.close()
        if not ui.configbool('upgradegeneraldelta', 'dryrun', default=False):
            manifesti = repo.sjoin('00manifest.i')
            manifestd = repo.sjoin('00manifest.d')
            manifestgdi = repo.sjoin('00manifestgd.i')
            manifestgdd = repo.sjoin('00manifestgd.d')
            manifestoldi = repo.sjoin('00manifestold.i')
            manifestoldd = repo.sjoin('00manifestold.d')
            # move the newly created manifests over
            if ui.configbool('upgradegeneraldelta', 'backup', default=True):
                os.rename(manifesti, manifestoldi)
                if os.path.exists(manifestd):
                    os.rename(manifestd, manifestoldd)
            os.rename(manifestgdi, manifesti)
            if os.path.exists(manifestgdd):
                os.rename(manifestgdd, manifestd)
            with repo.opener('requires', 'a+') as f:
                f.write('generaldelta\n')
        repo.invalidate()
    finally:
        ui.progress(_('upgrading'), None)
        if tr:
            tr.release()
        lock.release()
        repo.svfs.options = oldopts
def shrink(ui, repo, **opts):
    """
    Shrink revlog by re-ordering revisions. Will operate on manifest for
    the given repository if no other revlog is specified."""

    # Unbuffer stdout for nice progress output.
    sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)

    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))

    datafn = indexfn[:-2] + '.d'
    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')
    if not os.path.exists(datafn):
        # This is just a lazy shortcut because I can't be bothered to
        # handle all the special cases that entail from no .d file.
        raise util.Abort('%s does not exist: revlog not big enough '
                         'to be worth shrinking' % datafn)

    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))

    ui.write('shrinking %s\n' % indexfn)
    prefix = os.path.basename(indexfn)[:-1]
    (tmpfd, tmpindexfn) = tempfile.mkstemp(dir=os.path.dirname(indexfn),
                                           prefix=prefix,
                                           suffix='.i')
    tmpdatafn = tmpindexfn[:-2] + '.d'
    os.close(tmpfd)

    r1 = revlog.revlog(util.opener(os.getcwd(), audit=False), indexfn)
    r2 = revlog.revlog(util.opener(os.getcwd(), audit=False), tmpindexfn)

    # 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'))

    try:
        try:
            order = toposort(ui, r1)
            writerevs(ui, r1, r2, order, tr)
            report(ui, datafn, tmpdatafn)
            tr.close()
        except:
            # Abort transaction first, so we truncate the files before
            # deleting them.
            tr.abort()
            if os.path.exists(tmpindexfn):
                os.unlink(tmpindexfn)
            if os.path.exists(tmpdatafn):
                os.unlink(tmpdatafn)
            raise
        if not opts.get('dry_run'):
            # Racy since both files cannot be renamed atomically
            util.os_link(indexfn, oldindexfn)
            util.os_link(datafn, olddatafn)
            util.rename(tmpindexfn, indexfn)
            util.rename(tmpdatafn, datafn)
        else:
            os.unlink(tmpindexfn)
            os.unlink(tmpdatafn)
    finally:
        lock.release()

    if not opts.get('dry_run'):
        ui.write(
            'note: old revlog saved in:\n'
            '  %s\n'
            '  %s\n'
            '(You can delete those files when you are satisfied that your\n'
            'repository is still sane.  '
            'Running \'hg verify\' is strongly recommended.)\n' %
            (oldindexfn, olddatafn))
Esempio n. 15
0
 def __init__(self, repo):
     self._store = repo.store
     self._svfs = repo.svfs
     self._revlogs = dict()
     self._cl = revlog.revlog(self._svfs, '00changelog.i')
     self._repackstartlinkrev = 0
def shrink(ui, repo, **opts):
    """
    Shrink revlog by re-ordering revisions. Will operate on manifest for
    the given repository if no other revlog is specified."""

    # Unbuffer stdout for nice progress output.
    sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)

    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))

    datafn = indexfn[:-2] + '.d'
    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')
    if not os.path.exists(datafn):
        # This is just a lazy shortcut because I can't be bothered to
        # handle all the special cases that entail from no .d file.
        raise util.Abort('%s does not exist: revlog not big enough '
                         'to be worth shrinking' % datafn)

    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))

    ui.write('shrinking %s\n' % indexfn)
    prefix = os.path.basename(indexfn)[:-1]
    (tmpfd, tmpindexfn) = tempfile.mkstemp(dir=os.path.dirname(indexfn),
                                           prefix=prefix,
                                           suffix='.i')
    tmpdatafn = tmpindexfn[:-2] + '.d'
    os.close(tmpfd)

    r1 = revlog.revlog(util.opener(os.getcwd(), audit=False), indexfn)
    r2 = revlog.revlog(util.opener(os.getcwd(), audit=False), tmpindexfn)

    # 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'))

    try:
        try:
            order = toposort(ui, r1)
            writerevs(ui, r1, r2, order, tr)
            report(ui, datafn, tmpdatafn)
            tr.close()
        except:
            # Abort transaction first, so we truncate the files before
            # deleting them.
            tr.abort()
            if os.path.exists(tmpindexfn):
                os.unlink(tmpindexfn)
            if os.path.exists(tmpdatafn):
                os.unlink(tmpdatafn)
            raise
        if not opts.get('dry_run'):
            # Racy since both files cannot be renamed atomically
            util.os_link(indexfn, oldindexfn)
            util.os_link(datafn, olddatafn)
            util.rename(tmpindexfn, indexfn)
            util.rename(tmpdatafn, datafn)
        else:
            os.unlink(tmpindexfn)
            os.unlink(tmpdatafn)
    finally:
        lock.release()

    if not opts.get('dry_run'):
        ui.write('note: old revlog saved in:\n'
                 '  %s\n'
                 '  %s\n'
                 '(You can delete those files when you are satisfied that your\n'
                 'repository is still sane.  '
                 'Running \'hg verify\' is strongly recommended.)\n'
                 % (oldindexfn, olddatafn))