serveronly: give the sub extension a way to access to the 'evolve' module
authorPierre-Yves David <pierre-yves.david@ens-lyon.org>
Tue, 07 Mar 2017 12:27:01 +0100
changeset 2047 ce39d0f9976d
parent 2046 994d81caec68
child 2048 05e91ba0a7a9
serveronly: give the sub extension a way to access to the 'evolve' module We keep it as clean as possible but if the extension is specified with a direct path, we have to be a bit hacky. Being able to access the whole evolve extension from the 'serveronly' extension will lift multiple constraints on how we organise the code and will allow for cleaner and clearer code. We extract a minor function into a 'utility' module to have something to depends on.
hgext3rd/evolve/__init__.py
hgext3rd/evolve/exchange.py
hgext3rd/evolve/serveronly.py
hgext3rd/evolve/utility.py
--- a/hgext3rd/evolve/__init__.py	Tue Mar 07 12:10:05 2017 +0100
+++ b/hgext3rd/evolve/__init__.py	Tue Mar 07 12:27:01 2017 +0100
@@ -113,9 +113,10 @@
 from mercurial.node import nullid
 
 from . import (
+    exchange,
     exthelper,
-    exchange,
     serveronly,
+    utility,
 )
 
 
@@ -124,7 +125,7 @@
 # Flags for enabling optional parts of evolve
 commandopt = 'allnewcommands'
 
-obsexcmsg = serveronly.obsexcmsg
+obsexcmsg = utility.obsexcmsg
 
 _pack = struct.pack
 _unpack = struct.unpack
--- a/hgext3rd/evolve/exchange.py	Tue Mar 07 12:10:05 2017 +0100
+++ b/hgext3rd/evolve/exchange.py	Tue Mar 07 12:27:01 2017 +0100
@@ -29,10 +29,11 @@
 from . import (
     exthelper,
     serveronly,
+    utility,
 )
 
 eh = exthelper.exthelper()
-obsexcmsg = serveronly.obsexcmsg
+obsexcmsg = utility.obsexcmsg
 
 def obsexcprg(ui, *args, **kwargs):
     topic = 'obsmarkers exchange'
--- a/hgext3rd/evolve/serveronly.py	Tue Mar 07 12:10:05 2017 +0100
+++ b/hgext3rd/evolve/serveronly.py	Tue Mar 07 12:27:01 2017 +0100
@@ -8,12 +8,16 @@
 For client side usages it is recommended to use the evolve extension for
 improved user interface.'''
 
+from __future__ import absolute_import
+
 testedwith = '3.3 3.4-rc'
 buglink = 'https://bz.mercurial-scm.org/'
 
 import hashlib
 import struct
 from cStringIO import StringIO
+import sys
+import os
 
 
 from mercurial import (
@@ -43,6 +47,17 @@
 
 from mercurial import pushkey
 
+try:
+    from . import utility
+except ValueError as exc:
+    if exc.message != 'Attempted relative import in non-package':
+        raise
+    # extension imported using direct path
+    sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
+    from evolve import utility
+
+obsexcmsg = utility.obsexcmsg
+
 # specific content also include the wrapping int extsetup
 def _nslist(orig, repo):
     rep = orig(repo)
@@ -53,14 +68,6 @@
 # End of simple4server specific content
 
 
-def obsexcmsg(ui, message, important=False):
-    verbose = ui.configbool('experimental', 'verbose-obsolescence-exchange',
-                            False)
-    if verbose:
-        message = 'OBSEXC: ' + message
-    if important or verbose:
-        ui.status(message)
-
 def _pushobsmarkers(repo, data):
     tr = lock = None
     try:
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hgext3rd/evolve/utility.py	Tue Mar 07 12:27:01 2017 +0100
@@ -0,0 +1,14 @@
+# Various utility function for the evolve extension
+#
+# Copyright 2017 Pierre-Yves David <pierre-yves.david@ens-lyon.org>
+#
+# This software may be used and distributed according to the terms of the
+# GNU General Public License version 2 or any later version.
+
+def obsexcmsg(ui, message, important=False):
+    verbose = ui.configbool('experimental', 'verbose-obsolescence-exchange',
+                            False)
+    if verbose:
+        message = 'OBSEXC: ' + message
+    if important or verbose:
+        ui.status(message)