Patchwork [1,of,7,main-line-of-works,(28,more,patches,to,go)] ] bundle2: introduce a specific function for debug messages while unbundling

login
register
mail settings
Submitter Pierre-Yves David
Date May 28, 2015, 4:53 p.m.
Message ID <7672b85918fe945b6517.1432831992@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/9324/
State Accepted
Headers show

Comments

Pierre-Yves David - May 28, 2015, 4:53 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1432705732 25200
#      Tue May 26 22:48:52 2015 -0700
# Node ID 7672b85918fe945b6517afc83c38449d36e83df5
# Parent  df978afcfc43e474686dd195c4caa0a3e8fb0175
bundle2: introduce a specific function for debug messages while unbundling

The bundling process is very verbose, we would like to be able to hide such
output behind a configuration flag and have it more explicitly referencing
bundle2. The first step is to gather all these messages in a dedicated function.

Patch

diff --git a/mercurial/bundle2.py b/mercurial/bundle2.py
--- a/mercurial/bundle2.py
+++ b/mercurial/bundle2.py
@@ -175,10 +175,14 @@  preferedchunksize = 4096
 
 def outdebug(ui, message):
     """debug regarding output stream (bundling)"""
     ui.debug('bundle2-output: %s\n' % message)
 
+def indebug(ui, message):
+    """debug on input stream (unbundling)"""
+    ui.debug(message)
+
 def validateparttype(parttype):
     """raise ValueError if a parttype contains invalid character"""
     if _parttypeforbidden.search(parttype):
         raise ValueError(parttype)
 
@@ -344,21 +348,21 @@  def _processpart(op, part):
     try:
         try:
             handler = parthandlermapping.get(part.type)
             if handler is None:
                 raise error.UnsupportedPartError(parttype=part.type)
-            op.ui.debug('found a handler for part %r\n' % part.type)
+            indebug(op.ui, 'found a handler for part %r\n' % part.type)
             unknownparams = part.mandatorykeys - handler.params
             if unknownparams:
                 unknownparams = list(unknownparams)
                 unknownparams.sort()
                 raise error.UnsupportedPartError(parttype=part.type,
                                                params=unknownparams)
         except error.UnsupportedPartError, exc:
             if part.mandatory: # mandatory parts
                 raise
-            op.ui.debug('ignoring unsupported advisory part %s\n' % exc)
+            indebug(op.ui, 'ignoring unsupported advisory part %s\n' % exc)
             return # skip to part processing
 
         # handler is called outside the above try block so that we don't
         # risk catching KeyErrors from anything other than the
         # parthandlermapping lookup (any KeyError raised by handler()
@@ -557,11 +561,11 @@  def getunbundler(ui, fp, header=None):
         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)
+    indebug(ui, 'start processing of %s stream\n' % header)
     return unbundler
 
 class unbundle20(unpackermixin):
     """interpret a bundle2 stream
 
@@ -574,11 +578,11 @@  class unbundle20(unpackermixin):
         super(unbundle20, self).__init__(fp)
 
     @util.propertycache
     def params(self):
         """dictionary of stream level parameters"""
-        self.ui.debug('reading bundle2 stream parameters\n')
+        indebug(self.ui, 'reading bundle2 stream parameters\n')
         params = {}
         paramssize = self._unpack(_fstreamparamsize)[0]
         if paramssize < 0:
             raise error.BundleValueError('negative bundle param size: %i'
                                          % paramssize)
@@ -607,37 +611,37 @@  class unbundle20(unpackermixin):
         if name[0] not in string.letters:
             raise ValueError('non letter first character: %r' % name)
         # Some logic will be later added here to try to process the option for
         # a dict of known parameter.
         if name[0].islower():
-            self.ui.debug("ignoring unknown parameter %r\n" % name)
+            indebug(self.ui, "ignoring unknown parameter %r\n" % name)
         else:
             raise error.UnsupportedPartError(params=(name,))
 
 
     def iterparts(self):
         """yield all parts contained in the stream"""
         # make sure param have been loaded
         self.params
-        self.ui.debug('start extraction of bundle2 parts\n')
+        indebug(self.ui, 'start extraction of bundle2 parts\n')
         headerblock = self._readpartheader()
         while headerblock is not None:
             part = unbundlepart(self.ui, headerblock, self._fp)
             yield part
             part.seek(0, 2)
             headerblock = self._readpartheader()
-        self.ui.debug('end of bundle2 stream\n')
+        indebug(self.ui, 'end of bundle2 stream\n')
 
     def _readpartheader(self):
         """reads a part header size and return the bytes blob
 
         returns None if empty"""
         headersize = self._unpack(_fpartheadersize)[0]
         if headersize < 0:
             raise error.BundleValueError('negative part header size: %i'
                                          % headersize)
-        self.ui.debug('part header size: %i\n' % headersize)
+        indebug(self.ui, 'part header size: %i\n' % headersize)
         if headersize:
             return self._readexact(headersize)
         return None
 
     def compressed(self):
@@ -819,20 +823,20 @@  class interrupthandler(unpackermixin):
         returns None if empty"""
         headersize = self._unpack(_fpartheadersize)[0]
         if headersize < 0:
             raise error.BundleValueError('negative part header size: %i'
                                          % headersize)
