reviewboard: support calling showlist() with Mercurial 4.2 (bug 1385979); r?glob draft
authorGregory Szorc <gps@mozilla.com>
Mon, 31 Jul 2017 16:32:13 -0700
changeset 11430 248f4187095ae4b268c258989ef612963c628d39
parent 11429 500f518b05bd5c1061291e47d5d313e6df21db00
child 11431 93ab4833b1e4b2c7376ce90816e206dd2b2bd058
push id1746
push userbmo:gps@mozilla.com
push dateThu, 03 Aug 2017 02:22:07 +0000
reviewersglob
bugs1385979
reviewboard: support calling showlist() with Mercurial 4.2 (bug 1385979); r?glob The prototype of templatekw.showlist() changed in Mercurial 4.2. While I normally try to call one form and fall back on TypeError, the use of **kwargs in the old form makes this difficult. So we use inspect.getargspec() to see what arguments it expects. MozReview-Commit-ID: 88pZtlA1jXl
hgext/reviewboard/client.py
--- a/hgext/reviewboard/client.py
+++ b/hgext/reviewboard/client.py
@@ -17,22 +17,22 @@ This extension adds new options to the `
     testing or ensuring certain commits are present on the remote.
   * --reviewid The review identifier to use. Pushes using the same
     review ID will overwrite existing reviews for that ID.
   * -c Single changeset to review.
 """
 
 import contextlib
 import errno
+import inspect
 import json
 import os
 import re
 import sys
 import urllib
-import urllib2
 
 from mercurial import (
     cmdutil,
     commands,
     context,
     demandimport,
     encoding,
     error,
@@ -41,17 +41,16 @@ from mercurial import (
     hg,
     httppeer,
     localrepo,
     obsolete,
     phases,
     scmutil,
     sshpeer,
     templatekw,
-    url as urlmod,
     util,
 )
 from mercurial.i18n import _
 from mercurial.node import bin, hex
 
 OUR_DIR = os.path.normpath(os.path.dirname(__file__))
 execfile(os.path.join(OUR_DIR, '..', 'bootstrap.py'))
 
@@ -980,17 +979,23 @@ def template_reviews(repo, ctx, revcache
             r = repo.reviews.getreviewrequest(rid)
             # Bug 1065022 add parent review info to this data structure.
             reviews.append({
                 'url': repo.reviews.reviewurl(rid),
                 'status': r.get('status'),
             })
 
         revcache['reviews'] = reviews
-    return templatekw.showlist('review', revcache['reviews'])
+
+    # Mercurial 4.2+ take mapping as a positional argument. Older versions
+    # take mapping as **kwargs.
+    if 'mapping' in inspect.getargspec(templatekw.showlist).args:
+       return templatekw.showlist('review', revcache['reviews'], {})
+    else:
+        return templatekw.showlist('review', revcache['reviews'])
 
 @command('fetchreviews', [], _('hg fetchreviews'))
 def fetchreviews(ui, repo, **opts):
     """Fetch information about your active code reviews.
 
     When you initiate a code review by pushing to a review-enabled remote,
     your repository will track the existence of that code review.