Пример #1
0
def stream_out(repo, untrusted=False):
    '''stream out all metadata files in repository.
    writes to file-like object, must support write() and optional flush().'''

    if not repo.ui.configbool('server', 'uncompressed', untrusted=untrusted):
        raise StreamException(1)

    entries = []
    total_bytes = 0
    try:
        # get consistent snapshot of repo, lock during scan
        lock = repo.lock()
        try:
            repo.ui.debug(_('scanning\n'))
            for name, ename, size in repo.store.walk():
                # for backwards compat, name was partially encoded
                entries.append((store.encodedir(name), size))
                total_bytes += size
        finally:
            lock.release()
    except error.LockError:
        raise StreamException(2)

    yield '0\n'
    repo.ui.debug(_('%d files, %d bytes to transfer\n') %
                  (len(entries), total_bytes))
    yield '%d %d\n' % (len(entries), total_bytes)
    for name, size in entries:
        repo.ui.debug(_('sending %s (%d bytes)\n') % (name, size))
        yield '%s\0%d\n' % (name, size)
        for chunk in util.filechunkiter(repo.sopener(name), limit=size):
            yield chunk
Пример #2
0
def generatestreamclone(repo):
    """Emit content for a streaming clone.

    This is a generator of raw chunks that constitute a streaming clone.

    This code is copied from Mercurial. Until Mercurial 3.5, this code was
    a closure in wireproto.py and not consumeable by extensions.
    """
    entries = []
    total_bytes = 0
    # Get consistent snapshot of repo, lock during scan.
    lock = repo.lock()
    try:
        repo.ui.debug('scanning\n')
        for name, ename, size in repo.store.walk():
            if size:
                entries.append((name, size))
                total_bytes += size
    finally:
            lock.release()

    repo.ui.debug('%d files, %d bytes to transfer\n' %
                  (len(entries), total_bytes))
    yield '%d %d\n' % (len(entries), total_bytes)

    sopener = repo.svfs
    oldaudit = sopener.mustaudit
    debugflag = repo.ui.debugflag
    sopener.mustaudit = False

    try:
        for name, size in entries:
            if debugflag:
                repo.ui.debug('sending %s (%d bytes)\n' % (name, size))
            # partially encode name over the wire for backwards compat
            yield '%s\0%d\n' % (store.encodedir(name), size)
            if size <= 65536:
                fp = sopener(name)
                try:
                    data = fp.read(size)
                finally:
                    fp.close()
                yield data
            else:
                for chunk in util.filechunkiter(sopener(name), limit=size):
                    yield chunk
    finally:
        sopener.mustaudit = oldaudit
Пример #3
0
 def emitrevlogdata():
     try:
         for name, size in entries:
             if debugflag:
                 repo.ui.debug('sending %s (%d bytes)\n' % (name, size))
             # partially encode name over the wire for backwards compat
             yield '%s\0%d\n' % (store.encodedir(name), size)
             if size <= 65536:
                 fp = svfs(name)
                 try:
                     data = fp.read(size)
                 finally:
                     fp.close()
                 yield data
             else:
                 for chunk in util.filechunkiter(svfs(name), limit=size):
                     yield chunk
     finally:
         svfs.mustaudit = oldaudit