D7055: phabricator: update hgmatcher to cope with the new data format
Closed by commit rHGa124b79a3a7e: phabricator: update hgmatcher to cope with the new data format (authored by Kwan). This revision was automatically updated to reflect the committed changes. This revision was not accepted when it landed; it landed in state "Needs Review". REPOSITORY rHG Mercurial CHANGES SINCE LAST UPDATE https://phab.mercurial-scm.org/D7055?vs=17105=17259 CHANGES SINCE LAST ACTION https://phab.mercurial-scm.org/D7055/new/ REVISION DETAIL https://phab.mercurial-scm.org/D7055 AFFECTED FILES hgext/phabricator.py CHANGE DETAILS diff --git a/hgext/phabricator.py b/hgext/phabricator.py --- a/hgext/phabricator.py +++ b/hgext/phabricator.py @@ -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( To: Kwan, #hg-reviewers Cc: durin42, mercurial-devel ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
D7055: phabricator: update hgmatcher to cope with the new data format
durin42 added inline comments. INLINE COMMENTS > Kwan wrote in phabricator.py:155-156 > These will need converting to unicode first for py3.5 (I keep forgetting > about loads only accepting bytes from 3.6 onwards). That might be a nudge towards dropping 3.5 support. We've already got problems on 3.5. :( REPOSITORY rHG Mercurial CHANGES SINCE LAST ACTION https://phab.mercurial-scm.org/D7055/new/ REVISION DETAIL https://phab.mercurial-scm.org/D7055 To: Kwan, #hg-reviewers Cc: durin42, mercurial-devel ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
D7055: phabricator: update hgmatcher to cope with the new data format
Kwan added inline comments. INLINE COMMENTS > phabricator.py:155-156 > +if value.startswith(b'{') and value.endswith(b'}'): > +r1json = json.loads(value) > +r2json = json.loads(r2params[key][0]) > +if r1json != r2json: These will need converting to unicode first for py3.5 (I keep forgetting about loads only accepting bytes from 3.6 onwards). REPOSITORY rHG Mercurial CHANGES SINCE LAST ACTION https://phab.mercurial-scm.org/D7055/new/ REVISION DETAIL https://phab.mercurial-scm.org/D7055 To: Kwan, #hg-reviewers Cc: mercurial-devel ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
D7055: phabricator: update hgmatcher to cope with the new data format
Kwan added a comment. Kwan updated this revision to Diff 17105. I'd missed out the attrs key conversion needed on py3. REPOSITORY rHG Mercurial CHANGES SINCE LAST UPDATE https://phab.mercurial-scm.org/D7055?vs=17085=17105 BRANCH default CHANGES SINCE LAST ACTION https://phab.mercurial-scm.org/D7055/new/ REVISION DETAIL https://phab.mercurial-scm.org/D7055 AFFECTED FILES hgext/phabricator.py CHANGE DETAILS diff --git a/hgext/phabricator.py b/hgext/phabricator.py --- a/hgext/phabricator.py +++ b/hgext/phabricator.py @@ -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( To: Kwan, #hg-reviewers Cc: mercurial-devel ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
D7055: phabricator: update hgmatcher to cope with the new data format
Kwan added a comment. Kwan updated this revision to Diff 17085. Fix some test-check-code issues, and one test-check-pyflakes unused local. REPOSITORY rHG Mercurial CHANGES SINCE LAST UPDATE https://phab.mercurial-scm.org/D7055?vs=17061=17085 BRANCH default CHANGES SINCE LAST ACTION https://phab.mercurial-scm.org/D7055/new/ REVISION DETAIL https://phab.mercurial-scm.org/D7055 AFFECTED FILES hgext/phabricator.py CHANGE DETAILS diff --git a/hgext/phabricator.py b/hgext/phabricator.py --- a/hgext/phabricator.py +++ b/hgext/phabricator.py @@ -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( To: Kwan, #hg-reviewers Cc: mercurial-devel ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
D7055: phabricator: update hgmatcher to cope with the new data format
Kwan created this revision. Herald added a subscriber: mercurial-devel. Herald added a reviewer: hg-reviewers. REVISION SUMMARY 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. REPOSITORY rHG Mercurial BRANCH default REVISION DETAIL https://phab.mercurial-scm.org/D7055 AFFECTED FILES hgext/phabricator.py CHANGE DETAILS diff --git a/hgext/phabricator.py b/hgext/phabricator.py --- a/hgext/phabricator.py +++ b/hgext/phabricator.py @@ -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( To: Kwan, #hg-reviewers Cc: mercurial-devel ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel