hg2git.py: do not generate invalid fast-export names or emails
commitfc972c7a8344d3615f0158b968999809438e390b
authorKyle J. McKay <mackyle@gmail.com>
Fri, 4 Apr 2014 03:42:18 +0000 (3 20:42 -0700)
committerKyle J. McKay <mackyle@gmail.com>
Wed, 16 Apr 2014 03:03:12 +0000 (15 20:03 -0700)
tree235344d260ddf5752dfa13bc5413569f02580af1
parent779e2f6da887729fc513f5efceaa3a3083858c9b
hg2git.py: do not generate invalid fast-export names or emails

Git processes the user name and email portion of an author name by
first stripping any "crud" characters from both the beginning and
end of each, then removing any remaining '<', '>' or "\n" characters
and finally adding a surrounding '<' and '>' to the email and joining
that to the user name with a space.

While Git may appear to allow an empty name and/or email address in
the raw author data, doing so ultimately causes problems when any
attempt is made to use rebase, filter-branch or other such utilities,
so empty name and/or email addresses also need to be avoided.

The source commit data from hg appears to have few restrictions on
the format of the author information.  This can easily result in bogus
author data being produced in the fast-export stream that then causes
git fast-import to fail with an error.

Fix this by performing Git-like processing of both the user name and
email as extracted from the hg commit author information.

The basic idea is to take anything to the left of the first '<' and
to the right of the last '>' as the user name and anything between
the first '<' and the last '>' as the user email.  If there is no
'<' then the author data is either treated as a name only (if there's
no '@') or an email address only (if it contains an '@').

If there is no name, the part of the email up to the first '@' is used.

The resulting name and email are processed in the same manner as Git
before emitting them into the fast-export output stream.

The same output should be produced as the previous version produced
when that output is something that is valid for a fast-export stream.
Input that would have previously produced invalid fast-export author
data now produces valid output instead.

Some examples that now produce valid output instead of invalid:

  first middle last <fml <at> example.com>
  name <at> loca.tion
  <name>
  <name
  name>
hg2git.py