1N/A#
1N/A# This program is free software; you can redistribute it and/or modify
1N/A# it under the terms of the GNU General Public License version 2
1N/A# as published by the Free Software Foundation.
1N/A#
1N/A# This program is distributed in the hope that it will be useful,
1N/A# but WITHOUT ANY WARRANTY; without even the implied warranty of
1N/A# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1N/A# GNU General Public License for more details.
1N/A#
1N/A# You should have received a copy of the GNU General Public License
1N/A# along with this program; if not, write to the Free Software
1N/A# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
1N/A#
1N/A
1N/A#
2N/A# Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.
1N/A# Copyright 2008, 2010, Richard Lowe
1N/A#
1N/A
1N/A'''
1N/ADeal with Mercurial versioning.
1N/A
1N/AAt a basic level, code to verify that the version of Mercurial in use
1N/Ais suitable for use with Cadmium, and compare that version for the
1N/Asake of adapting to Mercurial API changes.
1N/A'''
1N/A
1N/A#
1N/A# It is important that this module rely on as little of Mercurial as
1N/A# is possible.
1N/A#
1N/A
1N/A#
1N/A# Mercurial >= 1.2 has util.version(), prior versions
1N/A# version.get_version() We discover which to use this way, rather than
1N/A# via ImportError to account for mercurial.demandimport delaying the
1N/A# ImportError exception.
1N/A#
1N/Afrom mercurial import util
1N/Aif hasattr(util, 'version'):
1N/A hg_version = util.version
1N/Aelse:
1N/A from mercurial import version
1N/A hg_version = version.get_version
1N/A
1N/A
1N/Aclass VersionMismatch(Exception):
1N/A "Exception used to indicate a mismatch between SCM tools and Mercurial"
1N/A pass
1N/A
1N/A#
1N/A# List of versions that are explicitly acceptable to us
1N/A#
1N/AGOOD_VERSIONS = ['1.1.2', '1.3.1', '1.4.2', '1.5.4', '1.6.3', '1.7.1',
2N/A '1.8.1', '1.8.2', '1.8.4', '2.2.1']
1N/A
1N/A
1N/Adef check_version():
1N/A '''Check that we're running on a suitable version of Mercurial'''
1N/A
1N/A def versionstring(versions):
1N/A '''return the list, versions, as a vaguely grammatical string'''
1N/A if len(versions) > 1:
1N/A return "%s or %s" % (', '.join(versions[0:-1]), versions[-1])
1N/A else:
1N/A return versions[0]
1N/A
1N/A if hg_version() not in GOOD_VERSIONS:
1N/A raise VersionMismatch("Scm expects Mercurial version %s, "
1N/A "actual version is %s." %
1N/A (versionstring(GOOD_VERSIONS),
1N/A hg_version()))
1N/A
1N/A
1N/Adef _split_version(ver):
1N/A '''Return the Mercurial version as a list [MAJOR, MINOR, MICRO],
1N/A if this is not a released Mercurial return None.'''
1N/A
1N/A try:
1N/A l = map(int, ver.split('.'))
1N/A # If there's only one element, it's not really a tagged version
1N/A if len(l) <= 1:
1N/A return None
1N/A else:
1N/A return l
1N/A except ValueError:
1N/A return None
1N/A
1N/A
1N/Adef at_least(desired):
1N/A '''Return boolean indicating if the running version is greater
1N/A than or equal to, the version specified by major, minor, micro'''
1N/A
1N/A hgver = _split_version(hg_version())
1N/A desired = map(int, desired.split('.'))
1N/A
1N/A #
1N/A # If _split_version() returns None, we're running on a Mercurial that
1N/A # has not been tagged as a release. We assume this to be newer
1N/A # than any released version.
1N/A #
1N/A if hgver == None:
1N/A return True
1N/A
1N/A # Pad our versions to the same overall length, appending 0's
1N/A while len(hgver) < len(desired):
1N/A hgver.append(0)
1N/A while len(desired) < len(hgver):
1N/A desired.append(0)
1N/A
1N/A for real, req in zip(hgver, desired):
1N/A if real != req:
1N/A return real > req
1N/A
1N/A return True