Update the Mercurial hgweb support for Python 3.x and Review Board 4.0.

Review Request #10931 — Created March 2, 2020 and submitted

Information

Review Board
release-4.0.x

Reviewers

The Mercurial hgweb backend had a couple of compatibility problems that
prevented it from working on Python 3 and Review Board 4.0. It was
trying to parse JSON payloads in the form of byte strings, which is not
supported on Python 3. Instead, we needed to ensure we were providing
Unicode strings. A handy new _get_http_json() method now does the work
of ensuring we're using the correct types.

When building commits, it was still passing a base_commit_id=
parameter to the Commit constructor, which has been removed in
Review Board 4.0. This was missed before due to the lack of unit tests
for the hgweb support.

Since we now have a _get_http_json() method that handles JSON API
requests in a more standardized way, we're also in a better position to
future-proof by checking if endpoints are implemented (comparing a payload
to b'not yet implemented') and then returning None. This ensures
we don't break with older versions of Mercurial now, and that going
forward we can introduce support for newer APIs without outright breaking
on version that lack them.

To ensure we have working compatibility now and in the future, this
change also adds unit tests that cover the hgweb communication.

Manually tested loading branches and commits, posting a change for
review, and viewing a diff.

Unit tests pass on all supported versions of Python.

Summary ID
Update the Mercurial hgweb support for Python 3.x and Review Board 4.0.
The Mercurial hgweb backend had a couple of compatibility problems that prevented it from working on Python 3 and Review Board 4.0. It was trying to parse JSON payloads in the form of byte strings, which is not supported on Python 3. Instead, we needed to ensure we were providing Unicode strings. A handy new `_get_http_json()` method now does the work of ensuring we're using the correct types. When building commits, it was still passing a `base_commit_id=` parameter to the `Commit` constructor, which has been removed in Review Board 4.0. This was missed before due to the lack of unit tests for the hgweb support. To ensure we have working compatibility now and in the future, this change also adds unit tests that cover the hgweb communication.
7cab3e568d2e92e51968011a15f6e9c82e4f65a1
Description From Last Updated

did you try old Mercurial 3.9 and lower? looks like a Regression for this https://hellosplat.com/s/beanbag/tickets/4524/

miserymisery

F401 'datetime.datetime' imported but unused

reviewbotreviewbot
Checks run (1 failed, 1 succeeded)
flake8 failed.
JSHint passed.

flake8

chipx86
david
  1. Ship It!
  2. 
      
misery
  1. 
      
  2. Show all issues

    did you try old Mercurial 3.9 and lower?

    looks like a Regression for this

    https://hellosplat.com/s/beanbag/tickets/4524/

    1. There is a change in behavior with get_commits(), in that we're logging a "Cannot load commits from hgweb" before returning an empty list. I think that might actually be the preferred behavior, rather than just pretending it succeeded, but I can revert back to the previous logic (and I realize that I missed a test for it).

      Otherwise, not seeing any issues. Was that what you were noticing?

      All the get_file_http() calls we had before are just wrapped now to deserialize if we got a JSON response.

    2. I'm going to land this, since I'm not seeing anything that regresses 3.9 and this gets us past some Python compatibility problems, but please tell me if I've missed something important. I'll turn around another patch quickly.

  3. 
      
chipx86
chipx86
Review request changed
Status:
Completed
Change Summary:
Pushed to release-4.0.x (21795a3)