[PATCH 4 of 6] Add support for username mapping

Alexis S. L. Carvalho alexis at cecm.usp.br
Thu Jun 7 18:56:48 CDT 2007


Thus spake Edouard Gomez:
> # HG changeset patch
> # User Edouard Gomez <ed.gomez at free.fr>
> # Date 1181250965 -7200
> # Node ID 537e4260a38347d32765c8fdfb6510288c0b0698
> # Parent  8b4f7b0f7b0d92883ef7063e8b164f2564cd1716
> Add support for username mapping

> @@ -550,6 +554,23 @@ class convert(object):
>              origmapfile.close()
>          except IOError:
>              pass
> +
> +        authorfile = None
> +        if 'authors' in opts:
> +            authorfile = opts.get('authors')
> +        elif hasattr(dest, 'authorfile'):
> +            authorfile = dest.authorsfile()
> +
> +        try:
> +            afile = open(authorfile, 'rb')

You're reading the file in binary mode, but writing it in text mode.

I guess this doesn't really matter even on windows, since you're calling
.strip() below, but it'd be better to be consistent.

And it'd be nice to be consistent with the mapfile (which is using text
mode).

> +            for line in afile:
> +                try:
> +                    self.authors[line.split('=')[0].strip()] = line.split('=')[1].strip()

Please split this into parsing the line and adding to self.authors -
this way things should fit in 80 columns. :)

> @@ -633,6 +654,13 @@ class convert(object):
>          self.mapfilefd.write("%s %s\n" % (src, dst))
>          self.mapfilefd.flush()
>  
> +    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()
> +

As Brendan noticed, it'd be nice to write the file only if -A was
specified.  As it is, if you're very unlucky, you can lose your file if
you press CTRL-C at the wrong time.

The help text should mention the format of this file.  And maybe
writeauthormap should say something like "Saving author map to %s.\nIt
will be automatically used on the next run if -A is not specified.\n"

Alexis


More information about the Mercurial-devel mailing list