Automatically Redirecting Mercurial Pushes
April 30, 2015 at 12:30 PM | categories: Mercurial, MozillaManaging URLs in distributed version control tools can be a pain, especially if multiple repositories are involved. For example, with Mozilla's repository-based code review workflow (you push to a special review repository to initiate code review - this is conceptually similar to GitHub pull requests), there exist separate code review repositories for each logical repository. Figuring out how repositories map to each other and setting up remote paths for each new clone can be a pain and time sink.
As of today, we can now do something better.
If you push to ssh://reviewboard-hg.mozilla.org/autoreview, Mercurial will automatically figure out the appropriate review repository and redirect your push automatically. In other words, if we have MozReview set up to review whatever repository you are working on, your push and review request will automatically go through. No need to figure out what the appropriate review repo is or configure repository URLs!
Here's what it looks like:
$ hg push review pushing to ssh://reviewboard-hg.mozilla.org/autoreview searching for appropriate review repository redirecting push to ssh://reviewboard-hg.mozilla.org/version-control-tools/ searching for changes remote: adding changesets remote: adding manifests remote: adding file changes remote: added 1 changesets with 1 changes to 1 files remote: Trying to insert into pushlog. remote: Inserted into the pushlog db successfully. submitting 1 changesets for review changeset: 11043:b65b087a81be summary: mozreview: create per-commit identifiers (bug 1160266) review: https://reviewboard.mozilla.org/r/7953 (draft) review id: bz://1160266/gps review url: https://reviewboard.mozilla.org/r/7951 (draft) (visit review url to publish this review request so others can see it)
Read the full instructions for more details.
This requires an updated version-control-tools repository, which you can get by running mach mercurial-setup from a Firefox repository.
For those that are curious, the autoreview repo/server advertises a list of repository URLs and their root commit SHA-1. The client automatically sends the push to a URL sharing the same root commit. The code is quite simple.
While this is only implemented for MozReview, I could envision us doing something similar for other centralized repository-centric services, such as Try and Autoland. Stay tuned.