Blog

Why Jub Jub has been using Mercurial (hg) for Source Control for a few years.

Posted April 23, 2010  |  By Robert Wallis, Senior Developer  |  Filed under: Web Programming


Good websites are software. Software needs source control. Historically developers used CVS and Microsoft Visual SourceSafe (VSS) among others. But they were hard to use, and caused almost more problems than they were worth. So lots of amateur developers decided to just not use source control. The some really smart people decided to replace CVS with Subversion (SVN), and it was great. You didn't have to "check out" code to work on it, and you could branch code and everything and it was sweet. So all us good developers said "Hay Oh" and stuck all our projects into SVN. We looked back on all the bad times with VSS and CVS and were so impressed. So impressed and proud of ourselves for learning something new that we didn't even see the problems. But someone did. Actually a few people did. And in 2005, two new source control packages appeared, Mercurial and Git. But we liked SVN. And it's not like we didn't hear about Mercurial and Git, we heard, but everything is already in SVN, and we have some pretty GUIs, and we don't want to learn some new difficult software.

But that's just the point! SVN is difficult to learn, because it's difficult to use. Remember when it was like, "Awesome!", to learn that SVN can branch code really quickly and you don't have to "check out" to get work done? Well it's just like that using Mercurial or Git instead of SVN. That's why, a few years ago, we starting using Mercurial. Git is another very good source control program but we just picked Mercurial. And both have basically the same principle: there is no main controller. And that concept is so powerful, that it leads to tons productivity. For instance, back in SVN days, we'd inherit a site that was not source controlled, from some amateur developer (usually the company's boss's nephew or something). And now we have to make a change right away, but still keep track of all the stuff we changed. We'd create a new SVN project, copy the files into the folder, add them all, check it into the server. But... then someone would make changes, and they didn't have SVN setup because they weren't in our company, so now we have to figure out what changed because we also made changes and they just overwrote our changes. Basically, we had to merge. That, is a big problem in SVN. ("Oh that's not that hard") someone just said. Well, "somebody" didn't have to deal with files being deleted, new files being created, and files being renamed. If you just delete all the files in your local directory and copy the live files back into your directory, you loose all the nested ".svn" folders. Anyway, there's all kinds of workarounds to the problem, and they all are terrible.

But in Mercurial, it's super easy. Delete everything in the local folder "rm -rf *", copy the new files, and type "hg addremove". Got that? Delete. Copy. "addremove". Very very easy, and the other developer didn't even have Mercurial! If he did have Mercurial it's only one step: "hg pull". Back in the SVN world, you have to have a working internet connection, or a working SVN server, or you can't work efficiently. Using Mercurial, you can check in all the time. Because everyone's computer is like the server. Fix one little thing, check in, write a comment, fix another thing, check in. This method, checking in often, allows you to clear your mind of all the stuff you have to remember. Then when it's time to push to the main server, you have notes already, of everything you've done. With SVN, you have to go through a giant diff and try to think of all the reasons why you did something, and it's out of chronological order, so things get messy. With Mercurial you can quickly experiment and change tons of files. Check in. Then decide that you want to try a different experiment, revert to before you experimented, and write something new. Then revert back again to the old. And all of that is really really easy. You don't have to explicitly copy a branch into a different branch folder on the server. To create a tag, just type "hg tag", you don't have to copy to a tag folder. In Mercurial you can push and pull from anyone. Not just a server. Because everyone is like a server. This means you can create mini tasks forces, two or three people working together on one part of the code, two or three people working on another, and then everyone merges together quickly and easily. If someone doesn't have ssh access to your computer, that's fine, just email them a "bundle", you can spend less time configuring or bootstrapping a project, and more time coding. It's more than just some program to keep track of your software, it's a development methodology that helps you to be productive. Some very smart guy, Joel, and an amazing developer, also recently switched to Mercurial, and he loved it so much, that he made a site answering all your questions: htinit.com. Have you been using SVN and got confused trying to use Mercurial? Is this the first time you've ever used version control? Joel's site answers all your questions. Read it, and then I double dare you to keep using SVN.