From a6d7ba7bf2710372083b05cd430420782197bc5d Mon Sep 17 00:00:00 2001 From: mhagger Date: Mon, 8 Mar 2010 15:44:42 +0000 Subject: [PATCH] Allow DVCS author_transforms values to be specified as pre-formatted strings. Treat tuples as before, but allow string values as an alternative. (Strings are easier to handle, for example, when reading author_transforms from a text file.) git-svn-id: http://cvs2svn.tigris.org/svn/cvs2svn/trunk@5069 be7e6eca-30d4-0310-a8e5-ac0d63af7087 --- cvs2bzr-example.options | 19 ++++++++++--------- cvs2git-example.options | 15 ++++++++------- cvs2hg-example.options | 17 +++++++++-------- cvs2svn_lib/dvcs_common.py | 34 +++++++++++++++++++++++++++------- cvs2svn_lib/git_output_option.py | 7 ++++--- 5 files changed, 58 insertions(+), 34 deletions(-) diff --git a/cvs2bzr-example.options b/cvs2bzr-example.options index 1930a874..1508bc0e 100644 --- a/cvs2bzr-example.options +++ b/cvs2bzr-example.options @@ -445,23 +445,24 @@ ctx.retain_conflicting_attic_files = False # CVS uses unix login names as author names whereas Bazaar requires # author names to be of the form "foo ". The default is to set -# the Bazaar author to "cvsauthor ". author_transforms can be -# used to map cvsauthor names (e.g., "jrandom") to a true name and +# the Bazaar author to "cvsauthor ". author_transforms can +# be used to map cvsauthor names (e.g., "jrandom") to a true name and # email address (e.g., "J. Random " for the -# example shown). All values should be either Unicode strings (i.e., -# with "u" as a prefix) or 8-bit strings in the utf-8 encoding. -# Please substitute your own project's usernames here to use with the -# author_transforms option of BzrOutputOption below. +# example shown). All strings should be either Unicode strings (i.e., +# with "u" as a prefix) or 8-bit strings in the utf-8 encoding. The +# values can either be strings in the form "name " or tuples +# (name, email). Please substitute your own project's usernames here +# to use with the author_transforms option of BzrOutputOption below. author_transforms={ 'jrandom' : ('J. Random', 'jrandom@example.com'), - 'mhagger' : ('Michael Haggerty', 'mhagger@alum.mit.edu'), + 'mhagger' : 'Michael Haggerty ', 'brane' : (u'Branko Čibej', 'brane@xbc.nu'), - 'ringstrom' : ('Tobias Ringström', 'tobias@ringstrom.mine.nu'), + 'ringstrom' : 'Tobias Ringström ', 'dionisos' : (u'Erik Hülsmann', 'e.huelsmann@gmx.net'), # This one will be used for commits for which CVS doesn't record # the original author, as explained above. - 'cvs2svn' : ('cvs2svn', 'admin@example.com'), + 'cvs2svn' : 'cvs2svn ', } # This is the main option that causes cvs2svn to output to a diff --git a/cvs2git-example.options b/cvs2git-example.options index edfdeb2f..8a3594e0 100644 --- a/cvs2git-example.options +++ b/cvs2git-example.options @@ -476,20 +476,21 @@ ctx.retain_conflicting_attic_files = False # the git author to "cvsauthor ". author_transforms can be # used to map cvsauthor names (e.g., "jrandom") to a true name and # email address (e.g., "J. Random " for the -# example shown). All values should be either Unicode strings (i.e., -# with "u" as a prefix) or 8-bit strings in the utf-8 encoding. -# Please substitute your own project's usernames here to use with the -# author_transforms option of GitOutputOption below. +# example shown). All strings should be either Unicode strings (i.e., +# with "u" as a prefix) or 8-bit strings in the utf-8 encoding. The +# values can either be strings in the form "name " or tuples +# (name, email). Please substitute your own project's usernames here +# to use with the author_transforms option of GitOutputOption below. author_transforms={ 'jrandom' : ('J. Random', 'jrandom@example.com'), - 'mhagger' : ('Michael Haggerty', 'mhagger@alum.mit.edu'), + 'mhagger' : 'Michael Haggerty ', 'brane' : (u'Branko Čibej', 'brane@xbc.nu'), - 'ringstrom' : ('Tobias Ringström', 'tobias@ringstrom.mine.nu'), + 'ringstrom' : 'Tobias Ringström ', 'dionisos' : (u'Erik Hülsmann', 'e.huelsmann@gmx.net'), # This one will be used for commits for which CVS doesn't record # the original author, as explained above. - 'cvs2svn' : ('cvs2svn', 'admin@example.com'), + 'cvs2svn' : 'cvs2svn ', } # This is the main option that causes cvs2svn to output to a diff --git a/cvs2hg-example.options b/cvs2hg-example.options index 715cb1f4..cd8fa8f0 100644 --- a/cvs2hg-example.options +++ b/cvs2hg-example.options @@ -444,21 +444,22 @@ ctx.retain_conflicting_attic_files = False # default is to set the author to "cvsauthor ". # author_transforms can be used to map cvsauthor names (e.g., # "jrandom") to a true name and email address (e.g., "J. Random -# " for the example shown). All values should be -# either Unicode strings (i.e., with "u" as a prefix) or 8-bit strings -# in the utf-8 encoding. Please substitute your own project's -# usernames here to use with the author_transforms option of -# GitOutputOption below. +# " for the example shown). All strings should +# be either Unicode strings (i.e., with "u" as a prefix) or 8-bit +# strings in the utf-8 encoding. The values can either be strings in +# the form "name " or tuples (name, email). Please substitute +# your own project's usernames here to use with the author_transforms +# option of GitOutputOption below. author_transforms={ 'jrandom' : ('J. Random', 'jrandom@example.com'), - 'mhagger' : ('Michael Haggerty', 'mhagger@alum.mit.edu'), + 'mhagger' : 'Michael Haggerty ', 'brane' : (u'Branko Čibej', 'brane@xbc.nu'), - 'ringstrom' : ('Tobias Ringström', 'tobias@ringstrom.mine.nu'), + 'ringstrom' : 'Tobias Ringström ', 'dionisos' : (u'Erik Hülsmann', 'e.huelsmann@gmx.net'), # This one will be used for commits for which CVS doesn't record # the original author, as explained above. - 'cvs2svn' : ('cvs2svn', 'admin@example.com'), + 'cvs2svn' : 'cvs2svn ', } # This is the main option that causes cvs2svn to output to an "hg diff --git a/cvs2svn_lib/dvcs_common.py b/cvs2svn_lib/dvcs_common.py index 80464096..0b819b5c 100644 --- a/cvs2svn_lib/dvcs_common.py +++ b/cvs2svn_lib/dvcs_common.py @@ -109,16 +109,36 @@ class DVCSOutputOption(OutputOption): self._symbolings_reader = None def normalize_author_transforms(self, author_transforms): - """Return a new dict with the same content as author_transforms, but with - all strings encoded to UTF-8 and the (name, email) tuple turned into a - string. Also turns None into the empty dict.""" + """Convert AUTHOR_TRANSFORMS into author strings. + + AUTHOR_TRANSFORMS is a dict { CVSAUTHOR : DVCSAUTHOR } where + CVSAUTHOR is the CVS author and DVCSAUTHOR is either: + + * a tuple (NAME, EMAIL) where NAME and EMAIL are strings. Such + entries are converted into a UTF-8 string of the form 'name + '. + + * a string already in the form 'name '. + + Return a similar dict { CVSAUTHOR : DVCSAUTHOR } where all keys + and values are UTF-8-encoded strings. + + Any of the input strings may be Unicode strings (in which case + they are encoded to UTF-8) or 8-bit strings (in which case they + are used as-is). Also turns None into the empty dict.""" + result = {} if author_transforms is not None: - for (cvsauthor, (name, email,)) in author_transforms.iteritems(): + for (cvsauthor, dvcsauthor) in author_transforms.iteritems(): cvsauthor = to_utf8(cvsauthor) - name = to_utf8(name) - email = to_utf8(email) - result[cvsauthor] = "%s <%s>" % (name, email,) + if isinstance(dvcsauthor, basestring): + dvcsauthor = to_utf8(dvcsauthor) + else: + (name, email,) = dvcsauthor + name = to_utf8(name) + email = to_utf8(email) + dvcsauthor = "%s <%s>" % (name, email,) + result[cvsauthor] = dvcsauthor return result def register_artifacts(self, which_pass): diff --git a/cvs2svn_lib/git_output_option.py b/cvs2svn_lib/git_output_option.py index c60a7574..9fc7e824 100644 --- a/cvs2svn_lib/git_output_option.py +++ b/cvs2svn_lib/git_output_option.py @@ -148,9 +148,10 @@ class GitOutputOption(DVCSOutputOption): git-fast-import commands for defining revisions will be written. - author_transforms -- a map {cvsauthor : (fullname, email)} from - CVS author names to git full name and email address. All of - the contents are 8-bit strings encoded as UTF-8. + author_transforms -- a map from CVS author names to git full name + and email address. See + DVCSOutputOption.normalize_author_transforms() for information + about the form of this parameter. """ -- 2.11.4.GIT