Skip to content

Commit

Permalink
Add an explicit "cvs2git" script.
Browse files Browse the repository at this point in the history
For now, it does exactly the same as "cvs2svn".

This change also adds some minimal test infrastructure for cvs2git,
and removes the "XFail" designation from those tests.  But the tests
only check that cvs2git runs to completion; they do not test the
output whatsoever.

* cvs2git: New top-level script, for starting conversions 2git or 2hg.

* cvs2git-example.options, cvs2hg-example.options, www/cvs2git.html,
  CHANGES: Document the new script.

* cvs2svn_lib/main.py (svn_main, git_main): New functions for starting
  the corresponding types of conversions.  They set up options then
  call main().

  (main): Take options run_options and pass_manager instead of
  cmd_args.

* cvs2svn: Invoke svn_main() instead of main().

* cvs2svn-example.options: Document the new (correct) type of the
  run_options variable.

* cvs2svn_lib/svn_run_options.py, cvs2svn_lib/git_run_options.py: New
  modules, containing RunOptions classes specific to 2svn and 2git
  conversions, respectively.  For now, these are identical to the
  common RunOptions class.

* cvs2svn_lib/run_options.py: Update module docstring.

* run-tests.py (cvs2git): New module-level variable.

  (run_cvs2git): The 2git analogue of run_cvs2svn().

  (GitConversion): New class, the analogue of Conversion (except that
  it does much less!)

  (main_git, main_hg): Use the GitConversion class.

  (test_list): Remove the XFail annotations from main_git and main_hg.

git-svn-id: http://cvs2svn.tigris.org/svn/cvs2svn/trunk@4744 be7e6eca-30d4-0310-a8e5-ac0d63af7087
  • Loading branch information
mhagger committed Dec 30, 2008
1 parent 243e0b8 commit 04e13a2
Show file tree
Hide file tree
Showing 12 changed files with 303 additions and 103 deletions.
1 change: 1 addition & 0 deletions CHANGES
Expand Up @@ -2,6 +2,7 @@ Version ?.?.? (not yet released)
--------------------------------

New features:
* Added a "cvs2git" script for starting conversions to git or Mercurial.

Bugs fixed:
* cvs2git with non-inline blobs: a revision after a delete could be empty.
Expand Down
75 changes: 75 additions & 0 deletions cvs2git
@@ -0,0 +1,75 @@
#!/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: cvs2git requires Python 2, version 2.4 or later; it does not
work with Python 3. You are currently using"""

version_advice = """\
Please restart cvs2git 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 cvs2git 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)


import os

from cvs2svn_lib.common import FatalException
from cvs2svn_lib.main import git_main


try:
git_main(os.path.basename(sys.argv[0]), sys.argv[1:])
except FatalException, e:
sys.stderr.write(str(e) + '\n')
sys.exit(1)


15 changes: 7 additions & 8 deletions cvs2git-example.options
Expand Up @@ -24,12 +24,11 @@
# see the comments in this file for information about what options are
# available and how they can be set.
#
# "cvs2git" is shorthand for "cvs2svn in the mode where it is
# outputting to git instead of Subversion". But the program that
# needs to be run is still called "cvs2svn". Run it with the
# --options option, passing it this file as argument:
# The program that is run to convert from CVS to git is called
# cvs2git. Run it with the --options option, passing it this file as
# argument:
#
# cvs2svn --options=cvs2git-example.options
# cvs2git --options=cvs2git-example.options
#
# Many options do not have defaults, so it is easier to copy this file
# and modify what you need rather than creating a new options file
Expand Down Expand Up @@ -63,9 +62,9 @@
# ctx -- a Ctx object (see cvs2svn_lib/context.py), which holds
# many configuration options
#
# run_options -- an instance of the RunOptions class (see
# cvs2svn_lib/run_options.py), which holds some variables
# governing how cvs2svn is run
# run_options -- an instance of the GitRunOptions class (see
# cvs2svn_lib/git_run_options.py), which holds some variables
# governing how cvs2git is run


