[PATCH 4 of 6] Add support for username mapping

Brendan Cully brendan at kublai.com
Thu Jun 7 18:09:57 CDT 2007


On Thursday, 07 June 2007 at 23:50, Edouard Gomez wrote:
> # HG changeset patch
> # User Edouard Gomez <ed.gomez at free.fr>
> # Date 1181250965 -7200
> # Node ID 537e4260a38347d32765c8fdfb6510288c0b0698
> # Parent  8b4f7b0f7b0d92883ef7063e8b164f2564cd1716
> Add support for username mapping
> 
> Allows mapping usernames to new ones during conversion process.
>  - Use -A option for first import
>  - Then at the end of the conversion process and if the destination
>    repo supports authorfile attribute, author map content is copied
>    to the file pointed by the authorfile call.
>  - On incremental conversions w/o any -A option specified, the
>    destination authorfile, if any, gets read automatically.
> 
> EG: This allows mapping unix system usernames used in CVS accounts
>     to a more typical "Firstname Lastname <address at server.org>" pair.

> +        authorfile = None
> +        if 'authors' in opts:
> +            authorfile = opts.get('authors')
> +        elif hasattr(dest, 'authorfile'):
> +            authorfile = dest.authorsfile()
> +
> +        try:
> +            afile = open(authorfile, 'rb')
> +            for line in afile:
> +                try:
> +                    self.authors[line.split('=')[0].strip()] = line.split('=')[1].strip()
> +                except IndexError:
> +                    pass
> +            afile.close()
> +        except IOError:
> +           pass

I think using 'if authorfile:' instead of 'try:... except IOError'
might be better. You run a small risk of silently ignoring the author
map in your version.

> +    def writeauthormap(self):
> +        if len(self.authors) > 0 and hasattr(self.dest, 'authorfile'):
> +           ofile = open(self.dest.authorfile(), 'w+')
> +           for author in self.authors:
> +               ofile.write("%s=%s\n" % (author, self.authors[author]))
> +           ofile.close()
> +

This appears to rewrite the authorfile on every run. Shouldn't this
only be done when -A is given on the command line?



More information about the Mercurial-devel mailing list