reviewboard: avoid devel warning in Mercurial 4.3 (bug 1413628); r?glob draft
authorGregory Szorc <gps@mozilla.com>
Thu, 02 Nov 2017 10:07:51 -0700
changeset 11779 a7465f6a6091cca6e44c9ad354c33749531fd0d5
parent 11778 b7562c0562df9d9f49778d3441da5afffd400a84
child 11780 2dbcfe4f0ee4e956cfc35a3ad2973297a0e6aa3f
push id1816
push usergszorc@mozilla.com
push dateThu, 02 Nov 2017 19:46:54 +0000
reviewersglob
bugs1413628
reviewboard: avoid devel warning in Mercurial 4.3 (bug 1413628); r?glob Mercurial 4.3+ will issue a devel warning if you pass a default argument to look up the config value of an option with a static default value. There doesn't appear to be a good way to suppress the warning in code aside from not passing the default argument. So we change the code. MozReview-Commit-ID: 9RbEMrq7IMZ
hgext/reviewboard/server.py
--- a/hgext/reviewboard/server.py
+++ b/hgext/reviewboard/server.py
@@ -61,16 +61,24 @@ cmdtable = {}
 
 # Mercurial 4.3 introduced registrar.command as a replacement for
 # cmdutil.command.
 if util.safehasattr(registrar, 'command'):
     command = registrar.command(cmdtable)
 else:
     command = cmdutil.command(cmdtable)
 
+# Mercurial 4.3 started defining config items using a central registrar.
+# Mercurial 4.4 finished this transition.
+try:
+    from mercurial import configitems
+    have_config_registrar = True
+except ImportError:
+    have_config_registrar = False
+
 # Capabilities the server requires in clients.
 #
 # Add to this and add a corresponding entry in the client extension to force
 # the client to pull latest code.
 requirecaps = set([
     # Client can speak protocol format 1.
     'proto1',
     # Client knows how to interpret lists in review data.
@@ -391,17 +399,23 @@ def reposetup(ui, repo):
     if not ui.config('reviewboard', 'password', None):
         raise util.Abort(_('Please set reviewboard.password to the password '
             'for priveleged communications with Review Board.'))
 
     if not ui.config('bugzilla', 'url', None):
         raise util.Abort(_('Please set bugzilla.url to the URL of the '
             'Bugzilla instance to talk to.'))
 
-    if ui.configbool('phases', 'publish', True):
+    # TRACKING hg33+
+    if have_config_registrar:
+        publish = ui.configbool('phases', 'publish')
+    else:
+        publish = ui.configbool('phases', 'publish', True)
+
+    if publish:
         raise util.Abort(_('reviewboard server extension is only compatible '
             'with non-publishing repositories.'))
 
     ui.setconfig('hooks', 'changegroup.reviewboard', changegrouphook)
 
     # This shouldn't be needed to prevent pushes, as the "heads" wireproto
     # wrapping should kill them. However, this is defense in depth and will
     # kill all changegroup additions, even if the server operator is dumb.