Saturday, January 21, 2012

Cleaning Up Branch Checkouts

Since Twisted development typically involves at least one branch per ticket, a Twisted developer can end up with a lot of branches checked out.  For example, this morning I had 177 Twisted branches checked out on my laptop.  Many of these were branches that I contributed code to, and perhaps even merged into trunk myself when they were complete.  I could probably have deleted them at that point, but I usually can't be bothered.  Besides, I put everything I have into the branch itself, by the time I'm merging it I'm done.  Other branches are ones I've done code reviews on for other developers.  I don't keep track of when these get merged into trunk as closely, since typically someone else is going to do those merges.

The incremental cost of another Twisted branch is pretty minimal.  A few more megs used on my hard drive is barely noticable.  The aggregate cost can get pretty high though (Seven GB for the 177 branches I had this morning).  At some point this can cause problems.

Not all of these branches have been merged to into trunk, either, or I could just wipe them all out with ease.  And while I try never to leave uncommitted changes in a branch checkout, nobody's perfect...  What I really want to do is just get rid of the branches that just aren't relevant anymore.

So I use cleanup-local.py to deal with the mess.  It looks at my branch checkouts, talks to the Twisted issue tracker to learn the state of the associated ticket (due to the naming convention for Twisted branches, it is easy to determine which ticket is associated with a branch, given just the branch name).  Then it deletes all the checkouts associated with closed tickets (due to the Twisted workflow, if a ticket is closed, it is a very safe bet that you won't need its branch anymore).

The net result is that in (far) less time than it took to write this post, my laptop went from having 177 Twisted branches to having just 34.  To save even more time, I could probably set this up as a weekly cron job or something similar.  It's easy enough to run now, though, that I just do so manually once every couple of months to keep things tidy.

Here's a brief snippet from today's run:

Found password-comparison-4536-2 for ticket(s): 4536
Status of 4536 is assigned
Found pb-chat-example-4459 for ticket(s): 4459
Status of 4459 is closed
Removing closed: pb-chat-example-4459
Found plugin-cache-2409 for ticket(s): 2409
Status of 2409 is closed
Removing closed: plugin-cache-2409
Found poll-default-2234-2 for ticket(s): 2234
Status of 2234 is closed
Removing closed: poll-default-2234-2

Tuesday, January 10, 2012

Learn About Twisted at PyCon 2012

At PyCon this year I'll be presenting a tutorial to introduce Python programmers to Twisted. This tutorial has two goals. First, to give attendees a firm grasp of Twisted's concurrency model, both in the abstract and the concrete. Second, to remove the mystery around the tools Twisted provides for developing robust, testable concurrent applications. If you attend, you'll come away with an understanding of how event loops work and how to write code that works best in Twisted's event loop.

I am a long time core Twisted developer with real world experience building maintainable, scalable systems with Twisted. I've also presented similar introductory Twisted tutorials several times in the past, letting me learn the common sticking points and teaching approaches to help overcome them.

Check out the tutorial's page on the PyCon 2012 website for details about what will be covered. Come learn how to leverage Twisted and Twisted-based libraries to their fullest extent!