mercurial/wireproto.py
changeset 21069 0a9cae236738
parent 21064 4d9d490d7bbe
child 21072 0879352d67d8
equal deleted inserted replaced
21068:c15b66a6bbb4 21069:0a9cae236738
     6 # GNU General Public License version 2 or any later version.
     6 # GNU General Public License version 2 or any later version.
     7 
     7 
     8 import urllib, tempfile, os, sys
     8 import urllib, tempfile, os, sys
     9 from i18n import _
     9 from i18n import _
    10 from node import bin, hex
    10 from node import bin, hex
    11 import changegroup as changegroupmod
    11 import changegroup as changegroupmod, bundle2
    12 import peer, error, encoding, util, store, exchange
    12 import peer, error, encoding, util, store, exchange
    13 
    13 
    14 
    14 
    15 class abstractserverproto(object):
    15 class abstractserverproto(object):
    16     """abstract class that summarizes the protocol API
    16     """abstract class that summarizes the protocol API
   333         if common is not None:
   333         if common is not None:
   334             opts['common'] = encodelist(common)
   334             opts['common'] = encodelist(common)
   335         if bundlecaps is not None:
   335         if bundlecaps is not None:
   336             opts['bundlecaps'] = ','.join(bundlecaps)
   336             opts['bundlecaps'] = ','.join(bundlecaps)
   337         f = self._callcompressable("getbundle", **opts)
   337         f = self._callcompressable("getbundle", **opts)
   338         return changegroupmod.unbundle10(f, 'UN')
   338         if bundlecaps is not None and 'HG20' in bundlecaps:
       
   339             return bundle2.unbundle20(self.ui, f)
       
   340         else:
       
   341             return changegroupmod.unbundle10(f, 'UN')
   339 
   342 
   340     def unbundle(self, cg, heads, source):
   343     def unbundle(self, cg, heads, source):
   341         '''Send cg (a readable file-like object representing the
   344         '''Send cg (a readable file-like object representing the
   342         changegroup to push, typically a chunkbuffer object) to the
   345         changegroup to push, typically a chunkbuffer object) to the
   343         remote server as a bundle. Return an integer indicating the
   346         remote server as a bundle. Return an integer indicating the
   563         if not requiredformats - set(('revlogv1',)):
   566         if not requiredformats - set(('revlogv1',)):
   564             caps.append('stream')
   567             caps.append('stream')
   565         # otherwise, add 'streamreqs' detailing our local revlog format
   568         # otherwise, add 'streamreqs' detailing our local revlog format
   566         else:
   569         else:
   567             caps.append('streamreqs=%s' % ','.join(requiredformats))
   570             caps.append('streamreqs=%s' % ','.join(requiredformats))
       
   571     if repo.ui.configbool('server', 'bundle2', False):
       
   572         caps.append('bundle2')
   568     caps.append('unbundle=%s' % ','.join(changegroupmod.bundlepriority))
   573     caps.append('unbundle=%s' % ','.join(changegroupmod.bundlepriority))
   569     caps.append('httpheader=1024')
   574     caps.append('httpheader=1024')
   570     return caps
   575     return caps
   571 
   576 
   572 # If you are writing an extension and consider wrapping this function. Wrap
   577 # If you are writing an extension and consider wrapping this function. Wrap
   600     for k, v in opts.iteritems():
   605     for k, v in opts.iteritems():
   601         if k in ('heads', 'common'):
   606         if k in ('heads', 'common'):
   602             opts[k] = decodelist(v)
   607             opts[k] = decodelist(v)
   603         elif k == 'bundlecaps':
   608         elif k == 'bundlecaps':
   604             opts[k] = set(v.split(','))
   609             opts[k] = set(v.split(','))
   605     cg = changegroupmod.getbundle(repo, 'serve', **opts)
   610     cg = exchange.getbundle(repo, 'serve', **opts)
   606     return streamres(proto.groupchunks(cg))
   611     return streamres(proto.groupchunks(cg))
   607 
   612 
   608 @wireprotocommand('heads')
   613 @wireprotocommand('heads')
   609 def heads(repo, proto):
   614 def heads(repo, proto):
   610     h = repo.heads()
   615     h = repo.heads()