Patchwork D2214: httppeer: change logic around argument handling

login
register
mail settings
Submitter phabricator
Date Feb. 13, 2018, 3:48 a.m.
Message ID <differential-rev-PHID-DREV-wzzgln72xmcykrafxwgf-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/27794/
State Superseded
Headers show

Comments

phabricator - Feb. 13, 2018, 3:48 a.m.
indygreg created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  The code to process arguments only makes sense if there are
  arguments. So change an "else" to "elif args", remove an
  "if" that isn't necessary, and add some docs for good measure.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  mercurial/httppeer.py

CHANGE DETAILS




To: indygreg, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/mercurial/httppeer.py b/mercurial/httppeer.py
--- a/mercurial/httppeer.py
+++ b/mercurial/httppeer.py
@@ -252,6 +252,8 @@ 
         # with infinite recursion when trying to look up capabilities
         # for the first time.
         postargsok = self._caps is not None and 'httppostargs' in self._caps
+
+        # Send arguments via POST.
         if postargsok and args:
             strargs = urlreq.urlencode(sorted(args.items()))
             if not data:
@@ -265,20 +267,27 @@ 
                 argsio.length = len(strargs)
                 data = _multifile(argsio, data)
             headers[r'X-HgArgs-Post'] = len(strargs)
-        else:
-            if len(args) > 0:
-                httpheader = self.capable('httpheader')
-                if httpheader:
-                    headersize = int(httpheader.split(',', 1)[0])
+        elif args:
+            # Calling self.capable() can infinite loop if we are calling
+            # "capabilities". But that command should never accept wire
+            # protocol arguments. So this should never happen.
+            assert cmd != 'capabilities'
+            httpheader = self.capable('httpheader')
+            if httpheader:
+                headersize = int(httpheader.split(',', 1)[0])
+
+            # Send arguments via HTTP headers.
             if headersize > 0:
                 # The headers can typically carry more data than the URL.
                 encargs = urlreq.urlencode(sorted(args.items()))
                 for header, value in encodevalueinheaders(encargs, 'X-HgArg',
                                                           headersize):
                     headers[header] = value
                     varyheaders.append(header)
+            # Send arguments via query string (Mercurial <1.9).
             else:
                 q += sorted(args.items())
+
         qs = '?%s' % urlreq.urlencode(q)
         cu = "%s%s" % (self._url, qs)
         size = 0