# Import some modules that are used in setting the options:
Expand Down
16 changes: 8 additions & 8 deletions cvs2hg-example.options
Expand Up @@ -24,12 +24,12 @@
# see the comments in this file for information about what options are
# available and how they can be set.
#
# "cvs2hg" is shorthand for "cvs2svn in the mode where it is
# outputting to Mercurial instead of Subversion". But the program
# that needs to be run is still called "cvs2svn". Run it with the
# --options option, passing it this file as argument:
# "cvs2hg" is shorthand for "cvs2git in the mode where it is
# outputting to Mercurial instead of git". But the program that needs
# to be run is still called "cvs2git". Run it with the --options
# option, passing it this file as argument:
#
# cvs2svn --options=cvs2hg-example.options
# cvs2git --options=cvs2hg-example.options
#
# Mercurial can (experimentally at this time) read git-fast-import
# format via its "hg fastimport" extension, with a couple of
Expand Down Expand Up @@ -80,9 +80,9 @@
# ctx -- a Ctx object (see cvs2svn_lib/context.py), which holds
# many configuration options
#
# run_options -- an instance of the RunOptions class (see
# cvs2svn_lib/run_options.py), which holds some variables
# governing how cvs2svn is run
# run_options -- an instance of the GitRunOptions class (see
# cvs2svn_lib/git_run_options.py), which holds some variables
# governing how cvs2git is run


# Import some modules that are used in setting the options:
Expand Down
6 changes: 3 additions & 3 deletions cvs2svn
Expand Up @@ -2,7 +2,7 @@
# (Be in -*- python -*- mode.)
#
# ====================================================================
# Copyright (c) 2000-2007 CollabNet. All rights reserved.
# 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
Expand Down Expand Up @@ -63,11 +63,11 @@ if not ((2,4) <= version < (3,0)):
import os

from cvs2svn_lib.common import FatalException
from cvs2svn_lib.main import main
from cvs2svn_lib.main import svn_main


try:
main(os.path.basename(sys.argv[0]), sys.argv[1:])
svn_main(os.path.basename(sys.argv[0]), sys.argv[1:])
except FatalException, e:
sys.stderr.write(str(e) + '\n')
sys.exit(1)
Expand Down
4 changes: 2 additions & 2 deletions cvs2svn-example.options
Expand Up @@ -53,8 +53,8 @@
# ctx -- a Ctx object (see cvs2svn_lib/context.py), which holds
# many configuration options
#
# run_options -- an instance of the OptionsFileRunOptions class
# (see cvs2svn_lib/run_options.py), which holds some variables
# run_options -- an instance of the SVNRunOptions class (see
# cvs2svn_lib/svn_run_options.py), which holds some variables
# governing how cvs2svn is run


Expand Down
26 changes: 26 additions & 0 deletions cvs2svn_lib/git_run_options.py
@@ -0,0 +1,26 @@
# (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/.
# ====================================================================

"""This module manages cvs2git run options."""


from cvs2svn_lib.run_options import RunOptions


class GitRunOptions(RunOptions):
pass


22 changes: 16 additions & 6 deletions cvs2svn_lib/main.py
Expand Up @@ -27,24 +27,21 @@
pass

from cvs2svn_lib.common import FatalError
from cvs2svn_lib.run_options import RunOptions
from cvs2svn_lib.svn_run_options import SVNRunOptions
from cvs2svn_lib.git_run_options import GitRunOptions
from cvs2svn_lib.context import Ctx
from cvs2svn_lib.pass_manager import PassManager
from cvs2svn_lib.passes import passes


def main(progname, cmd_args):
def main(progname, run_options, pass_manager):
# Disable garbage collection, as we try not to create any circular
# data structures:
gc.disable()

# Convenience var, so we don't have to keep instantiating this Borg.
ctx = Ctx()

pass_manager = PassManager(passes)

run_options = RunOptions(progname, cmd_args, pass_manager)

# Make sure the tmp directory exists. Note that we don't check if
# it's empty -- we want to be able to use, for example, "." to hold
# tempfiles. But if we *did* want check if it were empty, we'd do
Expand Down Expand Up @@ -98,3 +95,16 @@ def main(progname, cmd_args):
except:
pass


def svn_main(progname, cmd_args):
pass_manager = PassManager(passes)
run_options = SVNRunOptions(progname, cmd_args, pass_manager)
main(progname, run_options, pass_manager)


def git_main(progname, cmd_args):
pass_manager = PassManager(passes)
run_options = GitRunOptions(progname, cmd_args, pass_manager)
main(progname, run_options, pass_manager)


