Bzr-svn: Preserving Commits and Rebasing

Recently I’ve been using bzr-svn when I’m working with subversion repositories; its a bridge between a local bzr repository and a remote subversion one. I travel fairly frequently and the pain of being disconnected from the server, unable to diff or log, and then either unpicking everything I’ve done or sending a monster commit with the message “Things Lorna did in the last 2 days” is just tedious and annoying. Possibly more tedious and annoying for the rest of the team than me even, so a better solution is more than welcome!

Some time ago I blogged about starting to use bzr-svn but its taken me a while to get past those first steps. Having the repo locally is so fast to use, and the speedy diff and log functionality had me completely sold straight away. I’ve been mildly annoyed by bzr squashing my commits though, meaning that I’m still doing a single monster commit to subversion when I come back online after being gone for a few days.

Today, with some help from the very lovely people in the channel on freenode, I found out how to preserve my commit history when sending the changes back to subversion from bzr-svn. The bzr-svn user guide recommends a particular set of commands, but this includes merging your changes into the mirror of SVN. Even in a standard bzr branch, this would show in the logs as a single, combined commit.

Push, Don’t Merge

The key to retaining the commit history is to push changes from the branch, rather than merging into the trunk mirror. To make this clearer, I’ve shown an example. The SVN is checked out into lorna-trunk and I’m making changes in the lorna-branch directory, including adding the db directory and the hello.php file.

$ bzr commit -m "initialising database files and hello.php"
Committing to: /home/lorna/data/personal/publish/tek10/svn_vs_distributed/bzr-svn-example/lorna-repo/lorna-branch/
added db
added hello.php
added db/setup.sql
Committed revision 2.
$ bzr push ../lorna-trunk/
All changes applied successfully.
Pushed up to revision 2.

No matter how many times you commit, when you push, all your changes will be sent to subversion as individual commits in the same way. This will really help me next time I’m offline for a little while!

When There Are Changes In Subversion

Charmingly, while answering my questions to get me this far, the channel inhabitants then immediately explained to me that to handle changes in subversion, I’d have to rebase my branch before I could push my changes. This is because you can only push to a branch that is in sync with where yours was when you started making changes. If you try to push to subversion when there are changes in it, you will see this error:

bzr: ERROR: These branches have diverged.  See "bzr help diverged-branches" for more information.

All I needed to do was to run bzr update in the mirror, and then rebase my branch onto that. At first my system didn’t recognise the rebase command, but this was because I needed to install the bzr-rebase package (called bzr-rewrite in newer versions but bzr-rebase in mine, Ubuntu 9.10 Karmic Koala). Rebasing was easy to do and brings the changes from the repo into your working branch. Here are the commands and how the output looked for me (with shortened paths to make this more readable):

lorna@taygete:~/.../lorna-branch$ cd ../lorna-trunk/
lorna@taygete:~/.../lorna-trunk$ bzr update
+N  readme
All changes applied successfully.
Updated to revision 3.
lorna@taygete:~/.../lorna-trunk$ cd ../lorna-branch/
lorna@taygete:~/.../lorna-branch$ bzr rebase ../lorna-trunk/
All changes applied successfully.
Committing to: /home/lorna/.../lorna-branch/
modified hello.php
Committed revision 4.
lorna@taygete:~/.../lorna-branch$ bzr push ../lorna-trunk/
All changes applied successfully.
Pushed up to revision 4.

I haven’t had a lot of experience with using this in difficult situations with complex branching or conflicts yet, if you have any tips to add though, a comment would be excellent :)

svn+ssh with specific identity file

Here is a quick howto on using a config file to associate an SSH connection with a particular identity file. When I ssh directly from the command line, I can specify the port, identity file to use, and a whole raft of other options. However these options aren’t available when checking out from subversion using svn+ssh, and I needed to specify a particular private key to use. These instructions are for my kubuntu 9.10 installation but should work on every flavour of *nix as far as I know.

I was trying to check out using something like this:

svn co svn+ssh://[email protected]/desired/path

To do this, I created this file: ~/.ssh/config and in it I put the following:

host lornajane
HostName svn.example.com
IdentifyFile /path/to/private_key

Now I update my checkout syntax to make use of my alias rather than specifying the host directly, like this:

svn co svn+ssh://lorna@lornajane/desired/path

