changeset 43264:a4da1c3b82ab

phabricator: update hgmatcher to cope with the new data format The new conduit format can't be matched by the existing matcher since it shifts all the data into an urlencoded string of JSON, the order of which isn't stable between runs. Instead detect JSON values of params and load them into python dicts, which python will then naturally deep-equal compare. Differential Revision: https://phab.mercurial-scm.org/D7055
author Ian Moody <moz-ian@perix.co.uk>
date Thu, 10 Oct 2019 22:11:39 +0100
parents 06a33a501aa2
children 82879e06c926
files hgext/phabricator.py
diffstat 1 files changed, 15 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/phabricator.py	Thu Oct 10 22:05:28 2019 +0100
+++ b/hgext/phabricator.py	Thu Oct 10 22:11:39 2019 +0100
@@ -144,9 +144,21 @@
     def hgmatcher(r1, r2):
         if r1.uri != r2.uri or r1.method != r2.method:
             return False
-        r1params = r1.body.split(b'&')
-        r2params = r2.body.split(b'&')
-        return set(r1params) == set(r2params)
+        r1params = util.urlreq.parseqs(r1.body)
+        r2params = util.urlreq.parseqs(r2.body)
+        for key in r1params:
+            if key not in r2params:
+                return False
+            value = r1params[key][0]
+            # we want to compare json payloads without worrying about ordering
+            if value.startswith(b'{') and value.endswith(b'}'):
+                r1json = json.loads(value)
+                r2json = json.loads(r2params[key][0])
+                if r1json != r2json:
+                    return False
+            elif r2params[key][0] != value:
+                return False
+        return True
 
     def sanitiserequest(request):
         request.body = re.sub(