def readbundle(ui, fh, fname, vfs=None): header = changegroup.readexactly(fh, 4) alg = None if not fname: fname = "stream" if not header.startswith('HG') and header.startswith('\0'): fh = changegroup.headerlessfixup(fh, header) header = "HG10" alg = 'UN' elif vfs: fname = vfs.join(fname) magic, version = header[0:2], header[2:4] if magic != 'HG': raise util.Abort(_('%s: not a Mercurial bundle') % fname) if version == '10': if alg is None: alg = changegroup.readexactly(fh, 2) return changegroup.cg1unpacker(fh, alg) elif version == '2Y': return bundle2.unbundle20(ui, fh, header=magic + version) else: raise util.Abort(_('%s: unknown bundle version %s') % (fname, version))
def readbundle(ui, fh, fname, vfs=None): header = changegroup.readexactly(fh, 4) alg = None if not fname: fname = "stream" if not header.startswith('HG') and header.startswith('\0'): fh = changegroup.headerlessfixup(fh, header) header = "HG10" alg = 'UN' elif vfs: fname = vfs.join(fname) magic, version = header[0:2], header[2:4] if magic != 'HG': raise util.Abort(_('%s: not a Mercurial bundle') % fname) if version == '10': if alg is None: alg = changegroup.readexactly(fh, 2) return changegroup.unbundle10(fh, alg) elif version == '2X': return bundle2.unbundle20(ui, fh, header=magic + version) else: raise util.Abort(_('%s: unknown bundle version %s') % (fname, version))
def getunbundler(ui, fp, header=None): """return a valid unbundler object for a given header""" if header is None: header = changegroup.readexactly(fp, 4) magic, version = header[0:2], header[2:4] if magic != 'HG': raise util.Abort(_('not a Mercurial bundle')) unbundlerclass = formatmap.get(version) if unbundlerclass is None: raise util.Abort(_('unknown bundle version %s') % version) unbundler = unbundlerclass(ui, fp) ui.debug('start processing of %s stream\n' % header) return unbundler
def _readexact(self, size): """read exactly <size> bytes from the stream""" return changegroup.readexactly(self._fp, size)