[PATCH 8 of 8] changed logmessage() to encode/decode commit messages properly

Alexis S. L. Carvalho alexis at cecm.usp.br
Mon Nov 20 12:22:19 CST 2006


Thus spake Andrey:
> diff -r 02aa0b1fd22e -r 73709ef70e67 mercurial/commands.py
> --- a/mercurial/commands.py	Mon Nov 20 16:35:24 2006 +0600
> +++ b/mercurial/commands.py	Mon Nov 20 16:55:21 2006 +0600
> @@ -24,9 +24,9 @@ def bail_if_changed(repo):
>      if modified or added or removed or deleted:
>          raise util.Abort(_("outstanding uncommitted changes"))
>  
> -def logmessage(opts):
> +def logmessage(ui, opts):
>      """ get the log message according to -m and -l option """
> -    message = opts['message']
> +    message = ui.decode(opts['message'])

This should use "stdio" encoding, no?

>      logfile = opts['logfile']
>  
>      if message and logfile:
> @@ -35,9 +35,9 @@ def logmessage(opts):
>      if not message and logfile:
>          try:
>              if logfile == '-':
> -                message = sys.stdin.read()
> +                message = ui.decode(sys.stdin.read(), 'stdio')
>              else:
> -                message = open(logfile).read()
> +                message = ui.decode(open(logfile).read())
>          except IOError, inst:
>              raise util.Abort(_("can't read commit message '%s': %s") %
>                               (logfile, inst.strerror))

And again, you want to abort if you can't decode the message, instead of
adding garbage to the changelog.

And this gets even better when you want to import a patch...

Alexis


More information about the Mercurial-devel mailing list