3 changes: 1 addition & 2 deletions cvs2svn_lib/run_options.py
Expand Up @@ -14,8 +14,7 @@
# history and logs, available at http://cvs2svn.tigris.org/.
# ====================================================================

"""This module contains classes to set cvs2svn run options."""

"""This module contains classes to set common cvs2xxx run options."""

import sys
import re
Expand Down
26 changes: 26 additions & 0 deletions cvs2svn_lib/svn_run_options.py
@@ -0,0 +1,26 @@
# (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/.
# ====================================================================

"""This module manages cvs2svn run options."""


from cvs2svn_lib.run_options import RunOptions


class SVNRunOptions(RunOptions):
pass


62 changes: 58 additions & 4 deletions run-tests.py
Expand Up @@ -71,6 +71,7 @@
from svntest.tree import get_child

cvs2svn = os.path.abspath('cvs2svn')
cvs2git = os.path.abspath('cvs2git')

# We use the installed svn and svnlook binaries, instead of using
# svntest.main.run_svn() and svntest.main.run_svnlook(), because the
Expand Down Expand Up @@ -160,6 +161,27 @@ def run_cvs2svn(error_re, *varargs):
# comment remains to warn about this problem.


def run_cvs2git(error_re, *varargs):
"""Run cvs2git with VARARGS, returning stdout as a list of lines.
If there is any stderr and ERROR_RE is None, raise
RunProgramException, and print the stderr lines if
svntest.main.verbose_mode is true.
If ERROR_RE is not None, it is a string regular expression that must
match some line of stderr. If it fails to match, raise
MissingErrorException."""

# Use the same python that is running this script
return run_program(sys.executable, error_re, cvs2git, *varargs)
# On Windows, for an unknown reason, the cmd.exe process invoked by
# os.system('sort ...') in cvs2svn receives invalid stdio handles, if
# cvs2svn is started as "cvs2svn ...". "python cvs2svn ..." avoids
# this. Therefore, the redirection of the output to the .s-revs file fails.
# We no longer use the problematic invocation on any system, but this
# comment remains to warn about this problem.


def run_svn(*varargs):
"""Run svn with VARARGS; return stdout as a list of lines.
If there is any stderr, raise RunProgramException, and print the
Expand Down Expand Up @@ -639,6 +661,32 @@ def check_props(self, keys, checks):
)


class GitConversion:
"""A record of a cvs2svn conversion.
Fields:
name -- a one-word name indicating the CVS repository to be converted.
stdout -- a list of lines written by cvs2svn to stdout."""

def __init__(self, name, error_re, args, options_file):
self.name = name
if not os.path.isdir(tmp_dir):
os.mkdir(tmp_dir)

cvsrepos = os.path.join(test_data_dir, '%s-cvsrepos' % self.name)

args = list(args)
assert options_file
self.options_file = os.path.join(cvsrepos, options_file)
args.extend([
'--options=%s' % self.options_file,
])

self.stdout = run_cvs2git(error_re, *args)


# Cache of conversions that have already been done. Keys are conv_id;
# values are Conversion instances.
already_converted = { }
Expand Down Expand Up @@ -3227,7 +3275,10 @@ def main_git():
# Then use "gitk --all", "git log", etc. to test the contents of the
# repository.

conv = ensure_conversion('main', options_file='cvs2git.options')
# We don't have the infrastructure to check that the resulting git
# repository is correct, so we just check that the conversion runs
# to completion:
conv = GitConversion('main', None, [], options_file='cvs2git.options')


def main_hg():
Expand All @@ -3245,7 +3296,10 @@ def main_hg():
# Then use "gitk --all", "git log", etc. to test the contents of the
# repository.

conv = ensure_conversion('main', options_file='cvs2hg.options')
# We don't have the infrastructure to check that the resulting
# Mercurial repository is correct, so we just check that the
# conversion runs to completion:
conv = GitConversion('main', None, [], options_file='cvs2hg.options')


def invalid_symbol():
Expand Down Expand Up @@ -3526,8 +3580,8 @@ def add_cvsignore_to_branch_test():
trunk_readd,
branch_from_deleted_1_1,
add_on_branch,
XFail(main_git),
XFail(main_hg),
main_git,
main_hg,
invalid_symbol,
invalid_symbol_ignore,
EOLVariants('LF'),
Expand Down

0 comments on commit 04e13a2

Please sign in to comment.