From the Canyon Edge -- :-Dustin

Monday, January 16, 2012

Automatically Swapping Launchpad and Bazaar Identities


I've been a Launchpad.net member since 2006-10-11, when I first created an account to add some debugging information and submit a patch to a bug affecting the xserver on iMac G3s and the Ubuntu 6.06 PowerPC LiveCD, which my wife, Kim, used in her 4th grade classroom.  Wow, those were the days!  I see that that bug is still open :-)  I can't imagine that hardware is even functional anymore....is it?


I was thoroughly impressed with the shear elegance, look, feel, and usability of Launchpad.net.  I was a long time user of SourceForge.net and Bugzilla, and had brushed by at least a dozen other bug trackers.  No other bug tracker or source code system could hold a candle to Launchpad, in my opinion.

In my ~4 years at Canonical, Launchpad.net and Bazaar became the cornerstone and foundation of my day to day development and productivity.  I was absolutely thrilled when Launchpad was open sourced (to relatively little fanfare, sadly).


I've filed and fixed a few minor issues, and worked around some others, and leveraged Launchpad for tools of my own (like ssh-import-id).  And today, I still think Launchpad.net and Bazaar are the best combination of bug tracking, source code management, binary package builders, team building, blueprint tracking out there!

I continue to use Launchpad and Bazaar to manage more than two dozen open source projects.  And now, we're also using commercial Launchpad here at Gazzang now, actively committing to both public and private projects every day.

This introduced a new challenge, for me, though.  I want to make ensure that my commits to Bazaar when I'm "at the office" and working on Gazzang projects are correctly credited to my work email address and identity, and otherwise, they're credited to my personal email address.

This email address is stored in ~/.bazaar/bazzar.conf.  For me, the logic is pretty easy...  I generally work from the office where we have a (mostly) static IP address.  I simply run a cronjob every five minutes that checks my external IP address, and updates ~/.bazaar/bazzar.conf accordingly.  Your logic might differ (perhaps time of day, etc.).  Does anyone know how I might perhaps hook bzr to check the project's name at commit time?  Also, any ideas about how to update $DEBEMAIL in a similar manner?  It's an environment variable, so it's pretty hard/impossible to update that in all of my shells and byobu sessions/windows/splits, and the Debian maintainer rejected a few requests to support $DEBEMAIL in ~/.devscripts.  Other ideas?

My script currently looks something like this:

#!/bin/sh
# $HOME/bin/update-email
work_email="dustin.kirkland@work.example.com"
home_email="dustin@home.example.com"

work_ip="10.9.8.7"
current_ip=$(wget -q -O- http://v4.ipv6-test.com/api/myip.php 2>/dev/null)

if [ "$current_ip" = "$work_ip" ]; then
        sed -i -e "s/<.*>/<$work_email>/g" $HOME/.bazaar/bazaar.conf
else
        sed -i -e "s/<.*>/<$home_email>/g" $HOME/.bazaar/bazaar.conf
fi

And it runs in this cronjob:
*/5 * * * *  run-one $HOME/bin/update-email

Suggestions for improvement?  Leave a note!

Enjoy!
:-Dustin

11 comments:

  1. In my everyday Debian/private/work life, I use zsh with this: https://github.com/aptituz/zsh/blob/master/directory-based-environment-configuration
    And having profiles for ~/, ~/Work and ~/Debian. There should be something similar for bash too. But hey, best moment to try the magic of zsh :)

    ReplyDelete
  2. PS: your comment form sucks when blocking 3rd party cookies. doesnt work and doesnt give a error :/

    ReplyDelete
  3. It may seem mad but... have two users on your computer. Log into your work user when doing work and log into your personal user when doing personal code.

    ReplyDelete
  4. bzr whoami --branch :P

    ReplyDelete
  5. You can update your whoami just on a single branch:

    bzr --branch whoami "Blah Blah "

    This will allow each branch to have a different identity.

    ReplyDelete
  6. I think you mean ~/.bazaar/bazaar.conf rather than ~/.bazaar/bazzar.conf :-)

    ReplyDelete
  7. I've hit the same issues too - I'd like to distinguish commits to bzr.dev I make in my spare time and commits I make in Canonical's time.

    Vincent Ladeuil has been working on improving Bazaar's configuration system, and in 2.5 it should be possible to install a trivial bzr plugin that provides a dynamic configuration option, based on whatever parameters. In my case I would probably use the time of day.

    Here's a quick example plugin (requires lp:~jelmer/bzr/config-option-override, which hasn't been merged yet): http://pastebin.ubuntu.com/806793/

    Note that this overrides the fallback, it won't be called if BZR_EMAIL is set or if you have 'email' configured in your bazaar.conf.

    ReplyDelete
  8. I do things like this with workit:
    https://github.com/mitechie/workit

    It's basically a rip of virtualenv wrapper hacked (not everything works) to allow postactivate scripts to run on any project directory I want. So I'd swap the files out or change them as I hop from project to project. It requires you to run:

    workit somedir

    but something like that might be able to fit into your workflow.

    ReplyDelete
  9. You can configure your identity based on the directories you are in, as well. ~/.bazaar/locations.conf

    So you can have:
    [/home/user/work_stuff/]
    email_address = ...

    [/home/user/play_stuff/]
    email_address = ...


    I'm not 100% sure if the Launchpad login stuff works the same, but that is how I would set things up. (You can also do 'bzr whoami --branch' to set it for a single branch, but at least *I* usually have a lot of branches, so doing it at a directory level works best for me.)

    ReplyDelete
  10. Nice idea. How about putting this script in /etc/network/if-up.d so it gets called dynamically?

    ReplyDelete
  11. Maybe you could use "bzr whoami --branch" to setup different identities for work and home projects?

    ReplyDelete

Please do not use blog comments for support requests! Blog comments do not scale well to this effect.

Instead, please use Launchpad for Bugs and StackExchange for Questions.
* bugs.launchpad.net
* stackexchange.com

Thanks,
:-Dustin

Printfriendly