From cc7a4acc31d7e4cf97a19b938416611288604913 Mon Sep 17 00:00:00 2001 From: mhagger Date: Tue, 1 Sep 2009 07:19:40 +0000 Subject: [PATCH] Add cvs2hg top-level script. Patch by: Greg Ward * cvs2hg: New script (copy of cvs2{svn,git} with an additional check of Mercural API version). * cvs2svn_lib/main.py: Add hg_main(). git-svn-id: http://cvs2svn.tigris.org/svn/cvs2svn/trunk@4911 be7e6eca-30d4-0310-a8e5-ac0d63af7087 --- cvs2hg | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++++ cvs2svn_lib/main.py | 8 +++++ 2 files changed, 103 insertions(+) create mode 100755 cvs2hg diff --git a/cvs2hg b/cvs2hg new file mode 100755 index 00000000..d048c9d4 --- /dev/null +++ b/cvs2hg @@ -0,0 +1,95 @@ +#!/usr/bin/env python +# (Be in -*- python -*- mode.) +# +# ==================================================================== +# Copyright (c) 2000-2008 CollabNet. All rights reserved. +# +# This software is licensed as described in the file COPYING, which +# you should have received as part of this distribution. The terms +# are also available at http://subversion.tigris.org/license-1.html. +# If newer versions of this license are posted there, you may use a +# newer version instead, at your option. +# +# This software consists of voluntary contributions made by many +# individuals. For exact contribution history, see the revision +# history and logs, available at http://cvs2svn.tigris.org/. +# ==================================================================== + +import sys + +# Make sure that a supported version of Python is being used. Do this +# as early as possible, using only code compatible with Python 1.5.2 +# and Python 3.x before the check. Remember: +# +# Python 1.5.2 doesn't have sys.version_info or ''.join(). +# Python 3.0 doesn't have string.join(). +# There are plans to start deprecating the string formatting '%' +# operator in Python 3.1 (but we use it here anyway). + +version_error = """\ +ERROR: cvs2hg requires Python 2, version 2.4 or later; it does not +work with Python 3. You are currently using""" + +version_advice = """\ +Please restart cvs2hg using a different version of the Python +interpreter. Visit http://www.python.org or consult your local system +administrator if you need help. + +HINT: If you already have a usable Python version installed, it might +be possible to invoke cvs2hg with the correct Python interpreter by +typing something like 'python2.5 """ + sys.argv[0] + """ [...]'. +""" + +try: + version = sys.version_info +except AttributeError: + # This is probably a pre-2.0 version of Python. + sys.stderr.write(version_error + '\n') + sys.stderr.write('-'*70 + '\n') + sys.stderr.write(sys.version + '\n') + sys.stderr.write('-'*70 + '\n') + sys.stderr.write(version_advice) + sys.exit(1) + +if not ((2,4) <= version < (3,0)): + sys.stderr.write( + version_error + ' version %d.%d.%d.\n' + % (version[0], version[1], version[2],) + ) + sys.stderr.write(version_advice) + sys.exit(1) + +hg_required = "ERROR: cvs2hg requires Mercurial 1.1 or later.\n" +hg_missing = "(No Mercurial API found.)\n" +hg_version = "(Attempted to use the Mercurial %s API in\n%s.)\n" + + +import os +try: + import mercurial + from mercurial import context, __version__ + context.memctx # ensure Mercurial >= 1.1 + context.memfilectx +except ImportError: + sys.stderr.write(hg_required + hg_missing) + sys.exit(1) +except AttributeError: + sys.stderr.write(hg_required + + hg_version + % (__version__.version, + os.path.dirname(mercurial.__file__))) + sys.exit(1) + +import os + +from cvs2svn_lib.common import FatalException +from cvs2svn_lib.main import hg_main + + +try: + hg_main(os.path.basename(sys.argv[0]), sys.argv[1:]) +except FatalException, e: + sys.stderr.write(str(e) + '\n') + sys.exit(1) + + diff --git a/cvs2svn_lib/main.py b/cvs2svn_lib/main.py index f222de0c..a98e642e 100644 --- a/cvs2svn_lib/main.py +++ b/cvs2svn_lib/main.py @@ -115,3 +115,11 @@ def bzr_main(progname, cmd_args): main(progname, run_options, pass_manager) +def hg_main(progname, cmd_args): + # Import late so cvs2{svn,git} do not depend on being able to import + # the Mercurial API. + from cvs2svn_lib.hg_run_options import HgRunOptions + + pass_manager = PassManager(passes) + run_options = HgRunOptions(progname, cmd_args, pass_manager) + main(progname, run_options, pass_manager) -- 2.11.4.GIT