-        self.ui.debug('part header size: %i\n' % headersize)
+        indebug(self.ui, 'part header size: %i\n' % headersize)
         if headersize:
             return self._readexact(headersize)
         return None
 
     def __call__(self):
-        self.ui.debug('bundle2 stream interruption, looking for a part.\n')
+        indebug(self.ui, 'bundle2 stream interruption, looking for a part.\n')
         headerblock = self._readpartheader()
         if headerblock is None:
-            self.ui.debug('no part found during interruption.\n')
+            indebug(self.ui, 'no part found during interruption.\n')
             return
         part = unbundlepart(self.ui, headerblock, self._fp)
         op = interruptoperation(self.ui)
         _processpart(op, part)
 
@@ -912,11 +916,11 @@  class unbundlepart(unpackermixin):
                    'Unknown chunk %d' % chunknum
             super(unbundlepart, self).seek(self._chunkindex[chunknum][1])
 
         pos = self._chunkindex[chunknum][0]
         payloadsize = self._unpack(_fpayloadsize)[0]
-        self.ui.debug('payload chunk size: %i\n' % payloadsize)
+        indebug(self.ui, 'payload chunk size: %i\n' % payloadsize)
         while payloadsize:
             if payloadsize == flaginterrupt:
                 # interruption detection, the handler will now read a
                 # single part and process it.
                 interrupthandler(self.ui, self._fp)()
@@ -930,11 +934,11 @@  class unbundlepart(unpackermixin):
                 if chunknum == len(self._chunkindex):
                     self._chunkindex.append((pos,
                                              super(unbundlepart, self).tell()))
                 yield result
             payloadsize = self._unpack(_fpayloadsize)[0]
-            self.ui.debug('payload chunk size: %i\n' % payloadsize)
+            indebug(self.ui, 'payload chunk size: %i\n' % payloadsize)
 
     def _findchunk(self, pos):
         '''for a given payload position, return a chunk number and offset'''
         for chunk, (ppos, fpos) in enumerate(self._chunkindex):
             if ppos == pos:
@@ -945,20 +949,20 @@  class unbundlepart(unpackermixin):
 
     def _readheader(self):
         """read the header and setup the object"""
         typesize = self._unpackheader(_fparttypesize)[0]
         self.type = self._fromheader(typesize)
-        self.ui.debug('part type: "%s"\n' % self.type)
+        indebug(self.ui, 'part type: "%s"\n' % self.type)
         self.id = self._unpackheader(_fpartid)[0]
-        self.ui.debug('part id: "%s"\n' % self.id)
+        indebug(self.ui, 'part id: "%s"\n' % self.id)
         # extract mandatory bit from type
         self.mandatory = (self.type != self.type.lower())
         self.type = self.type.lower()
         ## reading parameters
         # param count
         mancount, advcount = self._unpackheader(_fpartparamcount)
-        self.ui.debug('part parameters: %i\n' % (mancount + advcount))
+        indebug(self.ui, 'part parameters: %i\n' % (mancount + advcount))
         # param size
         fparamsizes = _makefpartparamsizes(mancount + advcount)
         paramsizes = self._unpackheader(fparamsizes)
         # make it a list of couple again
         paramsizes = zip(paramsizes[::2], paramsizes[1::2])