changeset 14:3ea6f45e78c4

compat: limited support for hg versions 1.1 - 1.5.4 Tolerate a missing pushkey module (added in hg 1.6) and various other api differences. When used with mercurial versions earlier than 1.6, the following functionality is not available: - automatic discovery of the tree configuration for remote (http, ssh) repos workaround: explicitly specify the list of subtrees when cloning, e.g., hg tclone http://hg.openjdk.java.net/jdk7/jdk7 myjdk7 corba jaxp jaxws ... - accurate splitting of quoted config items when trees.splitargs = True workaround: set trees.splitargs = False and use a separate --subtrees argument for each subtree - the tdebugkeys command
author jcoomes
date Fri, 08 Nov 2013 18:27:24 -0800
parents b5c07bff235f
children db626e5b3455
files makefile trees.py
diffstat 2 files changed, 54 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/makefile	Mon Nov 04 12:36:32 2013 -0800
+++ b/makefile	Fri Nov 08 18:27:24 2013 -0800
@@ -1,5 +1,5 @@
 # 
-# Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2010, 2013, 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
@@ -43,7 +43,7 @@
 
 HGEXT_TEST	:= tests
 EXTENSION_PY	:= ${SRC_DIR}/trees.py
-HG_VERSIONS	:= 1.6:
+HG_VERSIONS	:= 1.1:
 
 -include ${HGEXT_TEST}/hgext-test.gmk
 
--- a/trees.py	Mon Nov 04 12:36:32 2013 -0800
+++ b/trees.py	Fri Nov 08 18:27:24 2013 -0800
@@ -109,6 +109,7 @@
 """
 
 import __builtin__
+import exceptions
 import inspect
 import os
 import re
@@ -125,6 +126,7 @@
 from mercurial.i18n import _
 
 testedwith = '''
+1.1 1.1.2 1.2 1.2.1 1.3 1.3.1 1.4 1.4.3 1.5 1.5.4
 1.6 1.6.4 1.7 1.7.5 1.8 1.8.4 1.9 1.9.3
 2.0-rc 2.0 2.0.2 2.1-rc 2.1 2.1.2 2.2-rc 2.2 2.2.3
 2.3-rc 2.3 2.3.2 2.4-rc 2.4 2.4.2 2.5-rc 2.5 2.5.4
@@ -636,7 +638,10 @@
 def _update(cmd, ui, repo, node=None, rev=None, clean=False, date=None,
             check=False, **opts):
     ui.status('[%s]:\n' % repo.root)
-    trc = cmd(ui, repo, node, rev, clean, date, check)
+    if _newupdate:
+        trc = cmd(ui, repo, node, rev, clean, date, check)
+    else:
+        trc = cmd(ui, repo, node, rev, clean, date)
     rc = trc != None and trc or 0
     for subtree in _subtreelist(ui, repo, opts):
         ui.status('\n')
@@ -679,9 +684,27 @@
 
 # ----------------------------- mercurial linkage ------------------------------
 
+if not hasattr(hg, 'remoteui'):
+    if hasattr(cmdutil, 'remoteui'):
+        # hg < 1.5.4:  remoteui is in cmdutil instead of hg
+        hg.remoteui = cmdutil.remoteui
+    else:
+        # hg < 1.3:  no remoteui
+        def _remoteui(ui, opts):
+            cmdutil.setremoteconfig(ui, opts)
+            return ui
+        hg.remoteui = _remoteui
+
 # Tolerate changes to the signature of hg.clone().
 def compatible_clone():
     clone_args = inspect.getargspec(hg.clone)[0]
+    if not 'branch' in clone_args:
+        # hg < 1.5:  no 'branch' parameter (a78bfaf988e1)
+        def hg_clone(ui, peeropts, source, dest=None, pull=False, rev=None,
+                     update=True, stream=False, branch=None):
+            rui = hg.remoteui(ui, peeropts)
+            return hg.clone(rui, source, dest, pull, rev, update, stream)
+        return hg_clone
     if len(clone_args) < 9:
         # hg < 1.9:  no 'peeropts' parameter (d976542986d2, bd1acea552ff).
         def hg_clone(ui, peeropts, source, dest=None, pull=False, rev=None,
@@ -696,6 +719,7 @@
 if getattr(hg, 'peer', None) is None:
     hg.peer = lambda ui, opts, url: hg.repository(ui, url)
 
+_newupdate = len(inspect.getargspec(commands.update)[0]) >= 7
 namespaceopt = [('', 'tns', '',
                  _('trees namespace to use'),
                  _('NAMESPACE'))]
@@ -703,6 +727,16 @@
                  _('path to subtree'),
                  _('SUBTREE'))] + namespaceopt
 
+if len(commands.globalopts[0]) < 5:
+    # hg < 1.5.4:  arg description (5th tuple element) is not supported
+    def trimoptions(l):
+        i = 0
+        for opt in l:
+            l[i] = opt[:4]
+            i += 1
+    trimoptions(namespaceopt)
+    trimoptions(subtreesopts)
+
 walkopt = [('w', 'walk', False,
             _('walk the filesystem to discover subtrees'))]
 
@@ -803,5 +837,20 @@
     # Pushing keys is disabled; unclear whether/how it should work.
     pushfunc = lambda *x: False
     x = [_nsnormalize(s) for s in ui.configlist('trees', 'namespaces', [])]
-    for ns in [_ns(ui, {})] + x:
-        pushkey.register(ns, pushfunc, genlistkeys(ns))
+    try:
+        for ns in [_ns(ui, {})] + x:
+            pushkey.register(ns, pushfunc, genlistkeys(ns))
+    except exceptions.ImportError:
+        # hg < 1.6 - no pushkey.
+        def _listkeys(self, namespace):
+            # trees are ordered, so the keys are the non-negative integers.
+            d = {}
+            i = 0
+            try:
+                for line in self.opener(namespace):
+                    d[("%d" % i)] = line.rstrip('\n\r')
+                    i += 1
+                return d
+            except:
+                return {}
+        setattr(type(repo), 'listkeys', _listkeys)