Esempio n. 1
0
    def unbundle(self, cg, heads, source):
        '''Send cg (a readable file-like object representing the
        changegroup to push, typically a chunkbuffer object) to the
        remote server as a bundle.

        When pushing a bundle10 stream, return an integer indicating the
        result of the push (see localrepository.addchangegroup()).

        When pushing a bundle20 stream, return a bundle20 stream.'''

        if heads != ['force'] and self.capable('unbundlehash'):
            heads = encodelist(['hashed',
                                util.sha1(''.join(sorted(heads))).digest()])
        else:
            heads = encodelist(heads)

        if util.safehasattr(cg, 'deltaheader'):
            # this a bundle10, do the old style call sequence
            ret, output = self._callpush("unbundle", cg, heads=heads)
            if ret == "":
                raise error.ResponseError(
                    _('push failed:'), output)
            try:
                ret = int(ret)
            except ValueError:
                raise error.ResponseError(
                    _('push failed (unexpected response):'), ret)

            for l in output.splitlines(True):
                self.ui.status(_('remote: '), l)
        else:
            # bundle2 push. Send a stream, fetch a stream.
            stream = self._calltwowaystream('unbundle', cg, heads=heads)
            ret = bundle2.unbundle20(self.ui, stream)
        return ret
Esempio n. 2
0
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))
Esempio n. 3
0
 def getbundle(self, source, **kwargs):
     self.requirecap('getbundle', _('look up remote changes'))
     opts = {}
     for key, value in kwargs.iteritems():
         if value is None:
             continue
         keytype = gboptsmap.get(key)
         if keytype is None:
             assert False, 'unexpected'
         elif keytype == 'nodes':
             value = encodelist(value)
         elif keytype == 'csv':
             value = ','.join(value)
         elif keytype == 'boolean':
             value = '%i' % bool(value)
         elif keytype != 'plain':
             raise KeyError('unknown getbundle option type %s'
                            % keytype)
         opts[key] = value
     f = self._callcompressable("getbundle", **opts)
     bundlecaps = kwargs.get('bundlecaps')
     if bundlecaps is not None and 'HG2Y' in bundlecaps:
         return bundle2.unbundle20(self.ui, f)
     else:
         return changegroupmod.cg1unpacker(f, 'UN')
Esempio n. 4
0
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))
Esempio n. 5
0
 def getbundle(self, source, heads=None, common=None, bundlecaps=None,
               **kwargs):
     self.requirecap('getbundle', _('look up remote changes'))
     opts = {}
     if heads is not None:
         opts['heads'] = encodelist(heads)
     if common is not None:
         opts['common'] = encodelist(common)
     if bundlecaps is not None:
         opts['bundlecaps'] = ','.join(bundlecaps)
     opts.update(kwargs)
     f = self._callcompressable("getbundle", **opts)
     if bundlecaps is not None and 'HG2X' in bundlecaps:
         return bundle2.unbundle20(self.ui, f)
     else:
         return changegroupmod.unbundle10(f, 'UN')
Esempio n. 6
0
 def getbundle(self,
               source,
               heads=None,
               common=None,
               bundlecaps=None,
               **kwargs):
     self.requirecap('getbundle', _('look up remote changes'))
     opts = {}
     if heads is not None:
         opts['heads'] = encodelist(heads)
     if common is not None:
         opts['common'] = encodelist(common)
     if bundlecaps is not None:
         opts['bundlecaps'] = ','.join(bundlecaps)
     opts.update(kwargs)
     f = self._callcompressable("getbundle", **opts)
     if bundlecaps is not None and 'HG2X' in bundlecaps:
         return bundle2.unbundle20(self.ui, f)
     else:
         return changegroupmod.unbundle10(f, 'UN')
Esempio n. 7
0
 def getbundle(self, source, **kwargs):
     self.requirecap("getbundle", _("look up remote changes"))
     opts = {}
     for key, value in kwargs.iteritems():
         if value is None:
             continue
         keytype = gboptsmap.get(key)
         if keytype is None:
             assert False, "unexpected"
         elif keytype == "nodes":
             value = encodelist(value)
         elif keytype == "csv":
             value = ",".join(value)
         elif keytype == "boolean":
             value = "%i" % bool(value)
         elif keytype != "plain":
             raise KeyError("unknown getbundle option type %s" % keytype)
         opts[key] = value
     f = self._callcompressable("getbundle", **opts)
     bundlecaps = kwargs.get("bundlecaps")
     if bundlecaps is not None and "HG2Y" in bundlecaps:
         return bundle2.unbundle20(self.ui, f)
     else:
         return changegroupmod.cg1unpacker(f, "UN")