Wednesday, April 22, 2009

Bazaar

Introduction

Bazaar (or bzr) is a project of Canonical to develop an open source distributed version control system that is powerful, friendly, and scalable. ... It is used by Launchpad for managing revisions with packages. If you have never created a Launchpad project because bzr scared you, fear no more!

To get started, you should install the bzr application by running:
Code:
sudo apt-get install bzr
Bazaar relies on SSH keys to transfer files to your Launchpad account. If you don't have a SSH key, you can follow the next steps to get your SSH key on Launchpad. If you already have your SSH key on Launchpad, you can skip this section to "Using Bazaar".

Launchpad / SSH Key

To create your SSH key, open a terminal and run:
Code:
ssh-keygen -t dsa
Leave the first prompt (for the key location) at default, by pressing Enter, then enter a passphrase for your private SSH key. When complete, run:
Code:
cat ~/.ssh/id_dsa.pub
Copy your public key, from the previous command, then go to Launchpad to edit your SSH key:
https://launchpad.net/~username/+editsshkeys

Paste the key into "Add an SSH key" then click "Import Public Key". You should be all set now!


Using Bazaar

Suppose you found a project on Launchpad, that you wanted to help out with, or wanted to download their project source to tweak it to your own likings. I'll give my perlbot project as a quick example. If you go to:
https://code.launchpad.net/~drsmall/perlbot/trunk

You can view the trunk, and revisions for that project. If you wanted to download a copy of this trunk to your local system, you would issue this command:
Code:
bzr pull lp:perlbot
This would then download the source files of perlbot to ~/perlbot on your system. You can then execute, run, or send the revisions back to the trunk (with proper permission).

Ok. So let's say you want to start your own branch, where you can host your own edited version of some software, or it could be something you created by yourself that you want to be worked on by a team. Gather up all of the files you want to placed in your launchpad branch, and place them in one directory. cd to this directory, and then run:
Code:
bzr init
This makes the directory into a version branch. If you take the time to notice, there is now a hidden directory called .bzr in here. This is where all the revisions, and files are stored to be used by bzr. Now, add all of the files to the branch:
Code:
bzr add *
It is a good idea to get in the habit of running the next command for checking the difference between your last revision and the current one. You shouldn't have to do this on your first time around, though.
Code:
bzr diff
With this next step, we are committing our edits into the current revision. It is a good idea to label your revisions with meaningful comments.
Code:
bzr commit -m "Revision 1 Comment"
You may now upload your revision to your Launchpad branch. If the branch does not exist, it will be created. You can have multiple branches, so name them accordingly. This command may take a few minutes, but it is creating the branch, uploading your files, creating revisions and alot of other things.
Code:
bzr push lp:~user/projectname/branchname

Commands

Make directory a bzr branch:
Code:
bzr init
Download a branch:
Code:
bzr pull 
Update a branch:
Code:
bzr push 
Add files to branch:
Code:
bzr add 
Check the difference between revisions:
Code:
bzr diff
Commit the revision:
Code:
bzr commit -m "Revision Comment"
(These are just the basic commands. You can find the complete list of commands by running 'man bzr' in your terminal.)

No comments: