git-cvsimport-3: handle the backend option first

Most of the options to git-cvsimport-3 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-3: 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-3: 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-3: 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-3: 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-3: 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-3: 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-3: 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>

---
Is there a way to get the reflog moving from "git branch --move" using
porcelain commands?
git-cvsimport-3: 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>
---
Should we be asserting that the working tree is not dirty before
starting the import, in the same way the git-rebase does?