Sunday, February 13, 2011

How to use Bitbucket's free private Mercurial repositories with Git

Update: Since I wrote this post, bitbucket has added native Git support. Are you spotting a pattern here? Anyway, I'll leave the rest of the post here for the historians.

When Atlassian bought bitbucket in September 2010 one of the first things they did was to allow single users an unlimited amount of private repositories for free. If you want to create an backup of your own code without making the source available this seems like a difficult offer to beat. I've been using it for some months to do exactly this.
 
The only problem is that bitbucket uses Mercurial, what if you prefer git as your day to day version control? No worries as the Atlassians might say, you can bridge from Git to Mercurial using hg-git and a bit of fiddling. Here's what I did to set this all up, in case I forget later.


I use Ubuntu 10.04 and although hg-git is in the repositories it is an older version. Instead I installed python-dulwich via apt-get install python-dulwich, cloned the repository at https://bitbucket.org/durin42/hg-git and then added a suitable entry to my ~/.hgrc file:
hggit = /path/to/hg-git/hggit
The first gotcha is that hg-git can't clone a local file:// repository. When you try it, you get an error like this:
/tmp$ hg clone file:///home/rich/projects/test destination directory: test importing Hg objects into Git fatal: 'file:///home/rich/projects/test' does not appear to be a git repository abort: the remote end hung up unexpectedly
The workaround is to serve the repositories using the git-daemon and then clone them using the default git network protocol. I have the code I want to back-up in a directory ~/projects, so I start the git daemon to export all of them:
git daemon --verbose --export-all --base-path=~/projects/ --export-all
That is not particularly secure, but it isn't available outside my home network and means I can clone each repository using hg with the hg-git plugin enabled:
hg clone git://localhost/name name-hg
Once I have a local Mercurial clone, it is easy to set up the push to bitbucket. That is just vanilla Mercurial configuration. In name-hg/.hg/hgrc I added the bitbucket path so the full configuration looks like this:
[paths]
default = git://localhost/name
bb = http://user:password@bitbucket.org/user/project
Now name and project depend on the local name and the remote bitbucket project name, but hopefully you get the idea. I push this out to the server with hg push bb. Next time I want to copy all the changes I've made in the git repository since the last backup, I fire up the git-daemon, sync up the mercurial repository then push out the changes. I have a script that does all this, which boils down to the following:
#!/bin/sh # backup git repos to bitbucket private repos... cd ~/projects git daemon --verbose  --export-all --base-path=~/projects/ --export-all & for name in project1 project2 ; do     # echo "did this once... not needed again"     # hg clone git://localhost/${name} ${name}-hg     cd ~/projects/${name}-hg || exit 1     hg pull || exit 1     hg update || exit 1     hg push bb || exit 1 done
This way I can use git for day to day hacking, and have a secure backup on a server somewhere for if the worst happens.

Saturday, February 05, 2011

Chaos 1.7 and Android Market on the web

I added Chaos 1.7 to the Android Market the other day. It's now passed 3000 downloads and I've had several emails and 5 star reviews from Chaos fans, so I'm pretty pleased that it's gone down that well. The only downer is that it really is for fans only, I just don't have any idea how to teach anyone brought up on modern games how to fight their way through an 8-bit world. Patience is needed, I guess.

This release was the first time I'd linked to the brand new web-based Android Market. Until now I've always pointed to Appbrain. I think Appbrain has been struggling to keep up with the new additions that Google have made - like bigger icons, more screenshots and promo graphics. Appbrain has also had some down time and synchronisation issues, with comments being out of date or not appearing. I'm not sure what will happen to the 'brain. They have done a great service for Android users and it would be sad to see them disappear, but their business model was the classic snatching nickels from the path of an oncoming steamroller. I do hope they stick around, if only to keep Google on their toes.

Anyway, back to Chaos. The changes in this release are:
  • Remember preferences
  • Several performance improvements for better battery life
  • More consistent frame rate on newer Android devices
  • Attack sound no longer plays when sound is disabled in the options
Saving the preferences was suggested in the comments on the Market. I hadn't added it before because I didn't know how to save stuff on Android. Turns out it is really easy and doesn't even need extra permissions. Actually, I'd already learned how to save for the next game I'm doing so a nice bit of "copy paste" later and it was done. Ah, good old copy and paste. The best form of code re-use.

The performance improvements included not redrawing every single square every single frame, which for some reason I was doing before. If you spot any odd graphical artefacts because of this, do let me know.

The frame rate fixes were due to my recent discovery that newer Android devices are locked to a maximum of 30 frames-per-second. Hopefully Chaos now runs at the same speed across the board. If anyone wants to buy me a 2nd generation Android phone to check this on, please get in touch ;-)

The attack sound fix was a silly non-interesting bug. I fixed it ages ago but also got a prod by email to actually release a version with the fix in place.

I've updated the Nintendo DS and GBA versions too. These don't save the preferences, and I haven't tested them on hardware so let me know if they do not work at all. Apart from that, the DS and GBA are compiled with optimizations now (somehow this got lost in the last GBA/DS release) and should go faster. The GBA version was particularly sluggish last time round.