changeset 109:023cbafe1425

7901950: jcheck does not work with Mercurial 4.1 Contributed-By: erik.joelsson@oracle.com Reviewed-By: magnus.ihse.bursie@oracle.com
author jjg
date Mon, 21 Aug 2017 14:51:04 -0700
parents e3de70180f79
children c7f1b4bf6908
files jcheck.py jcheck_test.py
diffstat 2 files changed, 51 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/jcheck.py	Mon May 22 12:53:12 2017 -0700
+++ b/jcheck.py	Mon Aug 21 14:51:04 2017 -0700
@@ -1,21 +1,21 @@
 #
-# Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
-# 
+#
 # This code is free software; you can redistribute it and/or modify it
 # under the terms of the GNU General Public License version 2 only, as
 # published by the Free Software Foundation.
-# 
+#
 # This code is distributed in the hope that it will be useful, but WITHOUT
 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 # version 2 for more details (a copy is included in the LICENSE file that
 # accompanied this code).
-# 
+#
 # You should have received a copy of the GNU General Public License version
 # 2 along with this work; if not, write to the Free Software Foundation,
 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-# 
+#
 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 # or visit www.oracle.com if you need additional information or have any
 # questions.
@@ -53,7 +53,7 @@
 def datestr(ctx):
     # Mercurial 0.9.5 and earlier append a time zone; strip it.
     return util.datestr(ctx.date(), format="%Y-%m-%d %H:%M")[:16]
-    
+
 def oneline(ctx):
     return ("%5d:%s  %-12s  %s  %s\n"
             % (ctx.rev(), short(ctx.node()), ctx.user(), datestr(ctx),
@@ -226,7 +226,7 @@
                 b = int(m.group(1))
                 if not b in bugids:
                     bugids[b] = ctx.rev()
-        
+
     # Should cache this, eventually
     bugids = { }                        # bugid -> rev
     opts = { 'rev' : ['0:tip'] }
@@ -626,7 +626,26 @@
     opts["strict"] = True
     return hook(ui, repo, hooktype, node, source, **opts)
 
+# From Mercurial 1.9, the preferred way to define commands is using the @command
+# decorator. If this isn't available, fallback on a simple local implementation
+# that just adds the data to the cmdtable.
+cmdtable = {}
+if hasattr(cmdutil, 'command'):
+    command = cmdutil.command(cmdtable)
+else:
+    def command(name, options, synopsis):
+        def decorator(func):
+            cmdtable[name] = func, list(options), synopsis
+            return func
+        return decorator
 
+opts = [("", "lax", False, "Check comments, tags and whitespace laxly"),
+        ("r", "rev", [], "check the specified revision or range (default: tip)"),
+        ("s", "strict", False, "check everything")]
+
+help = "[-r rev] [-s]"
+
+@command("jcheck", opts, "hg jcheck " + help)
 def jcheck(ui, repo, **opts):
     """check changesets against JDK standards"""
     ui.debug("jcheck repo=%s opts=%s\n" % (repo.path, opts))
@@ -678,13 +697,3 @@
         return Pass
     ui.write_err('ERROR:  pushing keys (%s) is disabled\n' % namespace)
     return Fail
-
-opts = [("", "lax", False, "Check comments, tags and whitespace laxly"),
-        ("r", "rev", [], "check the specified revision or range (default: tip)"),
-        ("s", "strict", False, "check everything")]
-
-help = "[-r rev] [-s]"
-
-cmdtable = {
-    "jcheck": (jcheck, opts, "hg jcheck " + help)
-}
--- a/jcheck_test.py	Mon May 22 12:53:12 2017 -0700
+++ b/jcheck_test.py	Mon Aug 21 14:51:04 2017 -0700
@@ -1,21 +1,21 @@
 #
-# Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
+# Copyright 2008, 2017, Sun Microsystems, Inc.  All Rights Reserved.
 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
-# 
+#
 # This code is free software; you can redistribute it and/or modify it
 # under the terms of the GNU General Public License version 2 only, as
 # published by the Free Software Foundation.
-# 
+#
 # This code is distributed in the hope that it will be useful, but WITHOUT
 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 # version 2 for more details (a copy is included in the LICENSE file that
 # accompanied this code).
-# 
+#
 # You should have received a copy of the GNU General Public License version
 # 2 along with this work; if not, write to the Free Software Foundation,
 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-# 
+#
 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 # or visit www.oracle.com if you need additional information or have any
 # questions.
@@ -32,6 +32,26 @@
 sys.path.insert(0, os.path.dirname(__file__))
 import jcheck
 
+# From Mercurial 1.9, the preferred way to define commands is using the @command
+# decorator. If this isn't available, fallback on a simple local implementation
+# that just adds the data to the cmdtable.
+cmdtable = {}
+if hasattr(cmdutil, 'command'):
+    command = cmdutil.command(cmdtable)
+else:
+    def command(name, options, synopsis):
+        def decorator(func):
+            cmdtable[name] = func, list(options), synopsis
+            return func
+        return decorator
+
+opts = (jcheck.opts +
+       [("", "white", [], "changeset hash for whitelist (TESTING)"),
+        ("", "black", [], "changeset hash for blacklist (TESTING)")])
+
+help = "[--white hash] [--black hash] " + jcheck.help
+
+@command("jcheck_test", opts, "hg jcheck_test " + help)
 def jcheck_test(ui, repo, **opts):
     """check changesets against JDK standards (TESTING)"""
     ui.debug("jcheck repo=%s opts=%s\n" % (repo.path, opts))
@@ -43,14 +63,3 @@
     del opts["white"]
     del opts["black"]
     return jcheck.jcheck(ui, repo, **opts)
-
-opts = (jcheck.opts +
-       [("", "white", [], "changeset hash for whitelist (TESTING)"),
-        ("", "black", [], "changeset hash for blacklist (TESTING)")])
-
-help = "[--white hash] [--black hash] " + jcheck.help
-
-cmdtable = {
-    "jcheck_test": (jcheck_test, opts,
-                    "hg jcheck_test " + help)
-}