# HG changeset patch
# User Henrik Stuart <h...@hstuart.dk>
# Date 1249371242 -7200
# Node ID 3e3040595e92ea9dc640e8d6385db5cc780de8f4
# Parent  cee66577eee9eb3350373e3d5b3214ceea438767
hgtk: make version check independent from hglib

hglib currently imports mercurial.error that isn't present in earlier
versions of Mercurial, causing a demandimport error.

diff -r cee66577eee9 -r 3e3040595e92 hggtk/hgtk.py
--- a/hggtk/hgtk.py     Tue Aug 04 09:33:58 2009 +0200
+++ b/hggtk/hgtk.py     Tue Aug 04 09:34:02 2009 +0200
@@ -166,11 +166,6 @@
 def _runcatch(ui, args):
     try:
         try:
-            checkhgversion(hglib.hgversion)
-        except util.Abort, inst:
-            ui.status(_("abort: %s!\n") % inst)
-            return 0
-        try:
             return runcommand(ui, args)
         finally:
             ui.flush()
@@ -570,26 +565,6 @@
             else:
                 ui.write("%s\n" % first)
 
-def checkhgversion(v):
-    """range check the Mercurial version"""
-    # this is a series of hacks, but Mercurial's versioning scheme
-    # doesn't lend itself to a "correct" solution.  This will at least
-    # catch people who have old Mercurial packages.
-    reqver = ['1', '3']
-    if not v or v == 'unknown' or len(v) >= 12:
-        # can't make any intelligent decisions about unknown or hashes
-        return
-    vers = v.split('.')[:2]
-    if vers == reqver or len(vers) < 2:
-        return
-    nextver = list(reqver)
-    nextver[1] = chr(ord(reqver[1])+1)
-    if vers == nextver:
-        return
-    raise util.Abort(_('This version of TortoiseHg requires Mercurial '
-                       'version %s.n to %s.n, but finds %s') %
-                       ('.'.join(reqver), '.'.join(nextver), v))
-
 def version(ui, **opts):
     """output version and copyright information"""
     ui.write(_('TortoiseHg Dialogs (version %s), '
diff -r cee66577eee9 -r 3e3040595e92 hgtk
--- a/hgtk      Tue Aug 04 09:33:58 2009 +0200
+++ b/hgtk      Tue Aug 04 09:34:02 2009 +0200
@@ -29,7 +29,8 @@
 from mercurial import demandimport
 demandimport.ignore.append('win32com.shell')
 demandimport.enable()
-from mercurial import ui
+from mercurial import ui, util
+from thgutil.hgversion import hgversion, checkhgversion
 import cStringIO
 import traceback
 
@@ -44,6 +45,11 @@
 _ui = ui.ui()
 capt = _ui.configbool('tortoisehg', 'stderrcapt', True)
 
+err = checkhgversion(hgversion)
+if err:
+    _ui.warn('abort: %s\n' % err)
+    sys.exit(1)
+
 if not capt or 'THGDEBUG' in os.environ:
     sys.exit(hggtk.hgtk.dispatch(sys.argv[1:]))
 else:
diff -r cee66577eee9 -r 3e3040595e92 thgutil/hglib.py
--- a/thgutil/hglib.py  Tue Aug 04 09:33:58 2009 +0200
+++ b/thgutil/hglib.py  Tue Aug 04 09:34:02 2009 +0200
@@ -22,14 +22,7 @@
 _encodingmode = encoding.encodingmode
 _fallbackencoding = encoding.fallbackencoding
 
-try:
-    # post 1.1.2
-    from mercurial import util
-    hgversion = util.version()
-except AttributeError:
-    # <= 1.1.2
-    from mercurial import version
-    hgversion = version.get_version()
+from thgutil.hgversion import hgversion
 
 def toutf(s):
     """
diff -r cee66577eee9 -r 3e3040595e92 thgutil/hgversion.py
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/thgutil/hgversion.py      Tue Aug 04 09:34:02 2009 +0200
@@ -0,0 +1,30 @@
+# hgversion.py - Version information for Mercurial
+
+try:
+    # post 1.1.2
+    from mercurial import util
+    hgversion = util.version()
+except AttributeError:
+    # <= 1.1.2
+    from mercurial import version
+    hgversion = version.get_version()
+
+def checkhgversion(v):
+    """range check the Mercurial version"""
+    # this is a series of hacks, but Mercurial's versioning scheme
+    # doesn't lend itself to a "correct" solution.  This will at least
+    # catch people who have old Mercurial packages.
+    reqver = ['1', '3']
+    if not v or v == 'unknown' or len(v) >= 12:
+        # can't make any intelligent decisions about unknown or hashes
+        return
+    vers = v.split('.')[:2]
+    if vers == reqver or len(vers) < 2:
+        return
+    nextver = list(reqver)
+    nextver[1] = chr(ord(reqver[1])+1)
+    if vers == nextver:
+        return
+    return (('This version of TortoiseHg requires Mercurial '
+                       'version %s.n to %s.n, but finds %s') %
+                       ('.'.join(reqver), '.'.join(nextver), v))

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Tortoisehg-develop mailing list
Tortoisehg-develop@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tortoisehg-develop

Reply via email to