Patchwork [1,of,3] bundle20: move magic string into the class

login
register
mail settings
Submitter Pierre-Yves David
Date April 7, 2015, 6:30 a.m.
Message ID <3aea190962e2c2286d70.1428388252@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/8527/
State Accepted
Commit 685639f9430d407fbb3f35a09ca694c76bc10170
Headers show

Comments

Pierre-Yves David - April 7, 2015, 6:30 a.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1428360012 25200
#      Mon Apr 06 15:40:12 2015 -0700
# Node ID 3aea190962e2c2286d70a251b375957e1ab60c01
# Parent  7c6f9097e2e03be6630d782114ac312264f7333a
bundle20: move magic string into the class

This makes it easy to create new bundler class that inherit from the core one.
This match the way 'changegroup' packers work.

The main target is to allow HG2Y support in an extension to ease transition of
companies using the experimental protocol in production (yeah...) But I've no
doubt this will be useful when playing with a future HG21.

Patch

diff --git a/mercurial/bundle2.py b/mercurial/bundle2.py
--- a/mercurial/bundle2.py
+++ b/mercurial/bundle2.py
@@ -160,12 +160,10 @@  import changegroup, error
 from i18n import _
 
 _pack = struct.pack
 _unpack = struct.unpack
 
-_magicstring = 'HG2Y'
-
 _fstreamparamsize = '>i'
 _fpartheadersize = '>i'
 _fparttypesize = '>B'
 _fpartid = '>I'
 _fpayloadsize = '>i'
@@ -408,10 +406,12 @@  class bundle20(object):
 
     Use the `addparam` method to add stream level parameter. and `newpart` to
     populate it. Then call `getchunks` to retrieve all the binary chunks of
     data that compose the bundle2 container."""
 
+    _magicstring = 'HG2Y'
+
     def __init__(self, ui, capabilities=()):
         self.ui = ui
         self._params = []
         self._parts = []
         self.capabilities = dict(capabilities)
@@ -451,12 +451,12 @@  class bundle20(object):
         self.addpart(part)
         return part
 
     # methods used to generate the bundle2 stream
     def getchunks(self):
-        self.ui.debug('start emission of %s stream\n' % _magicstring)
-        yield _magicstring
+        self.ui.debug('start emission of %s stream\n' % self._magicstring)
+        yield self._magicstring
         param = self._paramchunk()
         self.ui.debug('bundle parameter: %s\n' % param)
         yield _pack(_fstreamparamsize, len(param))
         if param:
             yield param