[rfc][patch] bzr whoami can set your branch identity

John Arbash Meinel john at arbash-meinel.com
Mon Jan 9 04:18:39 GMT 2006


Robey Pointer wrote:
> This patch stems from an IRC conversation last week, where there was 
> some consensus that 'bzr whoami' ought to be able to set a per-branch 
> identity as well as display it, and that we should try harder when 
> guessing identity from gecos.
> 
> I ran into a few bumps in the patch, so criticism is welcome:
> 
> * Blackbox 'runbzr' assumes that it will be able to log the command-
> line parameters and stdout/stderr output from bzr.  Since the user 
> encoding can be pretty arbitrary, that's a huge leap of faith. :)  My 
> tactic was to have it quote non-ascii characters.  It's just for 
> logging, so hopefully that's good enough.

My encodings branch handles a lot of this. In general, ~/.bzr.log is
utf-8 encoded (which it already was). If mutter() fails with a Unicode
exception, it re-encodes the entire message as escaped ascii (python
repr()). But I would like to see more places that don't want to sanitise
their strings use %r rather than %s for safety.

> 
> * Unless I misunderstood how it works, I think 'whoami' output should 
> be encoded into the user's encoding, so I fixed that.

This might not be bzrlib.user_encoding. It should take
sys.stdout.encoding if it is present. (Again when I finish my encoding
branch, this will be done, I'm through about 1/2 of the commands).

> 
> * When reading the branch's "email" controlfile, no decoding is 
> necessary.  The controlfile API is handling encoding.  (Nice!)

Correct. Any file we create we use utf-8. (or at least we should :)

> 
> * I made a decorator '@with_user_encoding' for running a test with  the
> user's encoding temporarily changed to something else.  (I wanted  to
> test that both ascii and utf-8 would work.)  Is there a better way  to
> do that?  I feel like I probably just overlooked some existing 
> mechanism for testing with a temporary encoding.

Again, in my encoding branch, I have a parameter that you can pass to
run_bzr which sets the encoding.
Oh, and I generally avoid the Blackbox version of 'runbzr'. bzrlib.tests
has a TestCase which has 'run_bzr' which I think has a much nicer
interface. 'runbzr' is just a hangover of when we only had a single
'testbzr' file.

Just to point you to my branch:
http://bzr.arbash-meinel.com/branches/bzr/encoding/

> 
> This patch is against jam-integration because the IRC discussion was 
> with John.  It's not ready for integration and probably needs a bit  of
> discussion, unless you all think I'm right on all the above  points. ;)
> 
> robey
> 

My integration branch is pretty much up-to-date with bzr.dev. I think I
might have 1 or 2 patches extra.

By the way, Apple Mail doesn't seem to do a very good job with
attachments. It attaches your patch as:
application/octet-stream; x-unix-mode=0644; name="whoami.patch"

Since it is application/octet-stream, it won't be previewed in line (at
least in Thunderbird).

Maybe this is intentional because they don't want whitespace to be munged?


Anyway, to discuss you patch...
I would like a way to specify that I want to set the global option. In
fact, I might prefer to have it set the global option, unless I use a
flag to say I want the local one.
For people just getting started, who just had bzr not correctly set
their email. They may have started a branch, and found out that the
email was wrong. So they go to set their email and everything seems
fine, but then when they switch to another branch, their email is
incorrect again.

In this code:
=== modified file 'bzrlib/tests/__init__.py'
--- bzrlib/tests/__init__.py	
+++ bzrlib/tests/__init__.py	
@@ -401,7 +401,7 @@
         """
         stdout = StringIO()
         stderr = StringIO()
-        self.log('run bzr: %s', ' '.join(argv))
+        self.log('run bzr: %s', ' '.join(argv).encode('string-escape'))

Just do:
self.log('run bzr: %r', ' '.join(argv))

%r says to use python's repr() function (representation), which for
strings means it makes them ascii safe.
Basically %r (repr) is meant something like "give me the form that I
would put inside a .py file if I wanted to create this".

John
=:->
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 256 bytes
Desc: OpenPGP digital signature
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20060108/45ca9df0/attachment.pgp 


More information about the bazaar mailing list