watch this The wheels are turning, slowly turning. home
Cleaning Up Branch Checkouts 2012-01-21

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