This revision was automatically updated to reflect the committed changes.
Closed by commit rHGd715a85003c8: wireprotov2: establish a type for 
representing command response (authored by indygreg, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D3380?vs=8292&id=8323

REVISION DETAIL
  https://phab.mercurial-scm.org/D3380

AFFECTED FILES
  mercurial/debugcommands.py
  mercurial/wireprotov2peer.py

CHANGE DETAILS

diff --git a/mercurial/wireprotov2peer.py b/mercurial/wireprotov2peer.py
--- a/mercurial/wireprotov2peer.py
+++ b/mercurial/wireprotov2peer.py
@@ -17,6 +17,26 @@
     wireprotoframing,
 )
 
+class commandresponse(object):
+    """Represents the response to a command request."""
+
+    def __init__(self, requestid, command):
+        self.requestid = requestid
+        self.command = command
+
+        self.cbor = False
+        self.b = util.bytesio()
+
+    def cborobjects(self):
+        """Obtain decoded CBOR objects from this response."""
+        size = self.b.tell()
+        self.b.seek(0)
+
+        decoder = cbor.CBORDecoder(self.b)
+
+        while self.b.tell() < size:
+            yield decoder.decode()
+
 class clienthandler(object):
     """Object to handle higher-level client activities.
 
@@ -48,10 +68,7 @@
         rid = request.requestid
         self._requests[rid] = request
         self._futures[rid] = f
-        self._responses[rid] = {
-            'cbor': False,
-            'b': util.bytesio(),
-        }
+        self._responses[rid] = commandresponse(rid, command)
 
         return iter(())
 
@@ -104,28 +121,13 @@
         response = self._responses[frame.requestid]
 
         if action == 'responsedata':
-            response['b'].write(meta['data'])
+            response.b.write(meta['data'])
 
             if meta['cbor']:
-                response['cbor'] = True
+                response.cbor = True
 
             if meta['eos']:
-                if meta['cbor']:
-                    # If CBOR, decode every object.
-                    b = response['b']
-
-                    size = b.tell()
-                    b.seek(0)
-
-                    decoder = cbor.CBORDecoder(b)
-
-                    result = []
-                    while b.tell() < size:
-                        result.append(decoder.decode())
-                else:
-                    result = [response['b'].getvalue()]
-
-                self._futures[frame.requestid].set_result(result)
+                self._futures[frame.requestid].set_result(response)
 
                 del self._requests[frame.requestid]
                 del self._futures[frame.requestid]
diff --git a/mercurial/debugcommands.py b/mercurial/debugcommands.py
--- a/mercurial/debugcommands.py
+++ b/mercurial/debugcommands.py
@@ -83,6 +83,7 @@
     vfs as vfsmod,
     wireprotoframing,
     wireprotoserver,
+    wireprotov2peer,
 )
 from .utils import (
     dateutil,
@@ -3012,7 +3013,16 @@
                 with peer.commandexecutor() as e:
                     res = e.callcommand(command, args).result()
 
-                ui.status(_('response: %s\n') % stringutil.pprint(res))
+                if isinstance(res, wireprotov2peer.commandresponse):
+                    if res.cbor:
+                        val = list(res.cborobjects())
+                    else:
+                        val = [res.b.getvalue()]
+
+                    ui.status(_('response: %s\n') % stringutil.pprint(val))
+
+                else:
+                    ui.status(_('response: %s\n') % stringutil.pprint(res))
 
         elif action == 'batchbegin':
             if batchedcommands is not None:



To: indygreg, #hg-reviewers, durin42
Cc: mercurial-devel
_______________________________________________
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Reply via email to