App Developer Week -- Tracking Source Code History with Bazaar -- jelmer -- Wed, Apr 13th, 2011

   1 [22:02] <jelmer> hello
   2 [22:03] <jelmer> I'll be talking to you today about Bazaar, the version control system.
   3 [22:04] <jelmer> My name is Jelmer Vernooij and I'm one of the Bazaar hackers. I'll quickly go over what Bazaar is and some of the basics before briefly discussing some of the more advanced features that I think might be interesting to app developers.
   4 [22:04] <jelmer> Please ask questions, and if there are other features you're interested in and would like me to cover, please mention so. I'm more than happy to cover other Bazaar-related topics instead.
   5 [22:05] <jelmer> Bazaar is version control system, which can track the changes of your source code over time. You might be familiar with other version control systems such Subversion, CVS, Perforce or Visual Sourcesafe.
   6 [22:06] <jelmer> Like many current generation version control systems, such as Git or Mercurial, Bazaar is distributed. This means that somebody who checks out the source code gets a full copy of the history on their local machine rather than having a central location with the full history and requiring all changes to happen on that central server.
   7 [22:07] <jelmer> Every clone of your source history will have a hidden .bzr/ subdirectory which contains Bazaar metadata. You can use the bzr command to inspect and add to the history of your tree.
   8 [22:07] <jelmer> To version a tree using Bazaar, run "bzr init" in the root followed by "bzr add" to add the files you would like Bazaar to track. When you're happy, run "bzr commit" to store the first revision of your tree.
   9 [22:08] <jelmer> Bazaar will ask you for a description of your changes. Later on, when you've changed files you can run "bzr commit" again to store those changes as a new revision.
  10 [22:08] <jelmer> This creates a series of revisions, named a branch.
  11 [22:08] <jelmer> Let's try this with a simple hello world program:
  12 [22:08] <jelmer> $ mkdir hello
  13 [22:08] <jelmer> $ cd hello
  14 [22:08] <jelmer> $ bzr init
  15 [22:09] <jelmer> Bazaar should now tell you that it's created a branch and what file format it used.
  16 [22:09] <jelmer> After you've done this you should see a .bzr/ meta directory if you run "ls -a".
  17 [22:10] <jelmer> Now, create a file and tell Bazaar to track its history. I'm creating which simply prints "Hello, World" on standard out.
  18 [22:10] <jelmer> $ bzr add
  19 [22:11] <jelmer> You can now use "bzr commit" to store this as your first revision.
  20 [22:11] <jelmer> are there any questions so far ? Am going too fast, should I skip the basics?
  21 [22:12] <jelmer> Sorry, s/Am/Am I/
  22 [22:13] <jelmer> $ bzr commit
  23 [22:13] <jelmer> This will launch your editor and allow you to specify a message describing your changes. Since this is our original commit, I usually just type "Initial commit"
  24 [22:13] <jelmer> To look at the history of your source code later, you can use various bzr subcommands. Mostly commonly used are "bzr log", "bzr diff", "bzr cat" and the graphical "bzr qlog" (a QT revision browser) and "bzr viz" (a GTK+ revision browser).
  25 [22:15] <jelmer> If you change your file again you can run "bzr commit" to store your new changes.
  26 [22:15] <jelmer> "bzr log" should show you two revisions at this point.
  27 [22:15] <jelmer> To share code, you can push your branch somewhere using the "bzr push" command, pull in new changes from somebody else using the "bzr pull" command or create a clone of a branch found elsewhere using "bzr branch".
  28 [22:16] <jelmer> Bazaar allows you to push over the HTTP, SSH, SFTP and FTP transports as well as to local paths.
  29 [22:19] <jelmer> "bzr push" and "bzr pull" only allow you to add new revisions to existing history. If two branches have different changes, then you can use "bzr merge" to merge the two branches. If you merge somebody else's branch then their changes will be merged into your local tree. When you're happy with the way the trees were merged, you can run "bzr commit" to create a new revision that joins the changes.
  30 [22:19] <jelmer> Bazaar integrates with various other Ubuntu related tools. For example, Launchpad uses Bazaar as its version control system. You can push branches to Launchpad so others can access them.
  31 [22:19] <jelmer> Launchpad can also import branches from other version control systems like Git, Subversion, Mercurial or CVS for you. Launchpad will automatically add links on a branch page for bugs that have been marked as fixed by that branch.  You can use a shorthand ("lp:") to address Launchpad from within Bazaar.
  32 [22:20] <jelmer> Let's try to push the branch we created earlier to Launchpad. Assuming you're already logged in to Launchpad you can run "bzr push lp:~YOURNAME/+junk/hello".
  33 [22:21] <jelmer> Where YOURNAME is your Launchpad user name. If you get an error about logging in, you need to tell Bazaar about your Launchpad id by running "bzr lp-login".
  34 [22:21] <jelmer> This will create a branch named hello in your area of Launchpad that's not tied to a particular project. Use "bzr lp-open" to see Launchpad's page for your newly created branch.
  35 [22:22] <jelmer> QUESTION: So, you generally don't push from your working directory to someone else's, but rather to a common directory that you use for accumulating and tracking versions?
  36 === binfalse_ is now known as binfalse
  37 [22:24] <jelmer> There is no right answer to this, but usually you push to a central location, where all developers pull in new upstream changes from that central location and their branches eventually get merged into the upstream location again.
  38 [22:24] <jelmer> For more information on the possible workflows, see this wiki page:
  39 [22:25] <jelmer> What works best for you depends on the goals of your project, the number of developers, etc.
  40 [22:26] <jelmer> For example, in Bazaar we have a robot that is the only one with write access to our main branch. When a developer makes a change they push their branch to Launchpad, send an email to the robot and the robot will merge their branch, run the testsuite and only push to the main branch if all tests passed.
  41 [22:26] <jelmer> QUESTION: what does the --use-existing mean? when you bzr push --use-existing lp:~YOURNAME/=junk
  42 [22:27] <jelmer> --use-existing means that Bazaar will push to a location, even if that location is a directory with existing files. You shouldn't have to use it for Launchpad
  43 [22:29] <jelmer> To clone an existing branch on Launchpad, you can use "bzr branch" as I mentioned earlier. For example, you can make a clone of pydoctor project by running "bzr branch lp:pydoctor pydoctor".
  44 [22:30] <jelmer> There are several useful plugins available for Bazaar. If you're a web developer, you might want to have a look at bzr-upload. If you are doing Ubuntu or Debian packaging you might be interested in the bzr-builddeb plugin.
  45 [22:31] <jelmer> "bzr plugins" will print a list of plugins you currently have installed.
  46 [22:32] <jelmer> For a full list of the available plugins, have a look at this page:
  47 [22:32] <jelmer> The most commonly used ones are also packaged separately in Ubuntu.
  48 [22:33] <jelmer> You might in particular be interested in the bzr-gtk or qbzr plugins, which provide a graphical interface on top of Bazaar.
  49 [22:34] <jelmer> ("bzr-gtk" and "qbzr" are also the names of their respective packages in Ubuntu)
  50 [22:35] <jelmer> E.g. qbzr provides the "bzr qlog" command I mentioned earlier which allows you to browse history. Another useful command is "bzr qannotate" which will show you for each line in a file in which revision it was last modified, as well as the author of that revision and the message associated with that revision.
  51 [22:38] <jelmer> As I mentioned earlier, Launchpad can import revision history from other version control systems. It has upstream imports of a lot of upstream projects.
  52 [22:38] <jelmer> For example, lp:bzr is the upstream Bazaar source code, and lp:samba is the upstream Samba source code (Samba's source code is maintained in Git).
  53 [22:39] <jelmer> Launchpad also has branches for all source packages in Ubuntu. If you have a recent version of Bazaar installed, you can check out these branches by using "bzr branch ubuntu:PACKAGENAME"
  54 [22:40] <jelmer> One of the latest cool features of Launchpad are source recipes. Recipes are simple scripts of a couple of lines that can combine branches and build Debian source packages from them.
  55 [22:41] <jelmer> Launchpad can regularly (usually once a day, if one of the branches changed) build recipes for you. This is really useful if you want to regularly build Ubuntu packages of revisions of your application. It allows users to easily run the latest revision of your application.
  56 [22:42] <jelmer> The recipes are built at most once a day, when one of the branches in the recipe changes.
  57 [22:42] <jelmer> The resulting packages end up in a PPA.
  58 [22:42] <jelmer> Let's have a look at a recipe for the pydoctor tool -
  59 [22:43] <jelmer> At the bottom of the page you can see that this recipe combines two branches:
  60 [22:43] <jelmer> lp:pydoctor, which contains the upstream source code and  lp:~jelmer/pydoctor/unstable which contains packaging metadata.
  61 [22:44] <jelmer> This recipe is built daily without any intervention from anybody other than new revisions being pushed to Launchpad. As you can see, the last time it was built was on March 21, when Michael Hudson (the developer of pydoctor) made a change to the upstream branch. This caused a new package to be built into my PPA.
  62 [22:45] <jelmer> Packaging is outside of the scope of this session, as are recipes, but if you're interested I'd recommend watching Matthew Revell's screencast that explains recipes in more detail.
  63 [22:45] <jelmer>
  64 [22:46] <jelmer> Speaking about documentation... Bazaar has a lot of good user documentation, most of which can be found on our web site:
  65 [22:46] <jelmer> Is there anything else you would like me to cover?
  66 [22:47] <jelmer> If you're already using Bazaar, is there anything that you find problematic? Perhaps I can give hints to improve your workflow.
  67 [22:48] <jelmer> QUESTION: how would i "bzr push" behind a proxy/firewall?
  68 [22:50] <jelmer> That's a good question. For just pushing over HTTP (which we support too, but which is not supported by Launchpad), you can set the http_proxy environment variable.
  69 [22:51] <ClassBot> There are 10 minutes remaining in the current session.
  70 [22:51] <jelmer> Looking at the docs quickly I can't find any details on using SSH over a proxy.
  71 [22:52] <jelmer> You should be able to use corkscrew, see for details.
  72 [22:53] <jelmer> Are there any other questions?
  73 [22:56] <jelmer> QUESTION: outside of hosting sites like launchpad, how does one traditionally send a merge request? Is there a way to link repositories? Or do you just simply pull from it and see?
  74 [22:57] <jelmer> You can either just ask the person that you would like to do the merge informally. ("I have fixed bug X and my branch is at location http://..../, please merge"); or you can send them an email that contains the changes ("bzr send --mail-to=their-email-address")
  75 [22:58] <ClassBot> There are 5 minutes remaining in the current session.
  76 [23:00] <jelmer> Only one minute remaining.. thanks for attending. If you have any further questions, don't hesitate to ask in #bzr

MeetingLogs/appdevweek1104/Bazaar (last edited 2011-04-14 07:25:32 by 178)