def streamer(repo, entries, total): '''stream out all metadata files in repository.''' yield '0\n' # success repo.ui.debug('%d files, %d bytes to transfer\n' % (len(entries), total_bytes)) yield '%d %d\n' % (len(entries), total_bytes) sopener = repo.sopener 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 # replace with "finally:" when support for python 2.4 has been dropped except Exception: sopener.mustaudit = oldaudit raise sopener.mustaudit = oldaudit
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
def zgenerator(f): zd = zlib.decompressobj() try: for chunk in util.filechunkiter(f): yield zd.decompress(chunk) except httplib.HTTPException, inst: raise IOError(None, _('connection ended unexpectedly'))
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
def __init__(self, ui, path, bundlename): self._tempparent = None try: localrepo.localrepository.__init__(self, ui, path) except error.RepoError: self._tempparent = tempfile.mkdtemp() localrepo.instance(ui, self._tempparent, 1) localrepo.localrepository.__init__(self, ui, self._tempparent) if path: self._url = 'bundle:' + path + '+' + bundlename else: self._url = 'bundle:' + bundlename self.tempfile = None self.bundlefile = open(bundlename, "rb") header = self.bundlefile.read(6) if not header.startswith("HG"): raise util.Abort(_("%s: not a Mercurial bundle file") % bundlename) elif not header.startswith("HG10"): raise util.Abort(_("%s: unknown bundle version") % bundlename) elif (header == "HG10BZ") or (header == "HG10GZ"): fdtemp, temp = tempfile.mkstemp(prefix="hg-bundle-", suffix=".hg10un", dir=self.path) self.tempfile = temp fptemp = os.fdopen(fdtemp, 'wb') def generator(f): if header == "HG10BZ": zd = bz2.BZ2Decompressor() zd.decompress("BZ") elif header == "HG10GZ": zd = zlib.decompressobj() for chunk in f: yield zd.decompress(chunk) gen = generator(util.filechunkiter(self.bundlefile, 4096)) try: fptemp.write("HG10UN") for chunk in gen: fptemp.write(chunk) finally: fptemp.close() self.bundlefile.close() self.bundlefile = open(self.tempfile, "rb") # seek right after the header self.bundlefile.seek(6) elif header == "HG10UN": # nothing to do pass else: raise util.Abort( _("%s: unknown bundle compression type") % bundlename) # dict with the mapping 'filename' -> position in the bundle self.bundlefilespos = {}
def _sendfile(self, data): # send a file if isinstance(data, httpsendfile): # if auth required, some data sent twice, so rewind here data.seek(0) for chunk in util.filechunkiter(data): connection.send(self, chunk) else: connection.send(self, data)
def _sendfile(self, data): # send a file if isinstance(data, httpconnectionmod.httpsendfile): # if auth required, some data sent twice, so rewind here data.seek(0) for chunk in util.filechunkiter(data): orgsend(self, chunk) else: orgsend(self, data)
def zgenerator(f): zd = zlib.decompressobj() try: for chunk in util.filechunkiter(f): while chunk: yield zd.decompress(chunk, 2**18) chunk = zd.unconsumed_tail except httplib.HTTPException: raise IOError(None, _('connection ended unexpectedly')) yield zd.flush()
def __init__(self, ui, path, bundlename): self._tempparent = None try: localrepo.localrepository.__init__(self, ui, path) except error.RepoError: self._tempparent = tempfile.mkdtemp() localrepo.instance(ui, self._tempparent, 1) localrepo.localrepository.__init__(self, ui, self._tempparent) if path: self._url = 'bundle:' + path + '+' + bundlename else: self._url = 'bundle:' + bundlename self.tempfile = None self.bundlefile = open(bundlename, "rb") header = self.bundlefile.read(6) if not header.startswith("HG"): raise util.Abort(_("%s: not a Mercurial bundle file") % bundlename) elif not header.startswith("HG10"): raise util.Abort(_("%s: unknown bundle version") % bundlename) elif (header == "HG10BZ") or (header == "HG10GZ"): fdtemp, temp = tempfile.mkstemp(prefix="hg-bundle-", suffix=".hg10un", dir=self.path) self.tempfile = temp fptemp = os.fdopen(fdtemp, 'wb') def generator(f): if header == "HG10BZ": zd = bz2.BZ2Decompressor() zd.decompress("BZ") elif header == "HG10GZ": zd = zlib.decompressobj() for chunk in f: yield zd.decompress(chunk) gen = generator(util.filechunkiter(self.bundlefile, 4096)) try: fptemp.write("HG10UN") for chunk in gen: fptemp.write(chunk) finally: fptemp.close() self.bundlefile.close() self.bundlefile = open(self.tempfile, "rb") # seek right after the header self.bundlefile.seek(6) elif header == "HG10UN": # nothing to do pass else: raise util.Abort(_("%s: unknown bundle compression type") % bundlename) # dict with the mapping 'filename' -> position in the bundle self.bundlefilespos = {}
def streamer(repo, entries, total): """stream out all metadata files in repository.""" yield "0\n" # success 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)) # partially encode name over the wire for backwards compat yield "%s\0%d\n" % (store.encodedir(name), size) for chunk in util.filechunkiter(repo.sopener(name), limit=size): yield chunk
def streamer(repo, entries, total): '''stream out all metadata files in repository.''' yield '0\n' # success 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)) # partially encode name over the wire for backwards compat yield '%s\0%d\n' % (store.encodedir(name), size) for chunk in util.filechunkiter(repo.sopener(name), limit=size): yield chunk
def generator(f): zd = bz2.BZ2Decompressor() zd.decompress("BZ") for chunk in util.filechunkiter(f, 4096): yield zd.decompress(chunk)
def generator(f): zd = zlib.decompressobj() for chunk in util.filechunkiter(f): yield zd.decompress(chunk)
repolock = None try: try: repolock = repo.lock() except (lock.LockHeld, lock.LockUnavailable), inst: repo.ui.warn('locking the repository failed: %s\n' % (inst,)) fileobj.write('2\n') return fileobj.write('0\n') repo.ui.debug('scanning\n') entries = [] total_bytes = 0 for name, size in walkrepo(repo.spath): name = repo.decodefn(util.pconvert(name)) entries.append((name, size)) total_bytes += size finally: del repolock repo.ui.debug('%d files, %d bytes to transfer\n' % (len(entries), total_bytes)) fileobj.write('%d %d\n' % (len(entries), total_bytes)) for name, size in entries: repo.ui.debug('sending %s (%d bytes)\n' % (name, size)) fileobj.write('%s\0%d\n' % (name, size)) for chunk in util.filechunkiter(repo.sopener(name), limit=size): fileobj.write(chunk) flush = getattr(fileobj, 'flush', None) if flush: flush()
repolock = None try: try: repolock = repo.lock() except (lock.LockHeld, lock.LockUnavailable), inst: repo.ui.warn('locking the repository failed: %s\n' % (inst, )) fileobj.write('2\n') return fileobj.write('0\n') repo.ui.debug('scanning\n') entries = [] total_bytes = 0 for name, size in walkrepo(repo.spath): name = repo.decodefn(util.pconvert(name)) entries.append((name, size)) total_bytes += size finally: del repolock repo.ui.debug('%d files, %d bytes to transfer\n' % (len(entries), total_bytes)) fileobj.write('%d %d\n' % (len(entries), total_bytes)) for name, size in entries: repo.ui.debug('sending %s (%d bytes)\n' % (name, size)) fileobj.write('%s\0%d\n' % (name, size)) for chunk in util.filechunkiter(repo.sopener(name), limit=size): fileobj.write(chunk) flush = getattr(fileobj, 'flush', None) if flush: flush()