Installing Bazaar (bzr) Locally on a Web Host
Context
Bazaar (bzr) is a nifty version control system. I’m still a fan of subversion (svn), but there are things that svn just won’t do. For instance, if you want to publish your code to the open world, with svn, you end up with two options:
- You host it yourself on a dedicated server
- You have it hosted on either a paying site or for free (e.g. on SourceForge or Google Code)
I’ve been using the first solution for a while (got a dedicated server running in my closet with a dynamic dns), but I was at a point where I wanted to allow faster access to the repository. I host sample code that I give to my students, and when they’re all accessing the files at the same time, my internet connection is just not enough. On the other hand, I have a web host, so I figured this is where the repository should be. Except, my web host does not support subversion.
Why Bazaar
Bazaar is lightweight and decentralized. That’s what caught my attention. It’s meant to be used as a distributed version control tool – meaning it can be used in a decentralized manner. You checkout a branch anonymously, you work in it, you can commit changes to your local branch. Once you’re done, you can push back to the remote branch. Or, you can have other people checkout from your local branch and they can work on their side. The best part (as far as I was concerned): pushing a branch can be done over sftp, pulling a branch can be done over http. The server does not need to know anything about Bazaar. For instance. You have a server on which you have ssh access and a web page (e.g. at school).
Basics
You can create a new repository with a cpp file in it:
1 2 3 4 5 6 7 8 9 10 11 12 | $~>mkdir myproject $~>cd myproject $myproject>bzr init Created a standalone tree (format: pack-0.92) $myproject>ls -a . .. .bzr $myproject>touch main.cpp $myproject>bzr add main.cpp adding main.cpp $myproject>bzr ci main.cpp -m "my first revision" added main.cpp Committed revision 1. |
Notice the .bzr directory where Bazaar will keep information about this repository.
Then, you’ll want to host this branch on your remote server. You do that by pushing your branch:
1 2 | $myproject>bzr push sftp://mylogin@myserver.com/~/public_html/mybzrdir Pushed up to revision 1. |
If mybzrdir is accessible from the web, people can now checkout (bzr calls it branching) from your repository:
1 2 3 4 | $~>bzr branch http://myserver.com/~mylogin/mybzrdir Branched 1 revision(s). $~>ls -a mybzrdir/ . .. .bzr main.cpp |
There you go. You have a local branch of your remote repository (the server branch). You can work in it, even commit changes (bzr ci) and eventually, diff from the original branch and send the patch to the owner or, if you have access to the server branch, push it back with your local changes.
Identifying yourself
Since Bazaar works anonymously, you’ll want to identify yourself when you make changes to the branches. This is slightly different from most other revision control tools that I’ve used where you have an explicit login which is used both for access and identification. Anonymous access with the other tools that I’ve used meant you had a dead branch. You could still updated it, but you could not commit your changes. With Bazaar, you can work in your local branch, even if it was checked out anonymously.
When you are about to commit changes, you use the “whoami” command to tell who you are:
1 2 3 4 | $myproject>bzr whoami "John Doe " $myproject>bzr whoami John Doe $myproject>bzr ci -m "my changes" |
By default, whoami will try to use the name associated with your login. This is usually fine, but the email it will guess is most likely not the one you want to use (e.g. you@localhost).
Installing
Local Install on a Web Host
Here are the steps that I followed to install bzr locally (in my user directory without root access) without using gcc.
Although you do not need to install it on your server, I still wanted to. The reason being that I cannot find any decent cgi that will let me browse the content of my bzr repository from the web. The easiest way is to install bzr and have it used by a script query and stat your repository from your web page.
So again, you do not need to install bzr on the server (for me, that was the whole point of using Bazaar in the first place). Still here’s how I got it to install:
1. Log on to Your Server
1 | ssh myserver |
2. Get the Source
The source code is available from theBazaar Download page at http://bazaar-vcs.org/Download. Under “Source of the stable release for any platform”, you’ll find a link to the source code:
1 2 3 4 5 | $server:~>mkdir bzr-temp $server:~>cd bzr-temp $server:bzr-temp>wget http://launchpad.net/bzr/2.0/2.0.5/+download/bzr-2.0.5.tar.gz $server:bzr-temp>tar -zxvf bzr-2.0.5.tar.gz $server:bzr-temp>cd bzr-2.0.5 |
3. Compile the Source Locally Without gcc
My server does not give me access to gcc (they don’t really want me to start programming on the web server, I guess installing custom software, even locally, is borderline…).
Usually, to install locally (in $HOME), you’d simply run the following command:
1 | $server:bzr-2.0.5>python setup.py install --home $HOME |
But in this case, I ended up with
1 2 3 4 5 6 7 | gcc -pthread -fno-strict-aliasing -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fPIC -I/usr/include/python2.4 -c bzrlib/_annotator_pyx.c -o build/temp.linux-x86_64-2.4/bzrlib/_annotator_pyx.o unable to execute gcc: Permission denied Cannot build extension "bzrlib._annotator_pyx". Use "build_ext --allow-python-fallback" to use slower python implementations instead. error: command 'gcc' failed with exit status 1 |
Since gcc cannot be used, we’ll have to run the “slower” python implementation. This was achieved by adding the suggested arguments:
1 | $server:bzr-2.0.5>python setup.py install --home $HOME build_ext --allow-python-fallback |
This compiled and installed successfully.
4. Set the PYTHONPATH Environment Variable
Running “bzr” from the command line, I’d get the following error:
1 2 3 4 5 6 7 8 | $server:~>bzr bzr: ERROR: Couldn't import bzrlib and dependencies. Please check the directory containing bzrlib is on your PYTHONPATH. Traceback (most recent call last): File "/home2/enseed/bin/bzr", line 107, in ? import bzrlib ImportError: No module named bzrlib |
All you need to do is add the path to your local python libraries to the PYTHONPATH environment variable. This can be done in your .bashrc by adding an export directive
1 | export PYTHONPATH=~/lib64/python/ |
(in your case, it might be at some other place than lib64, check it up)
Or, simply define the variable when you execute bzr:
1 | $server:~>PYTHONPATH=~/lib64/python/ bzr |
Installing on Mac OS X
I used fink to install bzr on mac:
1 2 | $~>fink install bzr-py25 $~>fink install paramiko-py25 |
I did not install bzr-py26 becase paramiko, which is used by bzr for for ssh connections, was not available (at the time of this writing) for python 2.6.
Installing on Ubuntu
On Ubuntu, it was relatively painless to install:
1 | $~>sudo apt-get install bzr |
