changeset 876:b450448a9033

wrappers: don't break on old hg versions that lack discovery
author Augie Fackler <raf@durin42.com>
date Fri, 20 Apr 2012 18:33:19 -0500
parents 9cc3ed1f474d
children 2c9f4c1686fa
files hgsubversion/wrappers.py
diffstat 1 files changed, 10 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/hgsubversion/wrappers.py
+++ b/hgsubversion/wrappers.py
@@ -1,7 +1,11 @@
 from hgext import rebase as hgrebase
 
 from mercurial import cmdutil
-from mercurial import discovery
+try:
+    from mercurial import discovery
+    discovery.nullid  # force demandimport to import the module
+except ImportError:
+    discovery = None
 from mercurial import patch
 from mercurial import hg
 from mercurial import util as hgutil
@@ -92,10 +96,11 @@ def findcommonoutgoing(repo, other, only
     parent = repo.parents()[0].node()
     hashes = meta.revmap.hashes()
     common, heads = util.outgoing_common_and_heads(repo, hashes, parent)
-    outobj = getattr(discovery, 'outgoing', None)
-    if outobj is not None:
-        # Mercurial 2.1 and later
-        return outobj(repo.changelog, common, heads)
+    if discovery is not None:
+        outobj = getattr(discovery, 'outgoing', None)
+        if outobj is not None:
+            # Mercurial 2.1 and later
+            return outobj(repo.changelog, common, heads)
     # Mercurial 2.0 and earlier
     return common, heads