Quiet down the tarball builder.
git-cvsimport: comply with PEP 8 some more

Introduce 2 blank lines between top-level items and one between class
member functions, as recommended by PEP 8.

Signed-off-by: John Keeping <john@keeping.me.uk>
git-cvsimport: use title case for class names

Signed-off-by: John Keeping <john@keeping.me.uk>
git-cvsimport: extract main as a method

This is the first step to making it easier to debug the script using a
Python REPL.

Signed-off-by: John Keeping <john@keeping.me.uk>
git-cvsimport: remove a redundant version check

We already check the Python version at the top of the script, so doing
it again in main() is unnecessary.

Signed-off-by: John Keeping <john@keeping.me.uk>
git-cvsimport: don't quit when filesource is requested

Signed-off-by: John Keeping <john@keeping.me.uk>
git-cvsimport: extract error handler from main()

This will allow us to handle errors during option parsing by simply
raising an exception, and removes a layer of indentation.

Also change the error from "git_cvsimport" to "git cvsimport".

The patch is much clearer with 'git diff -b'.

Signed-off-by: John Keeping <john@keeping.me.uk>
git-cvsimport: use Fatal consistently

Instead of doing "sys.stderr.write(...); sys.exit(1)", raise a Fatal
exception when a fatal error occurs.  This change means that we can
remove the "git cvsimport: " prefix from all fatal error messages since
it is added by the top-level exception handler when printing the message
from a Fatal exception.

Signed-off-by: John Keeping <john@keeping.me.uk>
git-cvsimport: remove unused parameter to *_or_die

The legend parameters to do_or_die() and capture_or_die() are never
used.  Remove them.

Signed-off-by: John Keeping <john@keeping.me.uk>
git-cvsimport: handle the backend option first

Most of the options to git-cvsimport are simply passed to the backend,
this means the if the '-e <backend>' option does not occur first any
options preceding it will effectively be ignored.

Extract the '-e' option handling as a special case before the main
option handling loop to avoid this issue.

Signed-off-by: John Keeping <john@keeping.me.uk>
git-cvsimport: extract subprocess error handling

By changing subprocess.call into subprocess.check_call all invocations
of subprocesses will throw a CalledProcessError if the child fails.
This means that we can use common handling for subprocess errors and
extract this to the top-level of the script.

Signed-off-by: John Keeping <john@keeping.me.uk>
git-cvsimport: don't execute subcommands with the shell

Creating command strings to execute subcommands via the shell means that
care needs to be taken to quote any user-supplied values, but Python
provides a better way by passing a list of arguments when creating
subprocesses.

Make this change, changing pipelines that currently use the shell to use
pipelined subprocesses.

Signed-off-by: John Keeping <john@keeping.me.uk>
git-cvsimport: Remove cvsps 2.x fallback code

git-cvsimport-fallback isn't included here so this code can never work.

Signed-off-by: John Keeping <john@keeping.me.uk>
git-cvsimport: actually invoke git-branch

The command called if a branch is renamed is "branch -m".  This should
clearly by "git branch -m".

Signed-off-by: John Keeping <john@keeping.me.uk>
git-cvsimport: fix moving tags

The command "git tag -f $tag $changed" moves $tag to point at commit
$changed but $changed is the new name for the tag.  Fix this by
reordering the arguments to "git tag".

Also add a call to "git update-ref -d" to remove the old tag.

Signed-off-by: John Keeping <john@keeping.me.uk>
git-cvsimport: use for-each-ref not "branch -l"

git-branch is a porcelain command, switch to the plumbing command
git-for-each-ref so that we're not relying on the output format of
git-branch.

Signed-off-by: John Keeping <john@keeping.me.uk>
git-cvsimport: use for-each-ref not "tag -l"

git-tag is a porcelain command, switch to the plumbing command
git-for-each-ref so that we're not relying on the output format of
git-tag.

Signed-off-by: John Keeping <john@keeping.me.uk>
git-cvsimport: use git-update-ref to modify refs

Instead of the porcelain command "git-tag" use "git-update-ref" when
tags need to be renamed.

Signed-off-by: John Keeping <john@keeping.me.uk>
git-cvsimport: checkout the new tree correctly

Once the import has finished, the branch pointed at by HEAD may have
moved.  "git checkout -q" isn't sufficient to change the working tree -
use "git checkout -f" as git-cvsimport-2.perl does.

Signed-off-by: John Keeping <john@keeping.me.uk>
git-cvsimport: don't allow more than one module

Raise an error if more than one module is specified on the command line.

Signed-off-by: John Keeping <john@keeping.me.uk>