SSH realises that it should pull the host information from your local config file, and uses your HostName, IdentityFile and any other settings you specify (there are many options, see this reference for more information. For example I often use this for port numbers if I’m tunnelling my SSH between places, the possibilities are endless.

Hope this helps, if you’ve got anything to add then I’d be delighted to see a comment from you.

Book Review: Making it Big in Software

Recently the kind folks at Prentice Hall contacted me to ask if I’d like to read a new publication of theirs , “Making it Big in Software“. It sounded like something I’d be interested in and the copy duly arrived. My first impressions were of a wordy book, very much aimed at large organisations, or those working in academia. And although I’m 20-something myself, the advice in the first sections of the book is aimed more at students or recent graduates than, I felt , at me.

Moving on into the book I found more that applied to me, including some great advice on communicating in different settings and with different types of people. I was also interested to find some thoughts on debugging as a skill to be used instead of, or before, launching a built-in debugger. This makes sense to me because my first programming languages weren’t the kind that have IDEs or other advanced tools.

The chapter on time management starts with the words “if you only read one chapter in this book, this should probably be the one” – and I must say I agree. I consider myself to be organised but there were some great strategies outlined in that particular chapter. Also running through the book like a thread is a series of interviews with software luminaries, each of whom were asked mostly the same questions, including how they manage their time and work-life balance. So there were some real-life stories in there too – I was encouraged that almost all of the people interviewed said they didn’t think they found balance, because personally I know I haven’t.

The interviews provided a great structure on which to hang a book full of good advice. One chapter advises how to identify and avoid “career killers” – those dead-end projects that will hold up your progression. Later on the focus moves away from the big organisation that the author and interviewees have most experience of, to look at starting software companies and the skills and attitude needed for this. Certainly once I got past the first third of the book I was much more drawn in; maybe because that dealt with an early stage of career that I felt I had already mudddled through?

Overall this is quite a dense book to read over a short period of time, but an excellent one to keep around and dip into or read another chapter every few weeks perhaps. Certainly its one that will be going on my bookshelf for me to look back at and refresh my thoughts on various topics covered for some time to come.

WordPress Plugin for Joind.In

In case anyone thinks I’ve gone joind.in crazy after already writing about its import functionality this week, I really haven’t. Its just that some months of pulling a few things together have finally bourne fruit and so I can actually write about them now they are done! The good news is that this includes a plugin for wordpress, which pulls data from the joind.in website. You can find its official page on the wordpress plugin directory here: http://wordpress.org/extend/plugins/joindin-sidebar-widget/

Plugin Features

At the moment the plugin can display one of two data sets: The hot events on joind.in; or the talks from an event on joind.in. You can change the title on the block, limit the maximum number of records returned, specify which event the talks should come from and also indicate if you’d like the order randomised. You can see the plugin in action on techPortal, where it is picking a few sessions at this year’s Dutch PHP Conference to tempt you with!

Technical Information

I hadn’t written a wordpress plugin before although I was very familiar with the joind.in API and how to work with it from PHP. The plugin was relatively easy to write, there are plenty of tutorials on the web and I didn’t need to do anything particularly clever. I looked at a twitter plugin, tweetblend, which was a similar sort of idea in that it had settings, talked over an API, and stored data, and used that when I got stuck. My plugin is much simpler but that’s OK (and probably makes it a good example for me next time I want to write one of these things!!)

The plugin creates a database table when it is activated (and drops it when deactivated) which caches the data pulled from joind.in for a few minutes. This helps avoid lots of users having to wait for the data to load and also hopefully stops the plugin from pushing too much load to the joind.in servers. Since there is no limit or pagination on the joind.in API, even though only a few records are shown the whole result is cached. This means that if you turn on the randomise then the cache is still useful! The “random” is a bit contrived in that it just picks elements out of the array that haven’t been used but it looks fine to me.

Initially I was just going to put something together and upload it to the techportal site but I was persuaded that it would be a useful thing to share – so there it is. Comments and suggestions are all welcome – and if you are using it to publicise your event, let me know!

Importing Data to Joind.In

Update! This post is now outdated – the import functionality on joind.in has been replaced with a CSV import.

As a conference organiser I work extensively with the site joind.in, which allows attendees to comment on sessions at a conference. Recently the site has also started supporting sessions with both times and tracks, making it indispensable as a way of keeping track of all the sessions during an event. The only downside is entering all the data into it!! Joind.in does have some import functionality, which I recently rebuilt to reflect the timings and track changes, however this only accepts XML at present, so there is still some preparation work to get your data ready to import.

I know I’m not the only conference organiser who will have this problem so here’s my step-by-step guide to getting talk information into joind.in, easily and quickly. For up-to-date documentation on the joind.in import process and the official data format description, see http://joind.in/about/import.

Set up Event and Tracks

Step one is to submit your event to joind.in. When it is approved by the administrators you will receive notification and it will appear publicly on the site (joind.in also supports private events, see the website for more information).

Once it is approved, make sure the timezone is set correctly by editing your event. For me this is Europe/Amsterdam, since I’m setting up data for the Dutch PHP Conference.

If you are going to include information about the different tracks, either rooms or subject tracks, you can set these up now (if not, then skip to the next section). When viewing an event, if you are logged in and have admin rights on that event, you will see an “Event Admin” box. The “Event Tracks” screen will let you add, edit and remove the tracks for your event.

Prepare Your Data

I had the talks in a spreadsheet and I found this was a good starting point. Each row is imported independently so each one needs to contain all the information about the session. My spreadsheet had the following columns:

  • Date
  • Time
  • Track (string name matching the track you set up earlier)
  • Type (either “Social Event”, “Talk”, “Keynote”, or “Workshop”)
  • Speaker
  • Session
  • Abstract

There was a lot of duplication here, for example lots of copied and pasted dates, but for each row to be evaluated separately, we need it to look like this. At this point I exported the spreadsheet to .csv format but joind.in currently only supports XML so I still had to built the format it could understand.

Generate the XML

I wrote a little script that processed my CSV file and spat out the XML that joind.in was expecting. There are a few pitfalls with this step:

  • I’m British, so my date formats assume dd/mm/yyyy
  • The import doesn’t support languages (see http://github.com/enygma/joind.in/issues#issue/91)
  • The script contains a function copy/pasted out of the joind.in codebase to handle the timezones calculation (because I already had it working once, I just stole it)
  • The first row in the spreadsheet is assumed to contain titles and is ignored
  • The script has a hardcoded timezone in it for Europe/Amsterdam

By now you can guess this use-once script is a bit of a mess but in case it is useful I am uploading it here (if nothing else, I guess I might use it again!). I considered adding support for CSV files into joind.in itself (I’m a contributor) but I was short on time – if this would be useful to you or if you have any other comments on the process then add them here and I will do my best to reply!

Resources

  • Conversion script for CSV files to Joind.in XML format (use at your own peril!) csvToXml.txt – change the file extension to .php
  • My original spreadsheet, in case an example is helpful talks.csv – this is the data for DPC 2010

OOP Articles on Think Vitamin

I’ve been working on a series of articles for Think Vitamin, the Carsonified blog, about OOP in PHP5. In fact I’m wildly excited about this, partly because I love to write and partly because its such a cool site to write for! The first two installments are now live:

  • Getting Started with OOP PHP5 – which is a very gentle overview of why OOP is such a buzz word, and shows off some very simple examples on how to begin and what the terms mean
  • Getting Started with OOP PHP5: Part 2 – a follow on post showing constructors, static properties and methods, and also looks at how PHP handles objects.

None of it is rocket science but these are important topics often skated over by writers wanting to get to the complicated bits! Hopefully these posts bridge the gap between the very dated introductory PHP content that is still lying around on the web and the tutorials about shiny new stuff that are more typically found elsewhere. The community over on Think Vitamin is great, the comments and retweets have been very constructive and I’m very excited to be involved.

Publications

I find I’m writing for a few outlets other than just my blog these days and often want to refer people to that content as well, so I’ve added a “Publications” page, linked from the left hand sidebar. This will keep up with the articles I’m posting elsewhere, interviews, and anything else along those lines, all in one place.

Speaking at PHPWM: April 6th

Next week I will be making the trip to my original home town of Birmingham to speak at the PHP West Midlands User Group, on 6th April. They are an active user group and although I haven’t managed to organise myself to attend their meetings before, I do keep meeting their members at other technical events so I know they are a good crowd and I’m looking forward to this! My talk will be “SVN in a Distributed World” – looking at the features of SVN, of the distributed source control solutions, and thinking about whether SVN is now an outdated technology or whether it is still a good choice for source control.

Hope to see you there!

Ada Lovelace Day 2010: Mrs Maginnis

This is a post in celebration of Ada Lovelace Day, recognising women in science and technology. Last year I wrote about Kathy Sierra for Ada Lovelace Day; this year my subject is someone much closer to my own life.

I’d like to write about someone who influenced me greatly – in my choice of study and in my attitude to the gender imbalance in that area and in the industry in which I now work. Mrs Maginnis taught me advanced maths when I was 16-18, and making decisions about my next move. I was educated at an all-girls grammar school, which in some ways was an advantage. The experience of those all-female maths classes taught me a lot about how different women are when they meet their individual challenges in the company of one another.

The classes were very tough academically (as they should be!), and I did struggle during the course. At the start of the summer holiday, Mrs Maginnis handed me a textbook with a list of questions to try, and her phone number. All summer I wrestled those questions, with the occassional phone call for help. I went back to school, completed the year, and left the following summer with two A grades in A-level maths – undoubtedly because of the help and support I had been given by this one teacher. Those two A grades landed me my first choice of university place – I thanked her and off I went.

However, the strong influence of this character has stayed with me long since the memorable day I opened the results envelope. I was headed for a course in Electronic Engineering and Mrs Maginnis had been a Mechanical Engineer herself and I think had a good idea of what lay in store for me. The thing is – I was educated entirely with women … I genuinely did not know that there were subjects that girls just don’t do. So when I arrived at university with my academic grades from the all-girls school, I was confronted by a course that was 95% male and contained mostly people with grades at least as good as mine and usually including more practical subjects such as Electronics, which I hadn’t had the opportunity to study. So it was a struggle from that point of view.

The teacher who had, on paper, taught me maths, had in fact taught me so much more. Even now I sometimes remember stories, anecdotes, and advice that all drifted across the classroom along with the hyperbolic functions and calculus (which is a much more distant memory now). She had been an engineer herself, and through her stories she showed us all how it would be done, something on what to expect and some tips on how to handle it. Even now I don’t think I’ve had a stronger female role model for industry – and she managed all this from academia, when I was a teenager. So – I raise my glass to Mrs Maginnis. Thankyou for all you taught me.

GETting RESTful collections – may I filter?

At work at Ibuildings recently, I’ve been teaching some classes on web services, and its a topic that I’ve spoken about once or twice at conferences. But something has always bothered me, so I find myself in the unusual position of blogging a question.

RESTful collections

So, when you are retrieving information from a RESTful service. You have two options: retrieve a specific resource, whose URL you know; or retrieve a collection, which may contain a list of resources. I’ve also seen some nice ways of filtering collections, by creating kind of “sub collections” or “views”, similar to what twitter does with the URL of lists, for example http://twitter.com/dpcon/speakers10 which is like a filtered list of twitter users.

What if I want to search and sort?

Is it RESTful to add GET parameters to a collection in order to add functionality such as filtering, sorting, or pagination? What I have in mind is a URL that looks something like this:

  • http://example.com/users?orderby=firstname&start=0
  • http://example.com/users?start=0&limit=25
  • http://example.com/users?active=1&orderby=join_date&limit=12

This is what I would do with a search results page in a web application, and I use the same approach to web services which works really well and I recommend it to everyone! But is it RESTful?

I am also wondering where OpenSearch would fit into the answer for all this, I only noticed it recently but the more I look at it the more I think it could be an interesting addition!

Thoughts, links for me to RTFM, and all other additions are welcome in the comments box :)

Big Bed Cushions

This week I finally got around to making the big cushions for our bed. We do have some but they were cheap and are now old – and I reallocated Kevin’s onto my office chair about a year ago. Since we do often read or use the laptops in bed, cushions would be a good thing to have, but I just didn’t have the time to make them! Work was less crazy in February and I found I had the mental space to think of these things, so I bought two big fluffy cushions, and dug out the fabric I had left from making the curtains so that the cushions would match, and here they are:

New Bed Cushions

The cushions were 66cm so I cut two rectangles that were (66cm plus seam allowance) wide and ((2.5 * 66cm) plus seam allowance) long. Then I hemmed across the short sides (this was really fraying fabric, I should have overstitched everything before I started but I was too impatient!). They are simple envelope-backed cushions so I lay them on the floor with the right side up, folded the long sides at 33cm and then 99cm, basically you have a short end folded up and then the long end folded over that, with the seams showing. Then you sew up the sides and when you turn it the right way out – the short bit of the envelope is on the outside.

Dead simple but they match the curtains and they are lovely and soft – the fabric is plain sheeting too so nice and comfortable even in bed!